我正在构建一个超级基本的WordPress单页模板,所有插件都使用一些过滤器禁用。
当我尝试加载页面时出现错误,因为在functions.php文件中,它为各种各样的可能加载的插件提取了几个函数,这些都是由前一个开发人员完成的。由于它们被禁用,处理因致命错误而停止。
而不是用function_exists检查替换每个点,是否可以跳过加载functions.php文件,如果它在我正在使用的单个页面模板上?
困难是wp-settings.php总是加载模板的function.php。
但是,由于几乎在WordPress处理的最后加载了functions.php文件,我认为你可以使用动作'setup_theme'来接管WordPress处理并将其余的WordPress处理作为wp-blog-header。除了跳过functions.php的加载之外,php会有。
add_action( 'setup_theme', function() {
if ( $use_my_singlular_page_template ) {
// Define the template related constants.
wp_templating_constants( );
// Load the default text localization domain.
load_default_textdomain();
$locale = get_locale();
$locale_file = WP_LANG_DIR . "/$locale.php";
if ( ( 0 === validate_file( $locale ) ) && is_readable( $locale_file ) )
require( $locale_file );
unset( $locale_file );
/**
* WordPress Locale object for loading locale domain date and various strings.
* @global WP_Locale $wp_locale
* @since 2.1.0
*/
$GLOBALS['wp_locale'] = new WP_Locale();
/**
* WordPress Locale Switcher object for switching locales.
*
* @since 4.7.0
*
* @global WP_Locale_Switcher $wp_locale_switcher WordPress locale switcher object.
*/
$GLOBALS['wp_locale_switcher'] = new WP_Locale_Switcher();
$GLOBALS['wp_locale_switcher']->init();
/*
* don't load theme's function.php
// Load the functions for the active theme, for both parent and child theme if applicable.
if ( ! wp_installing() || 'wp-activate.php' === $pagenow ) {
if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists( STYLESHEETPATH . '/functions.php' ) )
include( STYLESHEETPATH . '/functions.php' );
if ( file_exists( TEMPLATEPATH . '/functions.php' ) )
include( TEMPLATEPATH . '/functions.php' );
}
*/
/**
* Fires after the theme is loaded.
*
* @since 3.0.0
*/
do_action( 'after_setup_theme' );
// Set up current user.
$GLOBALS['wp']->init();
/**
* Fires after WordPress has finished loading but before any headers are sent.
*
* Most of WP is loaded at this stage, and the user is authenticated. WP continues
* to load on the {@see 'init'} hook that follows (e.g. widgets), and many plugins instantiate
* themselves on it for all sorts of reasons (e.g. they need a user, a taxonomy, etc.).
*
* If you wish to plug an action once WP is loaded, use the {@see 'wp_loaded'} hook below.
*
* @since 1.5.0
*/
do_action( 'init' );
// Check site status
if ( is_multisite() ) {
if ( true !== ( $file = ms_site_check() ) ) {
require( $file );
die();
}
unset($file);
}
/**
* This hook is fired once WP, all plugins, and the theme are fully loaded and instantiated.
*
* Ajax requests should use wp-admin/admin-ajax.php. admin-ajax.php can handle requests for
* users not logged in.
*
* @link https://codex.wordpress.org/AJAX_in_Plugins
*
* @since 3.0.0
*/
do_action( 'wp_loaded' );
// do the remaining parts of wp-blog-header.php
// Set up the WordPress query.
wp();
// Load the theme template.
require_once( ABSPATH . WPINC . '/template-loader.php' );
// everything is done; must not return!
exit();
}
} );
快速修复将重命名/备份以前的开发人员functions.php
文件,然后创建一个新的空functions.php
文件。例如,使用bash shell终端:
mv /wp-content/themes/your-theme-here/functions.php /wp-content/themes/your-theme-here/functions.php.bkup
touch /wp-content/themes/your-theme-here/functions.php
mv
- 是移动/重命名命令,第一个参数是要移动(重命名)的文件,第二个是移动(重命名)它的位置。
touch
- 提供了一种创建新文件的方法。
然后,您可以使用项目仍需要的任何函数填充此新functions.php
文件。