init hook function causes comments to be closed.
-
Hi
I’ve written myself a small plugin which takes a custom post type and uses an init hook action to select them and register them as block pattern using register_block_pattern and register_block_pattern_category.
This all works really well, BUT, it seems to cause a problem when you try and submit a comment. Basically, I’m getting a “Sorry, comments are closed for this item.” from wp-comments-post.php.
If I comment out the init hook call, comments work again.
I’m not really sure how to approach debugging this one!
This is the hook being called:
function grab_patterns_for_registration() { $patterns = new WP_Query( array( 'post_type' => 'patterns', 'post_status' => 'publish' ) ); if ( $patterns->have_posts() ) { while ( $patterns->have_posts() ) { $patterns->the_post(); $pattern_name = 'patterns/' . get_post_field( 'post_name'); $content = get_the_content(); $title = get_the_title(); $postID = get_the_ID(); $category = get_post_meta(get_the_ID(),'pattern_category', true); /* if no category is set, give it a default */ if (!$category) { $category = 'Custom Patterns'; } /* Add the category */ register_block_pattern_category( $category, array( 'label' => __( $category, 'addpatterns' ) ) ); /* Register the block category */ register_block_pattern($pattern_name, [ 'title' => __($title, 'addpatterns'), 'categories' => [$category], 'content' => $content, ]); } } /* Restore original Post Data */ wp_reset_postdata(); } add_action('init', 'grab_patterns_for_registration');
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘init hook function causes comments to be closed.’ is closed to new replies.