themosis / theme

The Themosis framework theme.
http://framework.themosis.com/
GNU General Public License v2.0
104 stars 35 forks source link

themosisRouteConditions filter isn't accessible from admin directory #30

Closed Yokann closed 7 years ago

Yokann commented 7 years ago

Bonjour, I am trying to add some woocommerce conditions with themosisRouteConditions filter from the theme/admin directory. If i look in function.php, the RouteProvider is load before any of these files. My conditions are ignored.

So i think it's impossible to use add_filter('themosisRouteConditions', ...); from theme/admin directory. Did i missed something ?

Thank you.

Yokann commented 7 years ago

Maybe should i use a new provider that i call before the RouteProvider

jlambe commented 7 years ago

Can you try from the functions.php file to add a route condition and let me know if it works better?

jlambe commented 7 years ago

Or if you're familiar with the service provider you can create a new one that loads before the route one. Or use the RouteProvider and set your conditions before in the register() method.

Yokann commented 7 years ago

Yes it works fine if i add the conditions in the beginning of function.php .

I also create a new provider , it works to :

class WoocommerceService extends ServiceProvider
{
    /**
     * Define theme routes namespace.
     */
    public function register()
    {
        Action::add( 'after_setup_theme', [$this, 'addThemeSupport'] );
        Filter::add('themosisRouteConditions', [$this, 'addRouteConditions']);
    }

    public function addRouteConditions($conds)
    {
        $conds['product']          = 'is_product';
        $conds['shop']             = 'is_shop';
        $conds['cart']             = 'is_cart';
        $conds['checkout']         = 'is_checkout';
        $conds['account']          = 'is_account_page';
        $conds['product_category'] = 'is_product_category';
        return $conds;
    }

    public function addThemeSupport() {
        add_theme_support( 'woocommerce' );
    }

}
jlambe commented 7 years ago

Cool, I'm glad your issue is solved. I should probably add a note regading the filter on the documentation. Thanks!