2017-01-03 34 views
0

我想看看他是否正確地做這個代碼來開發一個自定義的簡短聯繫人表單想爲我的網站創建。WordPress的簡碼Issus v3

我看過wp codex想要使用類,所以我想出了這個代碼,如果這將工作。

<?php 

class MyPlugin { 
     // Conact Form shortcode 

    public static function allb_contact_form($atts, $content = " " ) { 
      //[contact_form] 
      //get the attribute_escape 
      $atts = shortcode_atts(
      array(), 
      $atts, 
      'contact_form' 
     ); 

      //return HTML 
      ob_start(); 
      include 'lib/inc/thmeplates/contact-form.php'; 
      return ob_get_clean(); 
    } 
} 
    add_shortcode('contact_form', array($this , 'allb_contact_form')); 

但它不會給我說的錯誤消息。有個人告訴我把add_shortcode('contact_form', array($this , 'allb_contact_form'));放在代碼的外面。

+0

@Yivi它的工作謝謝你隊友 –

回答

1

如果您是使用一類的意圖,無論你正在申報您的插件添加

$myplugin = new MyPlugin(); 
add_shortcode('contact_form', [ $myplugin , 'allb_contact_form' ]); 

並從類add_shortcode。它甚至不在那裏有效的代碼。