themosis / theme

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

Themosis plugin's bootstrap/start.php included instead of theme's #11

Closed erezmus closed 7 years ago

erezmus commented 8 years ago

When doing the command wp rewrite flush --hard, rewrite rules for my custom post types defined in resources/actions.php where not being generated. When going to backend of the WordPress install to Settings \ Permalinks, they did get generated.

I traced it to a problem in the theme's functions.php at the line:

require_once('bootstrap'.DS.'start.php');

For some reason this seems to include the bootstrap/start.php file in the themosis framework and not the theme's bootstrap/start.php when running in wp cli.

@jlambe do you agree? I can do a PR, just want to make sure its not just me

jlambe commented 8 years ago

Will test it and let you know. Weird that it's not called. At which line the issue is?

erezmus commented 8 years ago

line 162 of functions.php

jlambe commented 8 years ago

Ok thanks. I'll check for this. Can you paste your code for your rewrite rules and custom post type so I can replicate the issue?

erezmus commented 8 years ago

In resources/actions.php

add_action('init', function() {
    PostType::make('news', 'News', 'News')->set([
        'public'              => true,
        'publicly_queryable'  => true,
        'exclude_from_search' => false,
        'show_ui'             => true,
        'query_var'           => true,
        'menu_position'       => 8,
        'rewrite'             => ['slug' => 'news', 'with_front' => false],
        'has_archive'         => 'news',
        'capability_type'     => 'post',
        'hierarchical'        => false,
        'supports'            => array('title', 'editor', 'author', 'thumbnail', 'excerpt')
    ]);
});
jlambe commented 8 years ago

I haven't yet looked into this but you can remove your call to add_action in order to build your custom post type. The class handle this for you, which saves some lines of code ;)

erezmus commented 8 years ago

remove the add_action gives me Fatal error: Class 'PostType' not found

jlambe commented 8 years ago

Hmm. Are you running the latest release version? or do you use the dev-master version? Check the latest bootstrap/start.php file of the themosis/theme and update yours. This should not triggers a fatal error.

erezmus commented 8 years ago

yep latest one, and have pretty much the same theme bootstrap/start.php as the themosis/theme. Is it because its in in resources/admin and they get included before the after_setup_theme. Its in that hook that the frameworks's bootstrap/start.php adds the facades as class aliases?

jlambe commented 8 years ago

Yep it's in that hook that class aliases are defined for the facades. This means that you can't use short class name before the after_setup_theme hook. Always use full classnames for configuration and bootstrapping.

erezmus commented 8 years ago

Is there a reason why they are defined in that hook?

jlambe commented 8 years ago

Yes it's the only way I found to allow developers to override/add custom aliases into their plugins or themes.

erezmus commented 8 years ago

what about having them all in a config file (e.g. config/aliases.config.php or even in config/application.config.php, the same way that is done in laravel's config/app.php ? That way they just modify or add to the array?

jlambe commented 8 years ago

I'll say I'm open to suggestions because I'm struggling to allow plugins define their custom aliases. I suppose it's not something I should allow as it may creates conflicts between plugins. Perhaps aliases can only be defined when working in the theme where we gather all the data to build our views. Seems logical for me as I'm writing.