【问题标题】:Require theme with a wordpress plugin需要带有 wordpress 插件的主题
【发布时间】:2021-07-16 09:49:47
【问题描述】:

我为我的主题创建了一个 elementor 小部件插件,现在想将我的主题与我的插件打包在一起。就像如果用户安装了没有我的主题的单个插件,那么将抛出错误“需要我的主题”

【问题讨论】:

    标签: php wordpress wordpress-theming elementor


    【解决方案1】:

    您可以检查活动(父)主题的名称,如果它与您的主题不匹配,则会发出通知。并设置下载页面的链接。

    将代码放入主插件文件:

    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');
    

    【讨论】:

      猜你喜欢
      • 2011-10-21
      • 2012-04-11
      • 2014-07-02
      • 2017-09-04
      • 2020-03-09
      • 1970-01-01
      • 2013-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多