WordPress.org

Ready to get started?Download WordPress

Forums

OptionTree
[resolved] Path Issues in 'Theme Mode' when Using a Child Theme Fix (5 posts)

  1. IntricatePixels
    Member
    Posted 1 year ago #

    Hello and thanks for this great plugin.

    I'm using the Genesis framework with a custom child theme. Today I decided to set up OptionTree in theme mode. Your instruction are clear and made the set up process easy to follow.

    However, I ran into an issue (that I fixed), that I'd like to report (not sure if this is already reported and you're well aware of it, if that's the case, sorry for the double post).

    Because I'm using a child theme I was getting errors about files not being found.

    Warning: require_once(C:\Inetpub\newwww-site-dev/wp-content/themes/genesis/option-tree/includes/ot-functions-admin.php) [function.require-once]: failed to open stream: No such file or directory in C:\Inetpub\newwww-site-dev\wp-content\themes\My.Child.Theme\option-tree\ot-loader.php on line 183

    Then I realized that the 'OT_DIR' and 'OT_URL' were always being set to the parent theme paths, ignoring Child themes.

    ot-loader.php, around line 128:

    if ( false == OT_THEME_MODE ) {
            define( 'OT_DIR', plugin_dir_path( __FILE__ ) );
            define( 'OT_URL', plugin_dir_url( __FILE__ ) );
    	  } else {
            define( 'OT_DIR', trailingslashit( get_template_directory() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
            define( 'OT_URL', trailingslashit( get_template_directory_uri() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
          }

    To set the child directory paths if they exist, I modified the code to:

    if ( false == OT_THEME_MODE ) {
            define( 'OT_DIR', plugin_dir_path( __FILE__ ) );
            define( 'OT_URL', plugin_dir_url( __FILE__ ) );
    	  } elseif ( is_child_theme() ) {
    		define( 'OT_DIR', trailingslashit( get_stylesheet_directory() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
            define( 'OT_URL', trailingslashit( get_stylesheet_directory_uri() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
    	  } else {
            define( 'OT_DIR', trailingslashit( get_template_directory() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
            define( 'OT_URL', trailingslashit( get_template_directory_uri() ) . trailingslashit( basename( dirname( __FILE__ ) ) ) );
          }

    The code checks if the theme in use is a child theme (is_child_theme) and sets the dir and url using get_stylesheet_directory() and get_stylesheet_directory_uri().

    Hope this helps out anyone else running into this issue. It would be nice to see this fix included in the next release.

    Again, many thanks for the awesome plugin!

    http://wordpress.org/extend/plugins/option-tree/

  2. Derek Herman
    Member
    Plugin Author

    Posted 1 year ago #

    Thank you for the suggestion, it's a good one. However, at a glance it appears your code maybe would only work if OptionTree was in a child theme and not in a parent theme because it doesn't do any checking for the existence of those files just checks if it's a child theme. A better solution would be to allow themes the option to filter the paths, which I'll look into for the next version. Thanks @IntricatePixels.

  3. Derek Herman
    Member
    Plugin Author

    Posted 1 year ago #

    I created a new issue on github and added it to the 2.0.15 milestone. You can keep track of it here.

    https://github.com/valendesigns/option-tree/issues/78

  4. Derek Herman
    Member
    Plugin Author

    Posted 1 year ago #

    There is a new filter to use the plugin in child theme mode as of version 2.0.15

  5. IntricatePixels
    Member
    Posted 1 year ago #

    Thanks for implementing this Derek, child theme filter works like a charm!

    / Required: set 'ot_child_theme_mode' filter to true.
    add_filter( 'ot_child_theme_mode', '__return_true' );

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic