php - 将 WooCommerce 产品简短描述限制为仅文本(禁用 tinymce 编辑器)
问题描述
我想限制产品简短描述,以便只能添加文本。(禁用 tinymce 编辑器)。由于常规帖子中有帖子摘录。
当前的:
- 产品简短描述 = TinyMCE 编辑器
预期的:
- 常规帖子摘录=仅文本
根据我的发现,这就是 WooCommerce 用来替换标准摘录框的方法。
在第 119 行的 includes/admin/class-wc-admin-meta-boxes.php中有
add_meta_box( 'postexcerpt', __( 'Product short description', 'woocommerce' ), 'WC_Meta_Box_Product_Short_Description::output', 'product', 'normal' );
指的是includes/admin/meta-boxes/class-wc-meta-box-product-short-description.php
/**
* WC_Meta_Box_Product_Short_Description Class.
*/
class WC_Meta_Box_Product_Short_Description {
/**
* Output the metabox.
*
* @param WP_Post $post Post object.
*/
public static function output( $post ) {
$settings = array(
'textarea_name' => 'excerpt',
'quicktags' => array( 'buttons' => 'em,strong,link' ),
'tinymce' => array(
'theme_advanced_buttons1' => 'bold,italic,strikethrough,separator,bullist,numlist,separator,blockquote,separator,justifyleft,justifycenter,justifyright,separator,link,unlink,separator,undo,redo,separator',
'theme_advanced_buttons2' => '',
),
'editor_css' => '<style>#wp-excerpt-editor-container .wp-editor-area{height:175px; width:100%;}</style>',
);
wp_editor( htmlspecialchars_decode( $post->post_excerpt, ENT_QUOTES ), 'excerpt', apply_filters( 'woocommerce_product_short_description_editor_settings', $settings ) );
}
}
任何意见,将不胜感激
解决方案
您可以结合某些条件使用wp_editor_settings WordPress 挂钩。
注意不仅'tinymce'
设置为false,而且'quicktags'
和'mediabuttons'
所以你得到:
function filter_wp_editor_settings( $settings, $editor_id ) {
global $post;
// Target
if ( $editor_id == 'excerpt' && get_post_type( $post ) == 'product' ) {
// Settings
$settings = array(
// Disable autop if the current post has blocks in it.
'wpautop' => ! has_blocks(),
'media_buttons' => false,
'default_editor' => '',
'drag_drop_upload' => false,
'textarea_name' => $editor_id,
'textarea_rows' => 20,
'tabindex' => '',
'tabfocus_elements' => ':prev,:next',
'editor_css' => '',
'editor_class' => '',
'teeny' => false,
'_content_editor_dfw' => false,
'tinymce' => false,
'quicktags' => false,
);
}
return $settings;
}
add_filter( 'wp_editor_settings', 'filter_wp_editor_settings', 1, 2 );
为避免您仍然可以添加/编写 html 标签,请使用:
学分:BM
function filter_woocommerce_short_description( $short_description ) {
return wp_strip_all_tags( $short_description );
}
add_filter( 'woocommerce_short_description', 'filter_woocommerce_short_description', 10, 1 );
推荐阅读
- python-3.x - 是否有一个 python 函数可以让我获取一个主 CSV 文件并将其拆分为 100 行?
- botframework - 如何添加多个 ComponentDialogs?
- asp.net - 使用嵌套布局时,是否可以将使用 Razor 引擎的部分渲染委托给父布局?
- vba - 我试图在找到字符串后删除(用户确定的)数量的段落
- xcode - 使用 Xcode Memory Graph Debugger 时出现“Memory Graph Debugger: no serialized memory graph received from LeakAgent”错误
- spring-integration - Java DSL中spring IP集成中的日志拦截器
- python - Tmux,cron 不适用于我在谷歌云上的 python 脚本
- c# - 3 个问题,每个相关……是否可以循环函数声明、调用系统对象和从字符串加载程序集?
- html - 在一行中对齐内部项目
- git - Composer 使用存储库的私有分支