Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Learnpress 4.2.0 Broke Addon Templates being loaded from Themes and Child Themes #532

Open
Polybear-Philippe opened this issue Dec 27, 2022 · 1 comment

Comments

@Polybear-Philippe
Copy link

The updates to get_template in inc/abstracts/abstract-addon.php disallowed template loading from Child Themes. This is the function:

	public function get_template( string $template_name = '', $args = [] ) {
		$default_path        = $this->plugin_folder_path . "/templates/$template_name";
		$folder_name_rewrite = learn_press_template_path();
		$from_theme_path     = sprintf(
			'%s/%s/%s/%s/%s',
			get_template_directory(),
			$folder_name_rewrite,
			'addons',
			str_replace( 'learnpress-', '', $this->plugin_folder_name ),
			$template_name
		);
		$path_load           = file_exists( $from_theme_path ) ? $from_theme_path : $default_path;
		Template::instance()->get_template( $path_load, $args );
	}

There are a few problems here:

  • get_template_directory() only returns the Theme not a child theme so you cannot put the template in the child theme
  • file_exists call doesn't really work as the template_name doesn't have a ".php" suffix so it won't even find the template in a theme.
@tungnxt89
Copy link
Collaborator

tungnxt89 commented Jan 10, 2023

Hi Polybear-Philippe,

get_template_directory() only returns the Theme not a child theme so you cannot put the template in the child theme

We added the commit.

file_exists call doesn't really work as the template_name doesn't have a ".php" suffix so it won't even find the template in a theme.

The file_exists function checks whether a file or directory exists. So if you set $template_name wrong, it will not run right.

Thanks for the feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants