HEX
Server: nginx/1.16.1
System: Linux VM-0-14-centos 4.18.0-348.7.1.el8_5.x86_64 #1 SMP Wed Dec 22 13:25:12 UTC 2021 x86_64
User: www (1000)
PHP: 8.3.31
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/www.sceybwg.com/wp-content/plugins/wpjam-basic/extends/mobile-theme.php
<?php
/*
Name: 移动主题
URI: https://mp.weixin.qq.com/s/DAqil-PxyL8rxzWBiwlA3A
Description: 给当前站点设置移动设备设置上使用单独的主题。
Version: 2.0
*/
class WPJAM_Mobile_Stylesheet extends WPJAM_Option_Model{
	public static function get_fields(){
		$themes	= array_map(fn($v)=> $v->get('Name'), wp_get_themes(['allowed'=>true]));
		$themes	= wpjam_pick($themes, [get_stylesheet()])+$themes;

		return ['mobile_stylesheet'=>['title'=>'移动主题', 'options'=>$themes]];
	}

	public static function load(){
		$mobile	= self::get_setting('mobile_stylesheet');
		$button	= wpjam_register_page_action('set_mobile_stylesheet', [
			'button_text'	=> '移动主题',
			'class'			=> 'mobile-theme button',
			'direct'		=> true,
			'confirm'		=> true,
			'response'		=> 'redirect',
			'callback'		=> fn()=> self::update_setting('mobile_stylesheet', wpjam_get_data_parameter('stylesheet'))
		])->get_button(['data'=>['stylesheet'=>'slug']]);

		wpjam_script(sprintf(<<<'JS'
		if(wp && wp.Backbone && wp.themes && wp.themes.view.Theme){
			let render	= wp.themes.view.Theme.prototype.render;

			wp.themes.view.Theme.prototype.render = function(){
				render.apply(this, arguments);

				this.$el.find('.theme-actions').append(this.$el.data('slug') == %s ? '<span class="mobile-theme button button-primary">移动主题</span>' : (%s).replace('slug', this.$el.data('slug')));
			};
		}
		JS, wpjam_json_encode($mobile), wpjam_json_encode($button)));

		// wpjam_style('.mobile-theme{position: absolute; top: 45px; right: 18px;}');
	}

	public static function add_hooks(){
		$name	= wp_is_mobile() ? self::get_setting('mobile_stylesheet') : null;
		$name	= $name ?: ($_GET['wpjam_theme'] ?? null);
		$theme	= $name ? wp_get_theme($name) : null;

		$theme && wpjam_map(['stylesheet', 'template'], fn($k)=> add_filter($k, fn()=> $theme->{'get_'.$k}()));
	}
}

wpjam_add_option_section('wpjam-basic', 'enhance', ['model'=>'WPJAM_Mobile_Stylesheet', 'admin_load'=>['base'=>'themes']]);