Use 'the_content' hook

This commit is contained in:
Nathan Schneider 2024-06-17 10:45:44 -03:00
parent c58802a402
commit 5eeb7c93c1
1 changed files with 8 additions and 14 deletions

View File

@ -26,26 +26,20 @@ class ProductFormsController {
*/ */
public function init() { // phpcs:ignore WooCommerce.Functions.InternalInjectionMethod.MissingFinal, WooCommerce.Functions.InternalInjectionMethod.MissingInternalTag -- Not an injection. public function init() { // phpcs:ignore WooCommerce.Functions.InternalInjectionMethod.MissingFinal, WooCommerce.Functions.InternalInjectionMethod.MissingInternalTag -- Not an injection.
add_action( 'upgrader_process_complete', array( $this, 'migrate_templates_when_plugin_updated' ), 10, 2 ); add_action( 'upgrader_process_complete', array( $this, 'migrate_templates_when_plugin_updated' ), 10, 2 );
add_action( 'rest_post_dispatch', array( $this, 'maybe_add_product_form_templates' ), 10, 3 ); add_action( 'the_content', array( $this, 'maybe_add_product_form_templates' ), 10, 2 );
} }
/** /**
* Maybe add product form templates to the posts array. * Maybe add product form templates to the posts array.
*/ */
public function maybe_add_product_form_templates( $response, $server, $request ) { public function maybe_add_product_form_templates( $content ) {
if ( $request->get_route() === '/wp/v2/product_form' ) { $post = get_post();
$test = new SimpleProductTemplate();
$response->data[] = array( if ( 'product_form' === $post->post_type && 'Simple' === $post->post_title ) {
'content' => array( 'raw' => $test->get_comment_delimited_template() ), $simple = new SimpleProductTemplate();
'id' => 9999, return $simple->get_comment_delimited_template();
'title' => array(
'raw' => 'simple_test',
'rendered' => 'simple_test',
),
'excerpt' => array( 'ray' => 'simple_test' ),
);
} }
return $response; return $content;
} }
/** /**