/**
     * フロントエンドにて編集ができるように、the_content にフィルタをかける
     *
     *
     * @param $content
     * @return string
     */
    public function replace_content($content)
    {
        if (BCE_Utilis::check_edit_post()) {
            $post_id = get_the_ID();
            $block_content = get_post_meta($post_id, 'block_content', true);
            require_once WPINC . '/class-wp-editor.php';
            wp_editor('', 'content', array('textarea_rows' => 15, 'teeny' => true, 'quicktags' => true, 'media_buttons' => true));
            $save_text = __('Save', 'block-content-editor');
            $nonce = wp_create_nonce(__FILE__);
            $form = <<<FORM
<div id="front-block-content-editor-container" style="display: block; background: #fff;">
    <form name="front-block-content-editor-form" id="front-block-content-editor-form" action="?" method="post">
        <input type="hidden" name="front-block-content-editor-nonce" id="front-block-content-editor-nonce" value="{$nonce}" />
        <input type="hidden" name="front-block-content-editor-post_id" id="front-block-content-editor-post_id" value="{$post_id}" />
        <textarea name="block_content" id="front-block-content-editor" style="display: none;">{$block_content}</textarea>
        <div class="front-block-content-editor__submit">
            <button id="front-block-content-editor-submit" type="submit">{$save_text}</button>
        </div>
    </form>
    </div>
FORM;
            return $form;
        }
        return $content;
    }
Ejemplo n.º 2
0
 public function init()
 {
     if (!is_admin() && BCE_Utilis::is_enabled_editor()) {
         wp_enqueue_media();
     }
     $this->type = 'wpimage';
     $this->class = 'wpimage';
     $this->param = array('url', 'alt');
     $this->admin_javascript = array(plugin_dir_url(__FILE__) . 'wpimage.js');
     $this->template = '
     <div class="bce-block bce-block__image">
         <img src="%url%" alt="%alt%"/>
     </div>
     ';
 }
Ejemplo n.º 3
0
 /**
  * 多言語化を設定
  *
  * @since    1.0.0
  * @access   private
  */
 private function set_locale()
 {
     $plugin_i18n = new BCE_i18n();
     $plugin_i18n->set_domain(BCE_Utilis::get_plugin_name());
     $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');
 }
 /**
  * 管理画面の静的ファイルを登録
  *
  * @param $hook
  * @return bool
  */
 public function admin_enqueue_script($hook)
 {
     if (!BCE_Utilis::is_enabled_editor()) {
         return false;
     }
     if (isset($this->admin_javascript) && is_array($this->admin_javascript)) {
         foreach ($this->admin_javascript as $i => $js_path) {
             wp_enqueue_script($this->type . '_' . $i . '_' . 'js', $js_path, array(), null, true);
             if ($this->type == 'tinymce') {
                 wp_localize_script('tinymce_1_js', 'bce_tinymce_url', array('url' => plugin_dir_url(__FILE__) . 'tinymce/'));
             }
         }
     }
     if (isset($this->admin_css) && is_array($this->admin_css)) {
         foreach ($this->admin_css as $i => $css_path) {
             wp_enqueue_style($this->type . '_' . $i . '_' . 'css', $css_path, array());
         }
     }
 }
 /**
  * 記事を保存するタイミングで、カスタムフィールドとしてブロックエディタのコンテンツを保存する
  * @param $post_id
  *
  * @return bool
  */
 public function block_content_update($post_id)
 {
     remove_action('save_post', array($this, 'block_content_update'));
     if (!BCE_Utilis::is_enabled_editor()) {
         return false;
     }
     $block_content = isset($_REQUEST['block_content']) ? $_REQUEST['block_content'] : '';
     if (!$block_content || strlen($block_content) < 16) {
         return false;
     }
     update_post_meta($post_id, 'block_content', $block_content);
     /**
      * 強制保存が有効な場合は投稿コンテンツに保存。
      * それ以外の場合には、カスタムフィールドに値を保存する
      **/
     if ($this->force_post_content_save == true) {
         wp_update_post(array('ID' => $post_id, 'post_content' => $this->get_contents($post_id)));
     } else {
         update_post_meta($post_id, 'block_content_html', $this->get_contents($post_id));
     }
     add_action('save_post', array($this, 'block_content_update'));
 }
 /**
  * 投稿エディタにブロックコンテンツエディタ用のマークアップを追加
  * @param $content
  * @return string
  */
 public function the_editor($content)
 {
     if (!BCE_Utilis::is_enabled_editor()) {
         return $content;
     }
     $post_id = isset($_REQUEST['post']) ? intval($_REQUEST['post']) : '';
     $block_content = get_post_meta($post_id, 'block_content', true);
     return $content . '<div id="block-content-editor-container" style="display: none; background: #fff;"><textarea name="block_content" id="block-content-editor">' . $block_content . '</textarea></div>';
 }