/
apip.php
2618 lines (2416 loc) · 98.2 KB
/
apip.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Plugin Name: All plugins in pewae
* Plugin URI: http://pewae.com
* GitHub Plugin URI: https://github.com/lifishake/apip
* Description: Plugins used by pewae
* Author: lifishake
* Author URI: http://pewae.com
* Version: 1.37.4
* License: GNU General Public License 3.0+ http://www.gnu.org/licenses/gpl.html
*/
/*宏定义*/
define('APIP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define('APIP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ) ;
define('APIP_GALLERY_URL',home_url('/',is_ssl()?'https':'http').'wp-content/gallery/');
define('APIP_GALLERY_DIR', ABSPATH.'wp-content/gallery/');
register_activation_hook( __FILE__, 'apip_plugin_activation' );
register_deactivation_hook( __FILE__,'apip_plugin_deactivation' );
register_uninstall_hook(__FILE__, 'apip_plugin_deactivation');
/* 打log用 */
function apip_log( $any )
{
echo '<pre>'.$any.'</pre>';
}
/*插件激活*/
function apip_plugin_activation()
{
global $wpdb;
//4.1
$thumb_path = APIP_GALLERY_DIR . "gravatar_cache";
if (file_exists ($thumb_path)) {
if (! is_writeable ( $thumb_path )) {
@chmod ( $thumb_path, '511' );
}
} else {
@mkdir ( $thumb_path, '511', true );
}
if (!file_exists($thumb_path."/default.png")) {
@copy (APIP_PLUGIN_DIR."img/default.png", $thumb_path."/default.png");
}
}
/*插件反激活*/
function apip_plugin_deactivation()
{
}
/*配置画面*/
if (is_admin())
{
require_once( APIP_PLUGIN_DIR . '/apip-options.php');
}
//包含自定义的函数
require ( APIP_PLUGIN_DIR.'/apip-func.php') ;
function apip_option_check( $key, $val = 1 )
{
global $apip_options;
if ( empty($apip_options) ) {
$apip_options = get_option('apip_settings');
}
//array_key_exists
if ( isset( $apip_options[$key] ) && $apip_options[$key] == $val ) {
return true;
}
return false;
}
/* Plugin页面追加配置选项 */
function apip_settings_link($action_links, $plugin_file){
if($plugin_file == plugin_basename(__FILE__)){
$apip_settings_link = '<a href="options-general.php?page=apip/apip-options.php">Settings</a>';
array_push($action_links, $apip_settings_link);
}
return $action_links;
}
add_filter('plugin_action_links','apip_settings_link',10,2);
//add_action('current_screen', 'apip_remove_admin_help');
//add_action('in_admin_header', 'apip_remove_admin_help');
/*变量初期化*/
add_action('plugins_loaded', 'apip_init', 99);
function apip_init()
{
/** 00 */
global $wpdb;
//20210106统一整理admin_init
add_action('admin_init','apip_admin_init');
//0.1 插件自带脚本控制
add_action( 'wp_enqueue_scripts', 'apip_scripts' );
add_action( 'admin_enqueue_scripts', 'apip_admin_scripts' );
//0.2 屏蔽不必要的js
add_filter( 'wp_print_scripts', 'apip_remove_scripts', 99 );
add_filter( 'admin_print_scripts', 'apip_remove_scripts', 99 );
//0.3 屏蔽不必要的css
add_filter( 'wp_print_styles', 'apip_remove_styles', 99 );
add_filter( 'admin_print_styles', 'apip_remove_styles', 99 );
//0.4 在feed中增加关联内容
add_filter('the_excerpt_rss', 'apip_addi_feed');
add_filter('the_content_feed', 'apip_addi_feed');
//0.5 后台追加的快捷按钮
add_action('admin_print_footer_scripts','apip_quicktags');
//0.6 去掉后台的OpenSans -->移至统一的admin_enqueue_scripts
//0.7 自带的TagCloud格式调整 -->暂时不用
//0.8 移除后台的“作者”列
add_filter( 'manage_posts_columns', 'apip_posts_columns' );
//0.9 升级后替换高危文件
add_action( 'upgrader_process_complete', 'apip_remove_default_risk_files', 11, 2 );
//0.10 作者页跳转到404 -->移至统一的template_redirect钩子
//add_action('template_redirect', 'apip_redirect_author');
add_action('template_redirect', 'apip_template_redirect');
//0.11 屏蔽留言class中的作者名
add_filter('comment_class', 'apip_remove_author_class', 10, 5);
//0.12 禁用古腾堡
add_filter('use_block_editor_for_post', '__return_false');
remove_action( 'wp_enqueue_scripts', 'wp_common_block_scripts_and_styles' );
//0.13 替换human_time_diff函数中的英文单词
add_filter( 'human_time_diff', 'apip_replaced_human_time_diff', 10, 1 );
//0.14 改善代码在feed里的表现
add_filter('the_content_feed', 'apip_code_highlight', 199, 1) ;
//0.15 移除后台界面的WP版本升级提示 -->因为会引起downgrade失败,所以改为有配置项的2.11
//0.16 修改AdminBar
add_action( 'wp_before_admin_bar_render', 'apip_admin_bar', 199 );
//0.17 针对苹果旧设备的访问,减少404
add_filter('site_icon_meta_tags','apip_add_apple_touch_icon');
//0.18 汉字标题自动转utf8字符
//原来的sanitize_title范围太大,改为生成post slug和term slug的两个filter20211201
add_filter('wp_unique_term_slug', 'apip_unique_term_slug', 10, 3);
add_filter('wp_unique_post_slug', 'apip_unique_post_slug', 10, 6);
//0.19 autop与shortcode冲突问题
add_filter( 'the_content', 'apip_fix_shortcodes');
//0.20 改用户profile不需要邮件确认
remove_action('personal_options_update', 'send_confirmation_on_profile_email');
//0.21 设置chrome内核浏览器的tab颜色
add_action('wp_head', 'apip_set_theme_color', 20);
//0.22 移除后台的help
add_action('in_admin_header', 'apip_remove_admin_help');
/** 01 */
//颜色目前没有函数
/** 02 */
//2.1停止自动版本更新 =>这个必须在config里面设才行,已删除
//2.2停止自动保存
if( apip_option_check('auto_save_disabled') ) {
add_action( 'wp_print_scripts', 'apip_auto_save_setting' );
}
//2.3是否显示adminbar
add_filter( 'show_admin_bar', 'apip_admin_bar_setting' );
//2.4后台英文前台中文
if ( apip_option_check('forground_chinese') ) {
add_filter( 'locale', 'apip_locale', 99 );
}
//2.5屏蔽已经注册的open sans
if ( apip_option_check('block_open_sans') ) {
add_action( 'wp_default_styles', 'apip_block_open_sans', 100);
}
//2.6默认留言widget里屏蔽作者
if ( apip_option_check('show_author_comment') )
{
add_filter( 'widget_comments_args', 'before_get_comments' );
}
//2.7 搜索结果只有一条时直接跳入,移至apip_template_redirect
//2.8禁止直接访问wp_comments.php
if ( apip_option_check('protect_comment_php') )
{
add_action('check_comment_flood', 'check_referrer_comment');
}
//2.9搜索结果不包括page页面
if ( apip_option_check('search_without_page') )
{
add_filter('pre_get_posts','remove_page_search');
}
//2.10外链转内链
if ( apip_option_check('redirect_external_link') ) {
add_filter('the_content','convert_to_internal_links',99); // 文章正文外链转换
add_filter('comment_text','convert_to_internal_links',99); // 评论内容的链接转换
add_filter('comment_url','apip_comment_url', 10, 2); //链接转换
}
//2.11移除后台界面的WP版本升级提示
if ( apip_option_check('remove_core_updates') ) {
add_filter('pre_site_transient_update_core','remove_core_updates');
}
/** 03 */
if( apip_option_check('better_excerpt') ) {
//更好的中文摘要
add_filter('the_excerpt', 'apip_excerpt', 100);
}
if ( apip_option_check('header_description') ) {
//网站描述和关键字
add_action( 'wp_head', 'apip_desc_tag' );
}
/** 04 */
//4.1 头像替换
add_filter('get_avatar','apip_get_cavatar');
if (apip_option_check('local_gravatar')) {
//如果选择保存到本地
add_action( 'draft_to_publish','apip_delete_local_gravatars',99,1);
add_action( 'new_to_publish','apip_delete_local_gravatars',99,1);
add_filter( 'cron_schedules', 'apip_add_schdule' );
if(!wp_get_schedule( 'apip_delete_local_gravatars' ) ) {
wp_schedule_event( current_time( 'timestamp' ), '10Days', 'apip_delete_local_gravatars' );
}
}
else {
wp_clear_scheduled_hook( 'apip_delete_local_gravatars' );
}
//4.2 表情链接替换
add_filter( 'emoji_url', 'apip_rep_emoji_url', 99, 1);
add_filter( 'emoji_svg_url', 'apip_rep_emoji_url_svg', 99, 1);
/** 05 */
//5.1 广告关键字替换,抢在akimest前面
add_filter('preprocess_comment', 'hm_check_user',1);
add_action('comment_post', 'apip_remember_advertise_comment_details',10,3);
add_filter('comment_row_actions', 'apip_show_advertise_comment_details', 10, 2 );
add_filter('comment_form_defaults', 'apip_replace_triditional_comment_placeholder_text');
/** 06*/
//social没有添加项,需要外部手动调用
/** 07 自定义页面 */
//7.1 TAGcloud 注册
if ( apip_option_check('apip_tagcloud_enable') )
{
add_shortcode('mytagcloud', 'apip_tagcloud_page');
}
//7.2 友链注册
if ( apip_option_check('apip_link_enable') )
{
add_shortcode('mylink', 'apip_link_page');
}
//7.3 归档页注册
if ( apip_option_check('apip_archive_enable') )
{
add_shortcode('myarchive', 'apip_archive_page');
}
/** 08 */
//头部动作,一般用于附加css的加载
//add_action('wp_head','apip_header_actions') ;
//8.1 prettyprint脚本激活
//add_action('get_footer','apip_footer_actions') ;
//8.2 lazyload
if ( apip_option_check('apip_lazyload_enable') ) {
add_filter('the_content', 'apip_lazyload_filter', 200);
add_filter('post_thumbnail_html', 'apip_lazyload_filter', 200);
}
//8.3 结果集内跳转
if ( apip_option_check('range_jump_enable') ) {
add_action('template_redirect', 'apip_keep_query', 9 );
}
//8.4 留言邮件回复
if ( apip_option_check('notify_comment_reply') ) {
//邮件回复
add_action('wp_insert_comment','apip_comment_inserted',99,2);
}
//8.7 发帖天气
//当作每篇文章都会存草稿.草稿转成公开的时刻为发表时刻
//add_action( 'draft_to_publish','apip_save_heweather',99,1);
//add_action( 'draft_to_private','apip_save_heweather',99,1);
//add_action( 'auto-draft_to_publish','apip_save_heweather',99,1);
//add_action( 'auto-draft_to_private','apip_save_heweather',99,1);
//add_action( 'new_to_publish','apip_save_heweather',99,1);
//add_action( 'new_to_private','apip_save_heweather',99,1);
//8.10 特色图主颜色按钮
//必须在admin_init以前
add_action('admin_menu','apip_optimize_boxes');
//8.12 我的引文
add_shortcode('mysup', 'apip_sup_detail');
add_filter( 'the_content', 'apip_make_sup_anchors', 101);
// Add to the admin_init action hook
//add_filter('current_screen', 'my_current_screen' );
//0X 暂时不用了
//三插件冲突
//add_action( 'wp_print_scripts', 'apip_filter_filter',2 );
/** 99 */
if ( apip_option_check('local_widget_enable') ) {
require APIP_PLUGIN_DIR.'/apip-widgets.php';
}
}
function my_current_screen($screen) {
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) return $screen;
print_r($screen);
return $screen;
}
register_activation_hook( __FILE__, 'apip_disable_embeds_remove_rewrite_rules' );
register_deactivation_hook( __FILE__, 'apip_disable_embeds_flush_rewrite_rules' );
add_action('init', 'apip_init_actions', 999);
function apip_init_actions()
{
//0.A 移除没用的过滤项
remove_action('wp_head', 'feed_links_extra', 3 );
remove_action('wp_head', 'rsd_link' );
remove_action('wp_head', 'wlwmanifest_link' );
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10 );
remove_action('wp_head', 'wp_generator' );
remove_action('wp_head', 'rest_output_link_wp_head' );
remove_action('xmlrpc_rsd_apis', 'rest_output_rsd' );
remove_action('template_redirect', 'rest_output_link_header', 11 );
remove_action('wp_head', 'wp_oembed_add_discovery_links' );
remove_action('auth_cookie_malformed', 'rest_cookie_collect_status' );
remove_action('auth_cookie_expired', 'rest_cookie_collect_status' );
remove_action('auth_cookie_bad_username', 'rest_cookie_collect_status' );
remove_action('auth_cookie_bad_hash', 'rest_cookie_collect_status' );
remove_action('auth_cookie_valid', 'rest_cookie_collect_status' );
remove_action('user_request_action_confirmed', '_wp_privacy_account_request_confirmed' );
remove_action('user_request_action_confirmed', '_wp_privacy_send_request_confirmation_notification', 12);
remove_action('init', 'wp_schedule_delete_old_privacy_export_files' );
remove_action('wp_privacy_delete_old_export_files', 'wp_privacy_delete_old_export_files' );
remove_action('rest_api_init', 'rest_api_default_filters', 10 );
remove_action('rest_api_init', 'register_initial_settings', 10 );
remove_action('rest_api_init', 'create_initial_rest_routes', 99 );
remove_action('init', 'rest_api_init' );
remove_action( 'parse_request', 'rest_api_loaded' );
remove_filter('the_content', 'capital_P_dangit', 11 );
remove_filter('the_title', 'capital_P_dangit', 11 );
remove_filter('wp_title', 'capital_P_dangit', 11 );
remove_filter('comment_text', 'capital_P_dangit', 31 );
remove_filter('rest_authentication_errors', 'rest_cookie_check_errors', 100 );
remove_filter('wp_privacy_personal_data_exporters', 'wp_register_comment_personal_data_exporter' );
remove_filter('wp_privacy_personal_data_exporters', 'wp_register_media_personal_data_exporter' );
remove_filter('wp_privacy_personal_data_exporters', 'wp_register_user_personal_data_exporter', 1 );
remove_filter('wp_privacy_personal_data_erasers', 'wp_register_comment_personal_data_eraser' );
add_filter('use_default_gallery_style', '__return_false' );//不使用默认gallery
add_filter('xmlrpc_enabled', '__return_false' );//不使用xmlrpc
add_filter('feed_links_show_comments_feed', '__return_false' );//不输出comments的rss,4.4以上
add_filter('rest_enabled', '__return_false' );//禁用REST API,4.4以上
add_filter('rest_jsonp_enabled', '__return_false' );//禁用REST API,4.4以上
////0A.2
////禁用4.4以后的embed功能
////来源:disable-embeds
/*
global $wp;
if ( is_array($wp->public_query_vars) && !empty($wp->public_query_vars) ) {
$wp->public_query_vars = array_diff( $wp->public_query_vars, array(
'embed',
) );
}
remove_action( 'rest_api_init', 'wp_oembed_register_route' );
add_filter( 'embed_oembed_discover', '__return_false' );
remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 );
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
remove_action( 'wp_head', 'wp_oembed_add_host_js' );
add_filter( 'tiny_mce_plugins', 'apip_disable_embeds_tiny_mce_plugin' );
add_filter( 'rewrite_rules_array', 'apip_disable_embeds_rewrites' );
remove_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10 );
if ( class_exists('WP_Embed')) {
apip_remove_anonymous_object_hook( 'the_content', 'WP_Embed', 'run_shortcode' );
apip_remove_anonymous_object_hook( 'the_content', 'WP_Embed', 'autoembed' );
}
*/
//8.3 结果集内跳转的先决条件
/*
if( !session_id() )
{
session_start();
}
*/
if (session_status()!=PHP_SESSION_ACTIVE) {
session_start();
}
include (plugin_dir_path( __FILE__ )."apip-local-debug.php");
}
function apip_header_actions()
{
}
function apip_admin_init() {
/** 08 */
//8.8 留言验证问题
if( apip_option_check('apip_commentquiz_enable') ) {
add_meta_box('apipcommentquiz', '留言验证问题', 'apip_commentquiz_meta_box', 'post', 'side', 'high');
}
//增加ajax回调函数
add_action( 'wp_ajax_apip_accept_color', 'apip_accept_color' );
add_action( 'wp_ajax_apip_new_thumbnail_color', 'apip_new_thumbnail_color' );
//8.7
add_action( 'wp_ajax_apip_weather_manual_update', 'apip_weather_manual_update' );
//8.11
//在后台update区域增加不更新gmt的checkbox
add_action( 'post_submitbox_misc_actions', 'modify_no_gmt_field' );
add_filter( 'wp_insert_post_data', 'apip_adjust_modified_date_update', 10, 2 );
/** 09 */
//9.1 后台taglist增加private和draft计数列
add_filter( "manage_edit-post_tag_columns", 'apip_edit_post_tag_column_header', 10);
add_action( "manage_post_tag_custom_column", 'apip_edit_post_tag_content', 10, 3);
//9.2 post tag的slug转成utf-8
add_filter( 'post_tag_row_actions', 'apip_convert_post_tag_slug_to_utf', 10, 2 );
//9.3 postlist页增加post_tag的下拉过滤项
add_action( 'restrict_manage_posts', 'apip_add_post_tag_filter_ddl');
//9.4 后台增加显示今天要更新天气的贴。
add_action( 'wp_user_dashboard_setup', 'apip_add_dashboard_widget');
add_action( 'wp_dashboard_setup', 'apip_add_dashboard_widget');
//9.5 后台维护option表
add_action( 'wp_ajax_apip_db_maintain', 'apip_db_maintain' );
//9.6 图片上传
add_action('wp_ajax_apip_upload_image', 'apip_upload_image');
add_action('wp_ajax_nopriv_apip_upload_image','apip_upload_image');
}
/*
$options
00. 无选项,必须选中的内容
0.1 Ctrl+Enter提交 //20200418移除
0.2 屏蔽不必要的js
0.3 屏蔽不必要的style
0.4 feed结尾的追加内容
0.5 追加的快捷按钮
0.6 屏蔽后台的OpenSans
0.7 调整默认的TagCloud Widget
0.8 移除后台的作者列
0.9 版本升级后自动替换掉危险文件(wp-comments-post.php,xmlrpc.php)
0.11 移除无用的钩子
0.12 禁用古腾堡(5.0后)
0.13 替换human_time_diff函数中的英文单词
0.14 改善代码在feed里的表现
0.15 已删除
0.16 强化AdminBar
0.17 针对苹果旧设备的访问,减少404
0.18 汉字标题自动转utf8字符
0.19 autop与shortcode冲突问题
0.20 改用户profile不需要邮件确认
0.21 设置chrome的标签颜色
0.22 移除后台画面的help
0.23 禁止edit_lock
01. 颜色选项
02. 高级编辑选项
2.1 save_revisions_disable 阻止自动版本 ×已删除
2.2 auto_save_disabled 阻止自动保存
2.3 show_admin_bar 显示登录用户的admin bar
2.4 apip_locale 后台英文前台中文
2.5 block_open_sans 屏蔽后台的open sans字体
2.6 show_author_comment 屏蔽作者留言
2.7 redirect_if_single 搜索结果只有一条时直接跳入
2.8 protect_comment_php 禁止直接访问wp_comments.php
2.9 search_without_page 搜索结果中屏蔽page
2.10 redirect_external_link 外链转内链
2.11 remove_core_updates 移除后台界面的WP版本升级提示
03. header_description 头部描述信息
3.1 hd_home_text 首页描述文字
3.2 hd_home_keyword 首页标签
3.3 excerpt_length 摘要长度
3.4 excerpt_ellipsis 摘要结尾字符
04. GFW选项
4.1 local_gravatar 头像本地缓存
4.1.1 gravatar_mirror 头像镜像地址
4.1.2 available_gravatar_mirrors 头像镜像可用地址
4.2 replace_emoji 替换emoji地址
05. 留言者控制
5.1 blocked_commenters 替换广告留言用户名和网址
06. social_share_enable 社会化分享使能
07. 自定义的shortcode
7.1 apip_tagcloud_enable 更好看的标签云
7.2 apip_link_page 自定义友情链接
7.3 apip_achive_page 自定义归档页
08. 比较复杂的设定
8.1 apip_codehighlight_enable 代码高亮
available_codehighlight_tags 代码高亮的tag
8.2 apip_lazyload_enable LazyLoad
8.3 结果集内跳转
8.4. notify_comment_reply 有回复时邮件提示
8.7 heweather_key 和风天气/发帖时天气信息
8.8 apip_commentquiz_enable 回复前答题
8.9 apip_title_hex_meta_box 手动将标题转换成unicode值的按钮
8.10 apip_colorthief_meta_box 取特色图片主色调相关内容
8.11 apip_adjust_modified_date_update 在后台update区域增加不更新gmt的checkbox
09. 后台维护相关
9.1 后台taglist增加private和draft计数列
9.2 post tag的slug转成utf-8
9.3 后台postlist增加post_tag筛选下拉框
9.4 后台显示今日待追加天气的post
9.5 后台维护option表
9.6 后台上传图片功能
99. local_widget_enable 自定义小工具
99.1 local_definition_count 自定义widget条目数
*/
/******************************************************************************/
/* 00.没有选项必须好用 */
/******************************************************************************/
//0.1+
/**
* 作用: 插件自带脚本
* 来源: 自产
* URL:
*/
function apip_scripts()
{
global $apip_options;
$color_border = isset( $apip_options['border_color'] ) ? $apip_options['border_color'] : "#8a8988";
$color_link = isset( $apip_options['link_color'] ) ? $apip_options['link_color'] : "#1a5f99";
$color_font = isset( $apip_options['font_color'] ) ? $apip_options['font_color'] : "#0a161f";
$color_bg = isset( $apip_options['bg_color'] ) ? $apip_options['bg_color'] : "#ece5df";
wp_enqueue_style( 'apip-style-all', APIP_PLUGIN_URL . 'css/apip-all.css', array(), '20231116' );
wp_enqueue_script('apip-js-option', APIP_PLUGIN_URL . 'js/apip-option.js', array(), "20200418", true);
$css = '';
if ( /*is_single()*/1 ) {
wp_enqueue_style( 'apip_weather_style', APIP_PLUGIN_URL . 'css/weather-icons.min.css' );
wp_enqueue_style( 'apip_wind_style', APIP_PLUGIN_URL . 'css/weather-icons-wind.min.css' );
}
if (is_singular()) {
wp_enqueue_script('apip-js-singular', APIP_PLUGIN_URL . 'js/apip-singular.js', array(), "20201208", true);
}
//0.1 Ctrl+Enter 提交
//if (is_singular() && comments_open() ) {
//wp_enqueue_script('apip-comment-form', APIP_PLUGIN_URL . 'js/apip-comment-form.js', array(), "20200417", true);
//}
//07
if ( is_singular() && apip_option_check('social_share_enable') )
{
wp_enqueue_script('apip-js-social', APIP_PLUGIN_URL . 'js/apip-social.js', array(), "20191101", true);
}
//7.1
if ( is_page('my-tag-cloud') && apip_option_check('apip_tagcloud_enable') )
{
$link_colors = array();
$bg_colors = array();
$link_colors = apip_get_link_colors($color_link);
$bg_colors = apip_get_bg_colors($color_bg);
$css .= ' ul.tagcloud li {
background-color: '.$color_bg.'E6;
}
a.lk0 {
color: '.$link_colors[0].';
}
a.lk1 {
color: '.$link_colors[1].';
}
a.lk2 {
color: '.$link_colors[2].';
}
a.lk3 {
color: '.$link_colors[3].';
}
a.lk4 {
color: '.$link_colors[4].';
}
a.lk5 {
color: '.$link_colors[5].';
}
a.lk6 {
color: '.$link_colors[6].';
}
a.lk7 {
color: '.$link_colors[7].';
}';
}
//7.2
if ( is_page('my_links') && apip_option_check('apip_link_enable') )
{
$css .= ' .url::after {
color: '.$color_link.';
}';
}
//7.3
if ( (is_page('archive')||is_page('archives')) && apip_option_check('apip_archive_enable') )
{
$css .= '
.post-'.get_the_ID().' .entry-content ul li .achp-child {
line-height: 1.25rem;
font-size: 1rem;
}
.post-'.get_the_ID().' .entry-content ul,
.post-'.get_the_ID().' .entry-content ol {
border: none !important;
font-weight: normal !important;
text-shadow: none !important;
}
.post-'.get_the_ID().' .entry-content ul:not(.apip-no-disp),
.post-'.get_the_ID().' .entry-content ol:not(.apip-no-disp) {
display: inherit;
}';
wp_enqueue_script('apip-js-achp', APIP_PLUGIN_URL . 'js/apip-achp.js', array(), "20191105", true);
}
//8.1
$agm = array();
if (isset($apip_options['available_codehighlight_tags'])&& trim($apip_options['available_codehighlight_tags'])!=="") {
$agm = explode(",", $apip_options['available_codehighlight_tags']);
} else {
$agm[] = "testcode";
}
if ((in_category('code_share') || has_tag($agm)) && apip_option_check('apip_codehighlight_enable') == 1 )
{
add_filter('the_content', 'apip_code_highlight') ;
wp_enqueue_script('apip-js-prettify', APIP_PLUGIN_URL . 'js/apip-prettify.js', array(), "20191101", true);
}
//8.2
if ( apip_option_check('apip_lazyload_enable') ) {
wp_enqueue_script('apip-js-lazyload', APIP_PLUGIN_URL . 'js/unveil-ui.min.js', array(), '20200413', true);
}
//8.8
if ( is_single() && comments_open() && apip_option_check('apip_commentquiz_enable')) {
wp_enqueue_script( 'apip-js-comment-quiz',APIP_PLUGIN_URL . 'js/apip-commentquiz.js', array(), false, true);
}
if ( $css !== '' ) {
wp_add_inline_style('apip-style-all', $css);
}
}
/* 统一处理后台相关的脚本 */
function apip_admin_scripts() {
global $apip_options;
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_style( 'apip-style-option', APIP_PLUGIN_URL . 'css/apip-option.css', array(), '20240209' );
wp_enqueue_style( 'apip-style-admin', APIP_PLUGIN_URL . 'css/apip-admin.css', array(), '20240209' );
wp_enqueue_script('apip-color-thief', APIP_PLUGIN_URL . 'js/color-thief.js', array(), '20191101', true);
wp_enqueue_script('apip-js-admin', APIP_PLUGIN_URL . 'js/apip-admin.js', array('wp-color-picker' ), '20240218', true);
//wp_localize_script('apip-js-admin','yandexkey',$apip_options['yandex_translate_key']);
//20200416 原0.6功能,移除OpenSans字体
wp_deregister_style( 'open-sans' );
wp_register_style( 'open-sans', false );
}
//0.2
/**
* 作用: 屏蔽已装载插件的不必要的js
* 来源: 自产
* URL:
*/
function apip_remove_scripts()
{
global $wp_scripts;
if ( !is_object($wp_scripts) || empty($wp_scripts) || empty($wp_scripts->registered) )
return;
foreach ($wp_scripts->registered as $libs){
$libs->src = str_replace('//ajax.googleapis.com', '//gapis.geekzu.org/ajax', $libs->src);
//fonts.gmirror.org
}
if ( !is_admin() )
{
wp_dequeue_script( 'photocrati_ajax' );
wp_dequeue_script( 'lazy_resources' );
wp_dequeue_script( 'frame_event_publisher' );
}
if ( !is_page('gallery') )
{
wp_dequeue_script( 'jquery-nivo-slider' );
wp_dequeue_script( 'jquery-shuffle' );
}
}
//0.3
/**
* 作用: 屏蔽不必要的style
* 来源: 自产
* URL:
*/
function apip_remove_styles()
{
global $wp_styles;
foreach ($wp_styles->registered as $libs){
//替换google字体
$libs->src = str_replace('//fonts.googleapis.com', '//fonts.loli.net', $libs->src);
}
if ( !is_admin() )
{
wp_dequeue_style( 'fontawesome' );
}
if ( !is_page('gallery') )
{
wp_dequeue_style( 'jquery-plugins-slider-style' );
}
}
//0.4
/**
* 作用: 在feed中增加相关内容
* 来源: 自产
* URL:
*/
function apip_addi_feed($content)
{
if( !is_feed() )
{
return $content ;
}
$addi = sprintf( '<div style="max-width: 520px; margin:0 auto; padding:5px 30px;margin: 15px; border-top: 1px solid #CCC;"><span style="margin-left: 2px; display:block;">《%1$s》采用<a rel="license" href="//creativecommons.org/licenses/by-nc-nd/3.0/cn/deed.zh">署名-非商业性使用-禁止演绎</a>许可协议进行许可。 『%2$s』期待与您交流。</span><div style="display:table;">%3$s</div></div>',
sprintf( '<a href="%1$s">%2$s</a>' , get_permalink(get_the_ID()), get_the_title() ),
sprintf( '<a href="%1$s">%2$s</a>' , get_bloginfo('url'), get_bloginfo('name') ),
sprintf('<div style="margin: 5px 25px; display:table-cell; max-width:500px; "><h3 style="font-size:16px; font-weight:800;" >相关推荐:</h3>%s</div>', apip_related_post() )
);
$content.=$addi ;
return $content ;
}
//0.5
/**
* 作用: 追加代码和网易云的快捷按钮
* 来源: 自产
* URL:
*/
function apip_quicktags()
{
?>
<script type="text/javascript" charset="utf-8">
QTags.addButton( 'eg_pre', 'pre', '\n<pre>\n', '\n</pre>\n', 'p' );
QTags.addButton( 'eg_mysup', '引文', '[mysup sup_content="', '" /]', 'p' );
QTags.addButton( 'eg_any', 'any', any_callback );
</script>
<?php
}
//0.8 移除后台的作者列
function apip_posts_columns( $columns ) {
unset( $columns['author'] );
return $columns;
}
//0.9 升级后替换高危文件
function apip_remove_default_risk_files( $upgrader_object, $options )
{
if( 'update' === $options['action'] && 'core' === $options['type'] )
{
global $wp_filesystem;
$wp_dir = trailingslashit($wp_filesystem->abspath());
@$wp_filesystem->copy( APIP_PLUGIN_DIR.'/ext/wp-go-die.php', $wp_dir.'wp-comments-post.php', true );
@$wp_filesystem->copy( APIP_PLUGIN_DIR.'/ext/wp-go-die.php', $wp_dir.'xmlrpc.php', true );
}
}
//0.10 author页跳转到404
function apip_redirect_author() {
if (is_author()) {
global $wp_query;
$wp_query->set404();
wp_redirect( network_site_url( '404.php' ) );
exit;
}
}
//0.11 屏蔽留言中的作者名class
function apip_remove_author_class( $classes, $class, $comment_ID, $comment, $post_id ) {
$c_rm = array();
if ( $comment->user_id > 0 && $user = get_userdata( $comment->user_id ) ) {
$c_rm[] = 'comment-author-' . sanitize_html_class( $user->user_nicename, $comment->user_id );
}
$classes = array_diff( $classes, $c_rm );
return $classes;
}
//0.13
//来源:https://www.syshut.com/human_time_diff-function-localization-with-en-wp.html
function apip_replaced_human_time_diff( $since ) {
$search = array( 'years', 'year', 'months', 'month', 'weeks', 'week', 'days', 'day', 'hours', 'hour', 'mins', 'min', 'seconds', 'second', );
$replace = array( '年', '年', '个月', '个月', '周', '周', '天', '天', '小时', '小时', '分钟', '分钟', '秒', '秒', );
$since = str_replace( $search, $replace, $since );
return $since;
}
//0.15-->2.11
//来源:https://thomas.vanhoutte.be/miniblog/wordpress-hide-update/
function remove_core_updates(){
global $wp_version;
return (object) array('last_checked'=> time(),'version_checked'=> $wp_version,);
}
//0.16 优化AdminBar
function apip_admin_bar() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('wp-logo'); //移除Logo
$wp_admin_bar->remove_menu('updates');
if (!is_admin()){
$wp_admin_bar->remove_menu('customize');
$wp_admin_bar->add_menu( array(
'id' => 'custom_plugin',
'title' => 'Plugins',
'href' => home_url('/',is_ssl()?'https':'http').'wp-admin/plugins.php',
'parent' => 'site-name',
)
);
}
else {
//后台增加直接跳到草稿
$wp_admin_bar->add_menu( array(
'id' => 'custom_drafts',
'title' => 'Drafts',
'href' => home_url('/',is_ssl()?'https':'http').'wp-admin/edit.php?post_status=draft&post_type=post',
'parent' => 'site-name',
)
);
}
}
//0.17 减少苹果旧设备访问的404错误
function apip_add_apple_touch_icon($meta_tags){
$icon_180 = get_site_icon_url( 180 );
if ( $icon_180 ) {
$meta_tags[] = sprintf( '<link rel="apple-touch-icon" href="%s" />', esc_url( $icon_180 ) );
}
return $meta_tags;
}
//0.18 处理汉字slug
//20211201 原来函数处理的是title,是unicode汉字字符串。现在处理的对象变成了slug,是转换后的%xx形式,所以以前的字符串转换函数不适用。
function apip_unique_term_slug($slug, $term, $original_slug){
return apip_slug_unicode($slug);
}
function apip_unique_post_slug($slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug){
$public_pts = get_post_types(array( 'public' => true ));
if (!in_array($post_type, $public_pts)){
return $slug;
}
return apip_slug_unicode($slug);
}
function apip_slug_unicode($strSlug) {
$c_count = 0;
$strRet="";
for ( $i = 0; $i < strlen( $strSlug ); $i++ ) {
$ch1 = substr( $strSlug, $i, 1 );
$byte1st = ord( $ch1 );
if ('%' == $ch1){
$chs = substr($strSlug, $i, 9);
$str_tmp = str_replace("%","",$chs);
$strRet .= $str_tmp."-";
$i += 8;
}else{
$strRet .= $ch1;
}
}
$strRet = rtrim($strRet, "-");
return $strRet;
}
//0.19 给短代码擦屁股
//来源:https://www.wpexplorer.com/clean-up-wordpress-shortcode-formatting/
function apip_fix_shortcodes($content){
$array = array (
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']'
);
$content = strtr($content, $array);
return $content;
}
//0.21 设置chrome内核浏览器的tab颜色
//来源:https://developers.google.com/web/updates/2014/11/Support-for-theme-color-in-Chrome-39-for-Android
function apip_set_theme_color() {
global $apip_options;
$color_bg = isset( $apip_options['bg_color'] ) ? $apip_options['bg_color'] : "#ece5df";
$color_bg = apply_filters('apip_tab_color',$color_bg);
echo '<meta name="theme-color" content="'.trim($color_bg).'">';
//echo '<meta name="theme-color" content="#db5945">';
}
//0.22 移除后台各个画面上的help
//来源:分析代码
function apip_remove_admin_help( ) {
get_current_screen()->remove_help_tabs();
}
//0.23 禁止edit_lock
//来源:https://wordpress.stackexchange.com/questions/120179/how-to-disable-the-post-lock-edit-lock
function apip_remove_post_locked() {
$current_post_type = get_current_screen()->post_type;
// Disable locking for page, post and some custom post type
$post_types_arr = array(
'page',
'post',
'movie',
'book',
'game',
'album'
);
if(in_array($current_post_type, $post_types_arr)) {
add_filter( 'show_post_locked_dialog', '__return_false' );
add_filter( 'wp_check_post_lock_window', '__return_false' );
wp_deregister_script('heartbeat');
}
}
add_action('load-edit.php', 'apip_remove_post_locked');
add_action('load-post.php', 'apip_remove_post_locked');
/* 00终了 */
/******************************************************************************/
/* 01.解决中文摘要问题 */
/******************************************************************************/
/* 01终了 */
/******************************************************************************/
/* 02.高级编辑选项(就是全部为T/F的选项) */
/******************************************************************************/
//2.1
/**
* 作用: 阻止自动生成版本
* 来源: Amandeep S. Patti
* URL: http://www.aspatti.com
*/
function apip_auto_rev_settings()
{
define('WP_POST_REVISIONS', false);
}
//2.2
/**
* 作用: 阻止自动保存
* 来源: Amandeep S. Patti
* URL: http://www.aspatti.com
*/
function apip_auto_save_setting()
{
wp_deregister_script('autosave');
}
/**
* 作用: 是否显示admin bar
* 来源: Amandeep S. Patti
* URL: http://www.aspatti.com
*/
//2.3
function apip_admin_bar_setting($showvar)
{
global $show_admin_bar;
if( apip_option_check('show_admin_bar') )
{
return $showvar ;
}
else
{
$show_admin_bar = false;
return false;
}
}
//2.4
/**
* 作用: 后台显示英文,前台显示中文
* 来源: 自产
* URL:
*/
function apip_locale( $locale )
{
if ( is_admin() )
{
return $locale ;
}
return 'zh_CN' ;
}
//2.5
/**