*

MvdO79

  • ***
  • 32 posts
Child theme problems
« on: August 08, 2021, 02:23:53 AM »
I am using a child theme created from main delta theme, this works fine with some changes I made on user-login / user-register.

But some changes are not working:

- I can activate my child theme and set a logo, but the logo of the main theme is used
- Changes in the footer are not showing in the child theme, if I change the same stuff in the main theme footer of course it works

So some things are working others not, any direction what can cause these problems?

My delta_child index.php:

Code: [Select]
<?php
/*
Theme Name: Delta Child Osclass Theme
Theme URI: https://osclasspoint.com/osclass-themes/general/delta-osclass-theme_i170
Description: Premium front-end theme for classifieds script Osclass
Version: 1.1.3
Author: MB Themes
Author URI: https://osclasspoint.com
Widgets: header,footer
Theme update URI: delta-osclass-theme
Product Key: xxx
Parent Theme: delta
*/
?>

*

MvdO79

  • ***
  • 32 posts
Re: Child theme problems
« Reply #1 on: August 08, 2021, 03:57:08 PM »
Reading up on how child themes are created, think this will solve my problems:

https://osclasspoint.com/blog/osclass-create-child-theme-b21

Marked as best answer by MvdO79 on August 10, 2021, 01:00:16 AM
*

MB Themes

Re: Child theme problems
« Reply #2 on: August 09, 2021, 08:42:13 AM »
@MvdO79
There are few major issues with child theme.
It is not "issue" as "issue", but I think this is not way you would prefer for child themes.

The core issue is, that i.e. if you want to replace footer, you must do it in all files.
What does it means? If you create footer.php and main.php, update footer in child theme and will be OK on home page.
But, when you go to item page, old footer is used.
Why so? Because you have not replaced item.php in child theme, this means item.php of parent theme is used and this one includes footer from parent theme.

I am planning to spend some time to investigate, if this could be changed in:
Code: [Select]
<?php osc_current_web_theme_path('some-file') ; ?>
Code: [Select]
<?php osc_current_web_theme_url('some-file') ; ?>
Right now path depends on file that calls it, I would prefer check in case you use child theme.

Right now, these function are created in hDefines.php and looks like this:
Code: [Select]
/**
 * Gets the complete url of a given file using the theme url as a root
 *
 * @param string $file the given file
 * @return string
 */
function osc_current_web_theme_url($file = '') {
  $info = WebThemes::newInstance()->loadThemeInfo(WebThemes::newInstance()->getCurrentTheme());
  if (!file_exists(WebThemes::newInstance()->getCurrentThemePath() . $file) && isset($info['template']) && $info['template'] != ''){
    WebThemes::newInstance()->setParentTheme();
  }
  return WebThemes::newInstance()->getCurrentThemeUrl() . $file;
}

/**
 * Gets the complete path of a given file using the theme path as a root
 *
 * @param string $file
 * @return string
 */
function osc_current_web_theme_path($file = '') {
  $info = WebThemes::newInstance()->loadThemeInfo(WebThemes::newInstance()->getCurrentTheme());

  if( file_exists(WebThemes::newInstance()->getCurrentThemePath() . $file) ){
    require WebThemes::newInstance()->getCurrentThemePath() . $file;
  } elseif($info['template'] != '') {
    WebThemes::newInstance()->setParentTheme();
    if( file_exists(WebThemes::newInstance()->getCurrentThemePath() . $file) ) {
      require WebThemes::newInstance()->getCurrentThemePath() . $file;
    } else {
      WebThemes::newInstance()->setGuiTheme();
      if( file_exists(WebThemes::newInstance()->getCurrentThemePath() . $file) ) {
        require WebThemes::newInstance()->getCurrentThemePath() . $file;
      }
    }
  } else {
    WebThemes::newInstance()->setGuiTheme();
    if( file_exists(WebThemes::newInstance()->getCurrentThemePath() . $file) ) {
      require WebThemes::newInstance()->getCurrentThemePath() . $file;
    }
  }
}

That is problem, because if file exists, it does not look for anything else. Child theme conditions are like "just in case".

I've played with it for more than 2 hours and here is new version of files (modified for osclass 4.4) that will always check child/parent theme files no matter if you have child theme or parent theme activated. Will be updated and fixed in 4.5, but for easy of testing and use, try to replace with following functions:
Code: [Select]

/**
 * Gets the complete url of a given file using the theme url as a root
 *
 * @param string $file the given file
 * @return string
 */
function osc_current_web_theme_url($file = '') {
  $theme = WebThemes::newInstance()->getCurrentTheme();
  $file_fix = explode('?', $file)[0];  // remove version from file, i.e. style.css?v=21311
  $theme_split = explode('_', $theme);

  // HANDLE CHILD THEME IN BEST POSSIBLE WAY (v450)
  if(1==1) {
    if(isset($theme_split[1]) && $theme_split[1] == 'child') {
      $theme_child = $theme;
      $theme = $theme_split[0];
    } else {
      $theme_child = $theme . '_child';
      $theme = $theme;
    }

   
    WebThemes::newInstance()->setCurrentTheme($theme_child);

    if(file_exists(WebThemes::newInstance()->getCurrentThemePath() . $file_fix)){
      return WebThemes::newInstance()->getCurrentThemeUrl() . $file;
    }
   
    WebThemes::newInstance()->setCurrentTheme($theme);

    if(file_exists(WebThemes::newInstance()->getCurrentThemePath() . $file_fix)) {
      return WebThemes::newInstance()->getCurrentThemeUrl() . $file;
    }
  }
}

/**
 * Gets the complete path of a given file using the theme path as a root
 *
 * @param string $file
 * @return string
 */
function osc_current_web_theme_path($file = '') {
  $theme = WebThemes::newInstance()->getCurrentTheme();
  $theme_split = explode('_', $theme);

  if(1==1) {
    if(isset($theme_split[1]) && $theme_split[1] == 'child') {
      $theme_child = $theme;
      $theme = $theme_split[0];
    } else {
      $theme_child = $theme . '_child';
      $theme = $theme;
    }

   
    WebThemes::newInstance()->setCurrentTheme($theme_child);

    if(file_exists(WebThemes::newInstance()->getCurrentThemePath() . $file)){
      require WebThemes::newInstance()->getCurrentThemePath() . $file;
      return;
    }
   
    WebThemes::newInstance()->setCurrentTheme($theme);
   
    if(file_exists(WebThemes::newInstance()->getCurrentThemePath() . $file)) {
      require WebThemes::newInstance()->getCurrentThemePath() . $file;
      return;
    }
   
    WebThemes::newInstance()->setGuiTheme();
   
    if(file_exists(WebThemes::newInstance()->getCurrentThemePath() . $file)) {
      require WebThemes::newInstance()->getCurrentThemePath() . $file;
    }
  }
}

For me it worked better I was expecting.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

MvdO79

  • ***
  • 32 posts
Re: Child theme problems
« Reply #3 on: August 10, 2021, 12:44:27 AM »
THANK you for diving in to this, I didn't saw an alert about your post so sorry for replying so late.
I am gonna read up on your approach, thanks again!  :)