簡體   English   中英

Wordpress wp_editor 括號錯誤解決方法

[英]Wordpress wp_editor bracket bug workaround

我試圖讓所見即所得編輯器在自定義選項頁面上工作。 但是我不允許使用方括號作為編輯器 ID。

這是我目前使用的代碼。 (以此為起點: http : //themeshaper.com/2010/06/03/sample-theme-options/

            <?php

                $content =  $options['sometextarea'];
                $editor_id = 'some_theme_options[sometextarea]';

                $settings =   array(
                    'wpautop' => false, 
                    'media_buttons' => false, 
                    'textarea_name' => $editor_id,
                    'textarea_rows' => get_option('default_post_edit_rows', 10), 
                    'tinymce' => true,
                    'quicktags' => true
                );
                wp_editor( $content , $editor_id, $settings  );

                ?>

有人可以向我解釋如何讓這個工作嗎? 使用當前代碼,我只能獲得帶有快速標簽的所見即所得編輯器。 如果我將 $editor_id 重命名為純文本,我可以獲得完整的編輯器,但它不會保存。

我終於讓它正常工作了!

這是如何:

                <?php

                $content =  $options['sometextarea'];
                $editor_id = 'sometextarea';

                $settings =   array(
                    'wpautop' => false, 
                    'media_buttons' => false, 
                    'textarea_name' => 'mythemename_theme_options[sometextarea]', //You can use brackets here !
                    'textarea_rows' => get_option('default_post_edit_rows', 10), 
                    'tabindex' => '323',
                    'editor_css' => '', 
                    'editor_class' => '',
                    'teeny' => false, 
                    'dfw' => false,
                    'tinymce' => true, 
                    'quicktags' => true 
                );
                wp_editor( $content , $editor_id, $settings  );

                ?>

這個問題是由$editor_id參數引起的,所以給它一個不帶括號 [] 的名稱,而不是my_text_area_id_['textarea']只是給它一個像my-textarea-id這樣的普通 ID,它應該可以工作!

wp_editor( 

   string $content, 

    string $editor_id, 

   array $settings = array() 
);

參考: https : //developer.wordpress.org/reference/functions/wp_editor/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM