2015-10-31 57 views
1

我挣扎删除此功能线没有得到一个语法错误:从下面的代码PHP标签 - 语法错误

function product_meta_box_content($post) { 

<?php 
if (! class_exists('Tax_Meta_Boxes')) : 
class Tax_Meta_Boxes { 
    public function __construct() { 
     add_action('save_post', array($this, 'save_tax_meta_data')); 
    } 



    // I need to remove this function 
    function product_meta_box_content($post) { 

    ?> 

     <?php 
    } 

    public function save_tax_meta_data($post_id) { 

     if (! isset($_POST['post_type']) or $_POST['post_type'] !== 'product') { 
      return; 
     }  
    } 
} 
endif; 

我已经试过注释行了,删除该行,添加,删除php标签,但每次都会导致语法错误。

我在开启和关闭php标签并插入大括号时有点困惑。

有人能够指向我正确的方向,并指出如何正确删除功能线?

回答

1

这里是你的代码,你只需要注意函数的起始位置,php的结束位置,以及php开始和函数结束的位置。

我在注释中标记了哪些行可以被删除。

此外,如果您没有任何html内容<?<?php之间,你可以完全删除它们。

<?php 
if (! class_exists('Tax_Meta_Boxes')) : 
class Tax_Meta_Boxes { 
    public function __construct() { 
     add_action('save_post', array($this, 'save_tax_meta_data')); 
    } 

    // I need to get rid of this function 
    // delete this - function product_meta_box_content($post) { 

    ?> <!-- you can remove this line --> 
    <!-- if there is nothing here --> 
    <?php // also this one 

    // delete this - } 

    public function save_tax_meta_data($post_id) { 

     if (! isset($_POST['post_type']) or $_POST['post_type'] !== 'product') { 
      return; 
     }  
    } 
} 
endif; 
+0

是的,那工作,谢谢! –

+0

不客气! –

+0

亚历克斯,如果我需要放在下面的行:'$ deactive = get_post_meta($ post-> ID,'_wpbo_deactive',true);''公共职能save_tax_meta_data($ post_id)''现在行,我需要php标签吗?我的语法错误回来了.. –