Set a Default Document Tree v3.10
The wpce_default_document filter allows to define a document tree which is automatically inserted when a post is created:
php
add_filter('wpce_default_document', function ($document, $post, $wpce) {
if ($post->post_type === 'post') {
// Define the default document tree
$document = [
'id' => 'root',
// ...
];
}
return $document;
}, 10, 3);TIP
The easiest way to get hold of a document tree for this filter is to
- create your desired document in the WPCE editor
- copy its JSON by right-clicking the root element and selecting the "Element-JSON kopieren" context menu item
- remove all
guidproperties from the JSON - paste it into the JS to PHP converter to receive the document tree as a PHP array.
- Make sure to cast objects to
(object)where necessary.
A more specific example is shown below.
php
// https://wpce.docs.ownb.it/cookbook/default-document.html
add_filter('wpce_default_document', function ($document, $post, $wpce) {
if ($post->post_type === WPDT\PostTypes\Glossary\POST_TYPE) {
// Define the default document tree
$document = (object) [
'id' => 'root',
'children' => [
(object) [
'id' => 'text',
'visible' => true,
'children' => [],
'properties' => [
'content' => 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.',
],
]
],
'visible' => true,
'properties' => [
'documentVersion' => '1.0.0',
'wpceVersion' => '3.14.0'
],
'name' => 'Inhalt'
];
}
return $document;
}, 10, 3);