php - 插件激活后自动创建一个带有古腾堡 HTML 块的页面
问题描述
我已经设法在插件激活时创建了一个页面。我需要向创建的页面添加内容。所以我使用了以下代码。问题是它在页面中创建了一个经典编辑器,而不是古腾堡 HTML 编辑器。
register_activation_hook( __FILE__, 'my_plugin_install_function');
function my_plugin_install_function()
{
//post status and options
$post = array(
'comment_status' => 'closed',
'ping_status' => 'closed' ,
'post_author' => get_current_user_id(),
'post_date' => date('Y-m-d H:i:s'),
'post_name' => 'Checklists',
'post_status' => 'publish' ,
'post_content' => '[customization-shortcode]',
'post_title' => 'Checklists',
'post_type' => 'dash',
);
//insert page and save the id
$newvalue = wp_insert_post( $post, false );
//save the id in the database
update_option( 'hclpage', $newvalue );
}
我希望我的简码显示在古腾堡 HTML 块中,而不是经典编辑器中
解决方案
我找到了解决方案,我所做的只是更改以下行:
'post_content' => '[customization-shortcode]',
到
'post_content' => '<!-- wp:html -->[customization-shortcode]<!-- /wp:html -->',
这将创建一个通常的古腾堡 HTML 块,而不是旧的经典块。
推荐阅读
- qt - 如何更改 qcombobox 悬停时的下拉背景颜色?
- r - 如何加快Probit?
- javascript - 尝试将变量与数组中的字段匹配并返回结果
- c++ - Gl_UseProgram 不影响着色器
- mysql - 使用 MariaDB/MySQL 继续获得 1064
- samsung-knox - 如何将 200 个平板电脑添加到 Samsung Knox?
- python - Matplotlib 在 Python 中替换用户输入变量
- java - 如果检查了所有 RadioGroup,如何处理?
- java - SQL group_concat 删除左连接
- c# - 来自文件或流的 UWP 语音识别