2016-05-12 16 views
1

私はherbertを使用してワードプレス用のモジュールを作成しています。私はherbert wordPressプラグインフレームワークを使用してワードプレス代謝を作成する

<?php 

namespace Testing\MetaBoxes; 

use Testing\Helper; 

class ExtendMetaBoxes { 

    const WORDPRESS_CONTEXT = ['normal' => 'normal', 'advanced' => 'advanced', 'side' => 'side']; 
    const WORDPRESS_PRIORITY = ['high' => 'high', 'default' => 'default', 'low' => 'low']; 

    /** 
    * Metabox id. 
    * 
    * @var string 
    */ 
    private $id; 

    /** 
    * Metabox title. 
    * 
    * @var string 
    */ 
    private $title; 

    /** 
    * Metabox name. 
    * 
    * @var string 
    */ 
    protected $name; 

    /** 
    * Metabox nonce. 
    * 
    * @var string 
    */ 
    protected $nonce; 

    /** 
    * Metabox page. 
    * 
    * @var string 
    */ 
    private $page; 

    /** 
    * Metabox context. 
    * 
    * Allowed values from wordpress: "normal", "advanced" and "side" 
    * @var string 
    */ 
    private $context; 

    /** 
    * Metabox priority. 
    * 
    * Allowed values from wordpress: "high", "default" and "low" 
    * @var string 
    */ 
    private $priority; 

    /** 
    * Metabox callback_args. 
    * 
    * @var string 
    */ 
    private $callback_args; 

    /** 
    * Metabox view. 
    * 
    * @var herbert object 
    */ 
    private $view; 

    /** 
    * Constructs the metabox. 
    */ 
    public function __construct() 
    { 
     $this->id = 'properties-integretation-system'; 
     $this->title = Helper::get('pluginName'); 
     $this->page = 'property'; 
     $this->name = 'api_systems'; 
     $this->nonce = 'api_systems_nonce'; 
     $this->context = WORDPRESS_CONTEXT['side']; 
     $this->priority = WORDPRESS_PRIORITY['low']; 
     $this->view = herbert('twig'); 
     add_action('add_meta_boxes', [$this, 'registerMetabox']); 
    } 

    /** 
    * Adding meta box to the given page 
    */ 
    public function registerMetabox() 
    { 
     add_meta_box($this->id, $this->title, [$this, 'metaBoxTemplate'], $this->page, $this->context, $this->priority); 
    } 

    /** 
    * Prints out the metabox template. 
    * 
    * @param $post 
    */ 
    public function metaBoxTemplate() 
    { 
     echo $this->view->render('@Testing/metaboxes/api.twig'); 
    } 
} 

クラスを以下のクラスをしたように、特定のページにカスタムメタボックスをしようと、私はクラスがバックオフィスに存在することを確認するために知っているので、自動ロードされています。この linkによると、私のクラスは正しいですが、問題はそれが というメタボックステンプレートを呼び出さないということです。私が $this->metaBoxTemplate()に呼び出す方法を変更した場合は、テンプレートがロードされますが、ページ上の間違った位置にロードされます。 [$this, 'metaBoxTemplate']が実行されないが、 [$this, 'registerMetabox']が正常に実行され、どのように問題を解決できるのか誰にも分かりますか?ありがとう

答えて

1

私は問題を発見しました。問題は私が定数配列を呼び出す方法から来ていたので、私はこのように修正した:

$this->context = self::WORDPRESS_CONTEXT['side']; 
$this->priority = self::WORDPRESS_PRIORITY['low']; 
関連する問題