Skip to content

Commit

Permalink
Use template instead of the default_content hook to modify the CM pla…
Browse files Browse the repository at this point in the history
…ceholder (#122)
  • Loading branch information
zaguiini authored Sep 5, 2024
1 parent 232159b commit 11846ab
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions includes/manager/class-content-model-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ private function __construct() {
add_action( 'the_post', array( $this, 'map_template_to_content_model_editor_signature' ) );

/**
* Update placeholder prompts to be more suitable for creating a new model.
* Update title placeholder to be more suitable for creating a new model.
*/
add_filter( 'enter_title_here', array( $this, 'set_title_placeholder' ), 10, 2 );
add_filter( 'default_content', array( $this, 'set_content_placeholder' ), 10, 2 );
}

/**
Expand Down Expand Up @@ -111,6 +110,12 @@ private function register_post_type() {
'show_in_menu' => true,
'show_in_rest' => true,
'supports' => array( 'title', 'editor', 'custom-fields' ),
'template' => array(
array(
'core/paragraph',
array( 'placeholder' => __( 'Start building your model' ) ),
),
),
)
);

Expand Down Expand Up @@ -329,22 +334,4 @@ public function set_title_placeholder( $title, $post ) {
}
return $title;
}

/**
* Sets the content placeholder for the Content Model post type.
*
* @param string $content The default content.
* @param WP_Post $post The current post object.
* @return string The modified default content.
*/
public function set_content_placeholder( $content, $post ) {
if ( Content_Model_Manager::POST_TYPE_NAME === $post->post_type ) {
$placeholder = __( 'Start building your model' );
return sprintf(
'<!-- wp:paragraph {"placeholder":"%s"} --><p></p><!-- /wp:paragraph -->',
esc_attr( $placeholder )
);
}
return $content;
}
}

0 comments on commit 11846ab

Please sign in to comment.