最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Override plugin class which has namespace

programmeradmin0浏览0评论

I would like to override this plugin class in child theme :

class-config.php

namespace um;

if ( ! defined( 'ABSPATH' ) ) exit;

if ( ! class_exists( 'um\Config' ) ) {


    /**
     * Class Config
     *
     * Class with global variables for UM
     *
     * @package um
     */
    class Config
    {
        //some code here...
    }
    //end class
}

But as you can see, this class uses a namespace, so I can't just write this in my functions.php :

functions.php

class Config
{
    //some new code here...
}

I tried to add namespace um; in functions.php but of course it doesn't work.

Does anybody have an idea ? :)

I would like to override this plugin class in child theme :

class-config.php

namespace um;

if ( ! defined( 'ABSPATH' ) ) exit;

if ( ! class_exists( 'um\Config' ) ) {


    /**
     * Class Config
     *
     * Class with global variables for UM
     *
     * @package um
     */
    class Config
    {
        //some code here...
    }
    //end class
}

But as you can see, this class uses a namespace, so I can't just write this in my functions.php :

functions.php

class Config
{
    //some new code here...
}

I tried to add namespace um; in functions.php but of course it doesn't work.

Does anybody have an idea ? :)

Share Improve this question edited Oct 15, 2019 at 13:30 ArbreMojo asked Jan 25, 2019 at 15:04 ArbreMojoArbreMojo 191 silver badge9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

I found it ! :)

I just created another file called class-config-new.php just next to functions.php. I wrote my class in class-config-new.php and added the namespace, and I added a require_once in functions.php to call the file.

发布评论

评论列表(0)

  1. 暂无评论