PluginProbe
WPJAM Basic / trunk
WPJAM Basic vtrunk
wpjam-basic / components / wpjam-custom.php

wpjam-custom.php in WPJAM Basic trunk, at components/wpjam-custom.php

125 lines 5.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Name: 样式定制
4 URI: https://mp.weixin.qq.com/s/Hpu1vz7zPUKEeHTF3wqyWw
5 Description: 对网站的前后台和登录界面的样式进行个性化设置。
6 Version: 2.0
7 */
8 class WPJAM_Custom{
9 public static function __callStatic($method, $args){
10 return wpjam_call_option(static::class, $method, ...$args);
11 }
12
13 public static function get_sections(){
14 return [
15 'custom' => ['title'=>'前台定制', 'fields'=>[
16 'head' => ['title'=>'前台 Head 代码', 'type'=>'textarea'],
17 'footer' => ['title'=>'前台 Footer 代码', 'type'=>'textarea'],
18 'custom' => ['title'=>'文章页代码', 'type'=>'fields', 'fields'=>[
19 'custom_post' => ['label'=>'每篇文章单独设置 head 和 Footer 代码。'],
20 'list_table' => ['show_if'=>['custom_post', 1], 'after'=>'在文章列表页设置。', 'options'=>[0=>'不支持', 1=>'支持', 'only'=>'只�
21 �许']]
22 ]]
23 ]],
24 'admin' => ['title'=>'后台定制', 'fields'=>[
25 'admin_logo' => ['title'=>'工�
26 �栏左上角 Logo', 'type'=>'img', 'item_type'=>'url', 'size'=>'40x40'],
27 'admin_head' => ['title'=>'后台 Head 代码 ', 'type'=>'textarea'],
28 'admin_footer' => ['title'=>'后台 Footer 代码', 'type'=>'textarea'],
29 'admin_info' => ['title'=>'后台运行信息', 'label'=>'后台右下角显示�
30 存使用和 SQL 数量', 'value'=>1],
31 ]],
32 'login' => ['title'=>'登录界面', 'fields'=>[
33 'login_head' => ['title'=>'登录界面 Head 代码', 'type'=>'textarea'],
34 'login_footer' => ['title'=>'登录界面 Footer 代码', 'type'=>'textarea'],
35 'login_redirect' => ['title'=>'登录之后跳转的页面', 'type'=>'text'],
36
37 'disable_language_switcher' => ['title'=>'登录界面语言切换器', 'label'=>'屏蔽登录界面语言切换器'],
38 ]]
39 ];
40 }
41
42 public static function echo($name){
43 $value = self::get_setting($name);
44
45 if($name == 'admin_footer'){
46 echo ($value ?: '<span id="footer-thankyou">感谢使用<a href="https://wordpress.org/" target="_blank">WordPress</a>进行创作。</span> | <a href="https://wpjam.com/" title="WordPress JAM" target="_blank">WordPress JAM</a>');
47 }elseif($name == 'footer'){
48 echo $value.(wpjam_basic_get_setting('optimized_by_wpjam') ? '<p id="optimized_by_wpjam_basic">Optimized by <a href="https://blog.wpjam.com/project/wpjam-basic/">WPJAM Basic</a></p>' : '');
49 }else{
50 echo $value;
51 }
52
53 if(in_array($name, ['head', 'footer']) && is_singular() && self::get_setting('custom_post')){
54 if($value = get_post_meta(get_the_ID(), 'custom_'.$name, true)){
55 wpjam_echo($value, ...($name == 'head' ? ['wp_'.$name, 100] : []));
56 }
57 }
58 }
59
60 public static function on_admin_bar_menu($wp_admin_bar){
61 remove_action('admin_bar_menu', 'wp_admin_bar_wp_menu', 10);
62
63 $logo = self::get_setting('admin_logo');
64 $title = wpjam_tag(...($logo ? ['img', ['src'=>wpjam_get_thumbnail($logo, 40, 40), 'style'=>'height:20px; padding:6px 0;']] : ['span', ['ab-icon']]));
65
66 $wp_admin_bar->add_menu([
67 'id' => 'wp-logo',
68 'title' => $title,
69 'href' => is_admin() ? self_admin_url() : site_url(),
70 'meta' => ['title'=> get_bloginfo('name')]
71 ]);
72
73 is_admin() && self::get_setting('admin_info', 1) && add_filter('update_footer', fn($text)=> wpjam_join(' | ', [size_format(memory_get_usage()).'�
74 存使用', get_num_queries().'次SQL查询', $text]));
75 }
76
77 public static function init(){
78 add_action('admin_bar_menu', [self::class, 'on_admin_bar_menu'], 1);
79
80 if(is_admin()){
81 wpjam_hooks([
82 ['admin_title', fn($title)=> str_replace(' &#8212; WordPress', '', $title)],
83 ['admin_head', fn()=> self::echo('admin_head')],
84 ['admin_footer_text', fn()=> self::get_setting('admin_footer')]
85 ]);
86 }elseif(is_login()){
87 wpjam_hooks([
88 ['login_headerurl', fn()=> home_url()],
89 ['login_headertext', fn()=> get_option('blogname')],
90 ['login_head', fn()=> self::echo('login_head')],
91 ['login_footer', fn()=> self::echo('login_footer')],
92 ['login_redirect', fn($to, $requested)=> $requested ? $to : (self::get_setting('login_redirect') ?: $to), 10, 2],
93
94 self::get_setting('disable_language_switcher') ? ['login_display_language_dropdown', false] : []
95 ]);
96 }else{
97 wpjam_hooks([
98 ['wp_head', fn()=> self::echo('head'), 99],
99 ['wp_footer', fn()=> self::echo('footer'), 99]
100 ]);
101 }
102
103 self::get_setting('custom_post') && wpjam_register_post_option('custom-post', [
104 'title' => '文章页代码',
105 'modal' => true,
106 'post_type' => fn($post_type)=> is_post_type_viewable($post_type) && post_type_supports($post_type, 'editor'),
107 'summary' => '自定义文章代码可以让你在当前文章插�
108 �独有的 JS,CSS,iFrame 等类型的代码,让你可以对�
109 �体一篇文章设置不同样式和功能,展示不同的�
110 容。',
111 'list_table' => self::get_setting('list_table'),
112 'fields' => [
113 'custom_head' =>['title'=>'头部代码', 'type'=>'textarea', 'default'=>''],
114 'custom_footer' =>['title'=>'底部代码', 'type'=>'textarea', 'default'=>'']
115 ]
116 ]);
117 }
118 }
119
120 wpjam_register_option('wpjam-custom', [
121 'title' => '样式定制',
122 'model' => 'WPJAM_Custom',
123 'site_default' => true,
124 'menu_page' => ['parent'=>'wpjam-basic', 'position'=>1, 'function'=>'option', 'summary'=>__FILE__]
125 ]);