如何解决将 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,blockquote,justifyleft,justifycenter,justifyright,link,unlink,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 标签,请使用:
信用:A 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 );
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。