redux-framework icon indicating copy to clipboard operation
redux-framework copied to clipboard

Child Theme Question

Open pseudonymus opened this issue 12 years ago • 26 comments

Is there a more cleaner way of using Redux into a child theme, rather than putting the whole ReduxFramework folder in the child theme and calling it in child theme`s functions.php like so?

if ( !class_exists( 'ReduxFramework' ) && file_exists( dirname( __FILE__ ) . '/framework/ReduxFramework/ReduxCore/framework.php' ) ) {
    require_once( dirname( __FILE__ ) . '/framework/ReduxFramework/ReduxCore/framework.php' );
}
if ( file_exists( dirname( __FILE__ ) . '/framework/ReduxFramework/config.php' ) ) {
    require_once( dirname( __FILE__ ) . '/framework/ReduxFramework/config.php' );
}

I would love to just load the assets of ReduxFramework for the child theme, so I don`t have to update it every time the main theme is updated. My current ReduxFramework folder looks like this: http://snag.gy/5AwP5.jpg

I`m using version "3.1.8.22".

Thank you!

pseudonymus avatar Mar 18 '14 08:03 pseudonymus

Put it in the parent theme, or use Redux as a plugin.

kprovance avatar Mar 18 '14 17:03 kprovance

The thing is that if I leave it only in the parent theme, the Theme Options panel doesn't appear in the child theme, even if I load the whole package in the child theme too...tried many approaches on this, but couldn't find a solution, except for the one from above. Should be considered an issue or not?

Thanks!

pseudonymus avatar Mar 18 '14 18:03 pseudonymus

One of the reasons Redux works so beautifully as a plugin. :)

The way I understand child themes is that the core functionality remains in the parent theme. The user then creates a child theme with the intent of modifying it. With that in mind, why would you want to include the redux code and the config in the child theme? Since options are specific to the core of the theme and ideally should not be changed by the user for a child theme, both the Redux code and the config should stay in the parent theme. Again, that's my understanding of how it all works. The last time I experimented with all of this, I created a twentyfourteen child theme, left Redux and the config in the parent theme, and everything ran fine. If it's not on your end, it's an error in how it's setup.

If you are embedding, it's really as simple as putting this in the parent theme's functions.php

This example assumes the following directory structure: theme-dir functions.php --redux-framework ----ReduxCore ------framework.php ----sample ------sample-config.php

if ( !class_exists( 'ReduxFramework' ) && file_exists( dirname( __FILE__ ) . '/redux-framework/ReduxCore/framework.php' ) ) {
    require_once( dirname( __FILE__ ) . '/redux-framework/ReduxCore/framework.php' );
}

if ( file_exists( dirname( __FILE__ ) . '/redux-framework/sample/sample-config.php' ) ) {
    require_once( dirname( __FILE__ ) . '/redux-framework/sample/sample-config.php' );
}

It's that simple.

kprovance avatar Mar 18 '14 18:03 kprovance

Thank you so much for your reply. I really appreciate your dedication on this awesome project!

Have a great day! :+1:

pseudonymus avatar Mar 18 '14 22:03 pseudonymus

As much as I want to say that you're right, It still doesn't work on my side.

I just downloaded the latest version of the framework from Github, I made a fresh install, got the whole framework folder(didn't delete a single file of it, as you can see from the screenshot: http://goo.gl/xvfTbX ) placed it in the same order like you mentioned above in the twentyfourteen theme:

twentyfourteen --functions.php --redux-framework ----ReduxCore ------framework.php ----sample ------sample-config.php

Called the files in parent functions.php:

if ( !class_exists( 'ReduxFramework' ) && file_exists( dirname( __FILE__ ) . '/redux-framework/ReduxCore/framework.php' ) ) {
    require_once( dirname( __FILE__ ) . '/redux-framework/ReduxCore/framework.php' );
}
if ( file_exists( dirname( __FILE__ ) . '/redux-framework/sample/sample-config.php' ) ) {
    require_once( dirname( __FILE__ ) . '/redux-framework/sample/sample-config.php' );
}

Created a child theme just with the screenshot and stylesheet.

The options panel appears in parent theme: http://awesomescreenshot.com/0852igy218 , but it doesn't appear in the child theme: http://awesomescreenshot.com/0502igyaf1

I tested to see if the files are getting loaded in the child theme. They do, as you can see from those screenshots, but the options panel doesn't...

Any thoughts about this situation?

Thank you!

pseudonymus avatar Mar 18 '14 23:03 pseudonymus

Not really. I can't fix what I can't break. Still has to be something in your setup, somewhere.

kprovance avatar Mar 19 '14 00:03 kprovance

Hey, it seems to work if I just use:

$this->initSettings();

Instead of the default call:

// This is needed. Bah WordPress bugs.  ;)
if (strpos(Redux_Helpers::cleanFilePath(__FILE__), Redux_Helpers::cleanFilePath(get_stylesheet_directory())) !== false) {
    $this->initSettings();
} else {
    add_action('plugins_loaded', array($this, 'initSettings'), 10);
}

Thanks!

pseudonymus avatar Mar 19 '14 09:03 pseudonymus

Aha. Well that's because you do it slightly different than others. But yes, that would should solve the issue. @kprovance can we see if there's a better WP call we could make in a child theme that could bypass the check?

dovy avatar Mar 19 '14 13:03 dovy

@kprovance @dovy I recreated the problem here using twentyfourteen. Here are the steps:

  1. Downloaded Redux from the repo as zip and installed it using the Upload Plugin function.
  2. Created includes folder in the twentyfourteen directory and copied the sample folder from the zip in *twentyfourteen\includes* 1
  3. Added the following line at the bottom of the functions.php in twentyfourteen: require_once( get_template_directory() . '/includes/sample/sample-config.php' );
  4. Created a child theme with only screenshot and style.css with the line: [at]import url("../twentyfourteen/style.css");

Here is a link to the parent, child and zip file: https://www.dropbox.com/sh/jka5uxex3jnmox5/dg_dWftnbG

The options panel shows in the parent theme, but not in the child. I hope you can recreate the problem.

pnpetroff avatar Mar 19 '14 17:03 pnpetroff

I just pushed a fix in which Redux checks for either parent or child.

kprovance avatar Mar 19 '14 17:03 kprovance

Whoa, fast!

Tried it now. Why us it now after the plugin is installed the Options link is not showed until I click on the: Redux Framework has an embedded demo. Click here to activate the sample config file.

How can it be activated without clicking it? I've uncommented: add_action( 'redux/loaded', array( $this, 'remove_demo' ) );

pnpetroff avatar Mar 19 '14 17:03 pnpetroff

That's the demo mode, and uncommenting that won't change anything.

This is what I use in the parent function.php to include the config:

require_once( dirname( __FILE__ ) . '/path/to/sample-config.php' );

It works. I've tested it multiple times today in parent, child, demo and not demo mode.

kprovance avatar Mar 19 '14 17:03 kprovance

Using this: require_once( dirname( FILE ) . '/includes/sample/sample-config.php' ); in the above twentyfourteen parent theme that I've uploaded doesn't get the link to show up after installing the plugin (without clicking on that notice, but I'm sure that it doesn't load the file in the includes folder) :\

pnpetroff avatar Mar 19 '14 17:03 pnpetroff

I'm not sure what to tell you at this point. I can't fix what I can't break.

kprovance avatar Mar 19 '14 18:03 kprovance

This is the link with the files that have to to be copied into the twentyfourteen directory: https://www.dropbox.com/sh/5447134mjbd9p2a/pltlXQHG-a

After that Delete and install the zip from the repo as plugin. The menu don't have to appear until clicking on the notice.

You should be able to reproduce the problem... I hope :\

pnpetroff avatar Mar 19 '14 18:03 pnpetroff

We're getting into premium support territory here. As I've not been able to reproduce this, it's more than likely a problem with your code or your server's config. It's $125.00 an hour for me to download your code and go through it to see where the problem is.

kprovance avatar Mar 19 '14 18:03 kprovance

I don't have any custom code except the include, so it looks like I'll remove the check, and it starts to work perfectly on a clean installation of Wordpress.

$this->initSettings();

pnpetroff avatar Mar 19 '14 22:03 pnpetroff

LOL, good grief. Maybe you don't have the latest version, because I put checks for parent and child in the sample config. This is why I don't like when people say 'latest version', because it almost always isn't. The __construct for the sample-config should say this:

            // This is needed. Bah WordPress bugs.  ;)
            if (true == Redux_Helpers::isChildTheme() || true == Redux_Helpers::isParentTheme()) {
                $this->initSettings();
            } else {
                add_action('plugins_loaded', array($this, 'initSettings'), 10);
            }

kprovance avatar Mar 19 '14 22:03 kprovance

I have the latest version. The code that you quoted is exactly the check that I removed from the sample-config.php and left only the $this->initSettings(); part. It looks I didn't explain it well.

pnpetroff avatar Mar 20 '14 00:03 pnpetroff

Well, whatever works. It suggests there is something about your server or local install that doesn't agree with the checks. But as I can't reproduce it, I really can't fix it.

kprovance avatar Mar 20 '14 00:03 kprovance