johnbillion / extended-cpts

A library which provides extended functionality to WordPress custom post types and taxonomies.
GNU General Public License v2.0
979 stars 96 forks source link

Fatal error Call to a member function add_rewrite_tag() #85

Closed Mte90 closed 7 years ago

Mte90 commented 7 years ago
PHP Fatal error:  Uncaught Error: Call to a member function add_rewrite_tag() on null in /srv/www/boilerplate/htdocs/wp-includes/rewrite.php
:172
Stack trace:
#0 /srv/www/boilerplate/htdocs/wp-includes/class-wp-post-type.php(575): add_rewrite_tag('%demo%', '(.+?)', 'demo=')
#1 /srv/www/boilerplate/htdocs/wp-includes/post.php(1122): WP_Post_Type->add_rewrite_rules()
#2 /srv/www/boilerplate/htdocs/wp-content/plugins/WordPress-Plugin-Boilerplate-Powered/plugin-name/includes/lib/extended-cpts/src/class-extended-cpt.php(686): register
_post_type('demo', Array)
#3 /srv/www/boilerplate/htdocs/wp-content/plugins/WordPress-Plugin-Boilerplate-Powered/plugin-name/includes/lib/extended-cpts/src/class-extended-cpt.php(215): Extended
_CPT->register_post_type()
#4 /srv/www/boilerplate/htdocs/wp-content/plugins/WordPress-Plugin-Boilerplate-Powered/plugin-name/includes/lib/extended-cpts/functions.php(61): Extended_CPT->__constr
uct('demo', Array, Array)
#5 /srv/www/boilerplate/htdocs/wp-content/plugins/WordPress-Plugin-Boilerplate-Powered/plugin-n in /srv/www/boilerplate/htdocs/wp-includes/rewrite.php on line 172

I get that error :-/

Mte90 commented 7 years ago

Ok the problems seems that is the missing init, maybe add an alert can solve this issue.

johnbillion commented 7 years ago

Yeah the library now requires that the post type is registered on the init hook, to mirror the behaviour of WordPress core's register_post_type() function. I updated the docs, but I think I'll add a warning in the code if you register a post type before the init hook.