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

The function hu_is_authorized_tmpl is not pluggable and can't be rewritten in the child theme #990

Open
Arskrigitsioniets opened this issue Nov 4, 2023 · 1 comment

Comments

@Arskrigitsioniets
Copy link

Arskrigitsioniets commented Nov 4, 2023

The function hu_is_authorized_tmpl located in (functions/init-front.php:47) isn't pluggable.

if( ! function_exists('hu_is_authorized_tmpl') ) {
  function hu_is_authorized_tmpl( $tmpl ) {
    $ct_map = apply_filters(
        'hu_content_map',
        array( 'tmpl/index-tmpl', 'tmpl/archive-tmpl', 'tmpl/page-tmpl', 'tmpl/single-tmpl', 'tmpl/search-tmpl', 'tmpl/404-tmpl' )
    );
    //Are we good after filtering ?
    if ( ! is_array( $ct_map ) || ! is_string( $tmpl ) )
      return;
    return in_array( $tmpl, $ct_map );
}
}

Because this function define the list of allowed template files that Hueman can read with hu_get_content function, it doesn't allow creating custom templates, for example, for custom type posts. To make Hueman read my custom template from /tmpl, I should add this file it to the "authorized list", but it works only if I do it in the parent theme. Child theme ignores this function. So, I should update this file after each Hueman update manually if I have custom tmpl files.

The solution is simple: make the hu_is_authorized_tmpl pluggable.

@iamwebrocker
Copy link

iamwebrocker commented Feb 17, 2024

Thank you for this issue.
I really felt stupid, since in the functions.php of the theme the use of a child theme is encouraged, and then one of the (to me) simplest use case -- create a custom page template to include output coming from some AFC fields -- just didn't work.
I pulled several hairs, until I found this and the other closed issue #610 with the discussion.

Now, after looking at this function, I was able to add "my" template via the filter hu_content_map in the function.php of my child theme:

function hueman_child_content_map() {
	return array( 
	   // the original templates:
	   'tmpl/index-tmpl', 
	   'tmpl/archive-tmpl', 
	   'tmpl/page-tmpl', 
	   'tmpl/single-tmpl', 
	   'tmpl/search-tmpl', 
	   'tmpl/404-tmpl',
	   // my template:
	   'tmpl/page-custom-tmpl' 
	 );
}
add_filter('hu_content_map','hueman_child_content_map');

The solution is simple: make the hu_is_authorized_tmpl pluggable.

Since the filter works, I don't think a change of the original function is needed for that template use case.
But, maybe the filter should'nt replace the original templates array, but merge with whatever one wants to add to that.
Currently using the filter without also stating the original templates would remove those, which isn't such a good idea, I'm arfraid.

Cheers!

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