我已经开发了使用所有WordPress主题的插件。现在,根据主题的要求,我需要在一些文件上更改一些文件。但我不想碰我的插件。我用过
add_theme_support(\'jeweltheme-core\');我在插件上以同样的方式复制了插件文件和文件夹。我需要编辑“小部件”文件。我找不到任何方法来解决这个问题。
示例:我们在主题上使用“模板”目录复制覆盖“WooCommerce”模板,并将其重命名为“WooCommerce”。我想要像这样的精确解。
谢谢
我已经开发了使用所有WordPress主题的插件。现在,根据主题的要求,我需要在一些文件上更改一些文件。但我不想碰我的插件。我用过
add_theme_support(\'jeweltheme-core\');我在插件上以同样的方式复制了插件文件和文件夹。我需要编辑“小部件”文件。我找不到任何方法来解决这个问题。
示例:我们在主题上使用“模板”目录复制覆盖“WooCommerce”模板,并将其重命名为“WooCommerce”。我想要像这样的精确解。
谢谢
我的解决方案是这样的:
function jeweltheme_core_get_template_path($template){ $located = \'\'; $template_slug = rtrim( $template, \'.php\' ); $template = $template_slug . \'.php\'; $this_plugin_dir = WP_PLUGIN_DIR.\'/\'.str_replace( basename( __FILE__), "", plugin_basename(__FILE__) ); if ( $template ) { if ( file_exists(get_stylesheet_directory() . \'/jeweltheme-core/\' . $template)) { $located = get_stylesheet_directory() . \'/jeweltheme-core/\' . $template; } else if ( file_exists(get_template_directory() . \'/jeweltheme-core/\' . $template) ) { $located = get_template_directory() . \'/jeweltheme-core/\' . $template; } else if ( file_exists( $this_plugin_dir . $template) ) { $located = $this_plugin_dir . $template; } } return $located; }
如果您已经编写了插件,那么我建议您添加如下内容:
// Define these constants once in your main plugin init file
define( \'YOUR_PLUGIN_SLUG\', \'your-plugin-slug\' );
define( \'YOUR_PLUGIN_DIR\', plugin_dir_path( __FILE__ ) );
define( \'YOUR_PLUGIN_TEMPLATE_DIR\', trailingslashit( YOUR_PLUGIN_DIR ) . \'templates\' );
define( \'YOUR_PLUGIN_THEME_TEMPLATE_OVERRIDE_PATH_DIR\', trailingslashit( get_stylesheet_directory() . \'/\' . YOUR_PLUGIN_SLUG );
// Define a function to locate template files
function your_plugin_name_get_template_part_location( $part ) {
$part = $part \'.php\';
// Look in the user\'s theme first for the file
if ( file_exists( YOUR_PLUGIN_THEME_TEMPLATE_OVERRIDE_PATH_DIR . $part ) ) {
$file = YOUR_PLUGIN_THEME_TEMPLATE_OVERRIDE_PATH_DIR . $part;
}
// Otherwise use the file from your plugin
else {
$file = YOUR_PLUGIN_TEMPLATE_DIR . $part;
}
}
首先,定义一些常量(在主插件初始化文件中执行一次),这些常量可能已经存在。然后,该函数允许您调用文件(在我的示例中,模板文件/插件/插件名称/模板)。
例如,您可以使用
get_template_part(your_plugin_name_get_template_part_location(\'widget\'));
您的插件将首先查看用户的主题,以查看覆盖是否到位。如果这不存在,那么它将在您的插件中查找。
当然,您可以根据自己的目录结构和需要对其进行修改。
我在Wordpress网站的管理视图中收到通知,我有一个网站和插件的可用更新(在我的网络管理仪表板中,在“插件”和“更新”旁边的红色圆圈中有“1”)。。。但当我尝试同时转到“更新”页和;插件页面,是否显示主页?此时的URL为http:///wp-admin/network/update-core.php/和http:///wp-admin/plugins.php/分别地因此,我永远无法到达真正的更新页面,也无法更新我的Wordpress或插件。如何显示更新或插件页面?