문제

I am relatively new to wordpress development, I am trying to extend 'Walker_Category_Checklist' class found in /wp-admin/includes/class-walker-category-checklist.php to customize it for wp_terms_checklist() or wp_category_checklist() but when I try to require_once a link to my extended class in the child-theme function.php I get this error and site not loading!

x" Fatal error: Class 'Walker_Category_Checklist' not found in ..... "

Is it because of this class file in 'wp-admin/includes/' dir? if so then how to extend it ?

wordpress ver: 5.6 - php ver: 7.2

Thanks in advance Cheers Mo.

도움이 되었습니까?

해결책 2

I could not extend directly Walker_Category_Checklist I think because it's in wp-admin dir. even it's for "output an unordered list of category checkbox"!! similar classes to it etc. "Walker_Nav_Menu" existing in wp-include witch is should be the right place for the "Walker_Category_Checklist" I guess.. The answer that I found is going around by extending the parent class "Walker" to "my_Walker_Category_Checklist" then copy the code from "Walker_Category_Checklist" then do my customization on it, like that everything if working.

다른 팁

You can extend it, but the class definition and any code that uses it, can't run outside of the admin area.

Wrap your class in this conditional:

if ( is_admin() ) {
    ...
}

If you are trying to use this on the frontend or other non-Admin areas, do not do that.

Generally, classes WordPress uses should not be extended, walker classes and WP_Widget are the notable extensions.

Also, it's good practice to put classes in their own files.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 wordpress.stackexchange
scroll top