在不同后台管理页面添加不同样式文件的写法

Published
June 5, 2022
浏览次数 :  0

function cws_core_cwsfw_admin_scripts($a) {
		global $pagenow;
		global $cws_theme_funcs;

		$theme_admin_pages = array();
		if ($cws_theme_funcs && method_exists($cws_theme_funcs, 'get_theme_config')) {
			$theme_admin_pages = $cws_theme_funcs->get_theme_config('admin_pages');
			$theme_admin_pages = ($theme_admin_pages) ?: array(); // !!! since PHP 5.3
		}

		if( ($a == 'post-new.php' || $a == 'post.php' || $a == 'toplevel_page_cwsfw' || in_array($a, $theme_admin_pages)) ) {
			$theme_uri = get_template_directory_uri();

			if ($pagenow == 'nav-menus.php'){
				wp_enqueue_script('cws-custom-menu-js', $theme_uri . '/core/js/custom-menu.js', array('jquery') );
				wp_enqueue_style('cws-custom-menu-css', $theme_uri . '/core/css/custom-menu.css', false, '2.0.0' );
			}

			wp_enqueue_style( 'cws_font_awesome', $theme_uri . '/fonts/font-awesome/font-awesome.css' );
			wp_enqueue_style( 'cws-iconpack', $theme_uri . '/fonts/cws-iconpack/flaticon.css' );
			wp_enqueue_script('qtip-js', CWSTO_PLUGIN_URL . '/js/jquery.qtip.js', array('jquery'), false );
			wp_enqueue_style('qtip-css', CWSTO_PLUGIN_URL . '/css/jquery.qtip.css', false, '2.0.0' );

			if (has_action('fw_enqueue_scripts')) {
				do_action('fw_enqueue_scripts');
			} else {
				$styles =	array('select2_init' => 'select2.css');

				foreach($styles as $key=>$sc){
					wp_enqueue_style( $key, CWSTO_PLUGIN_URL . '/css/' . $sc);
				}

				$scripts = array ('select2_init' => 'select2.min.js');

				foreach ($scripts as $alias => $src) {
					wp_enqueue_script ($alias, CWSTO_PLUGIN_URL . "/js/$src", array(), "1.0", true);
				}

			}
			wp_enqueue_media();
			wp_enqueue_style('wp-color-picker');
			wp_enqueue_script('wp-color-picker');
			wp_enqueue_script('cwsfw-main-js', CWSTO_PLUGIN_URL . '/js/cwsfw.js', array('jquery', 'wp-backbone', 'customize-controls', 'qtip-js'), false );

			wp_localize_script('cwsfw-main-js', 'cwsfw_params', array(
				'pagenow' => esc_js($pagenow),
			));

			wp_enqueue_style('cwsfw-main-css', CWSTO_PLUGIN_URL . '/css/cwsfw.css', false, '2.0.0' );

			// wp_enqueue_script('webfont_js','https://ajax.googleapis.com/ajax/libs/webfont/1.5.18/webfont.js',array('jquery'),'1.5.18', true);
		} else if ($a == 'toplevel_page_cwsfw') {
			wp_enqueue_style('cwsfw-main-css', CWSTO_PLUGIN_URL . '/css/cwsfw.css', false, '2.0.0' );
		}
	}

Top