【发布时间】:2021-07-16 09:49:47
【问题描述】:
我为我的主题创建了一个 elementor 小部件插件,现在想将我的主题与我的插件打包在一起。就像如果用户安装了没有我的主题的单个插件,那么将抛出错误“需要我的主题”
【问题讨论】:
标签: php wordpress wordpress-theming elementor
我为我的主题创建了一个 elementor 小部件插件,现在想将我的主题与我的插件打包在一起。就像如果用户安装了没有我的主题的单个插件,那么将抛出错误“需要我的主题”
【问题讨论】:
标签: php wordpress wordpress-theming elementor
您可以检查活动(父)主题的名称,如果它与您的主题不匹配,则会发出通知。并设置下载页面的链接。
将代码放入主插件文件:
function check_my_theme() {
$theme = wp_get_theme();
$my_theme_name = 'My Theme'; // Edit Theme name.
if( $theme->name != $my_theme_name && $theme->parent_theme != $my_theme_name ) {
$class = 'notice notice-error';
$message = __( 'You are using the wrong Theme. Take instead ', 'your-plugin' );
$link_to_theme = '#'; // Edit link to theme.
printf( '<div class="%1$s"><p>%2$s<a href="%3$s" target="_blank">%4$s</a></p></div>',
esc_attr( $class ),
esc_html( $message ),
esc_url( $link_to_theme ),
esc_html( $my_theme_name )
);
}
}
add_action( 'admin_notices', 'check_my_theme');
【讨论】: