需要带有 wordpress 插件的主题
Require theme with a wordpress plugin
我已经为我的主题创建了一个 elementor widgets 插件,现在想用我的插件打包我的主题。就像如果用户安装了没有我的主题的单个插件然后将抛出错误 'Require my theme'
您可以检查活动(父)主题的名称,如果它与您的主题不匹配则发出通知。并设置 link 到下载页面。
将代码放入您的主插件文件中:
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');
我已经为我的主题创建了一个 elementor widgets 插件,现在想用我的插件打包我的主题。就像如果用户安装了没有我的主题的单个插件然后将抛出错误 'Require my theme'
您可以检查活动(父)主题的名称,如果它与您的主题不匹配则发出通知。并设置 link 到下载页面。
将代码放入您的主插件文件中:
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');