Wordpress插件错误

时间:2017-09-17 14:30:19

标签: php wordpress

我正在尝试激活我正在处理的Wordpress网站的插件,这就是我的错误所说的:

"解析错误:语法错误,意外情况'全局' (T_GLOBAL)位于第104行的#home/dh_xr8y2y/grindnriseweb.xyz/wp-content/plugins/special-coffee/special-coffee.php" 我已经发布了以下代码,我不太确定我需要修复什么来激活我的代码。这保存在我的插件名为special-coffee>的文件夹下。特殊coffee.php。我提前感谢您的帮助。

<?php
/*
 Plugin Name: Special Coffee CPT
 Plugin URI: http://grindnrise.xyz
 Description: This plugin creates a custom post type & template page that for special coffees.
 Author: Preeti
Version: 1.0
Author URI: https://www.grindnriseweb.xyz/
*/ 

add_action('init', 'special_coffee_register'); 

function special_coffee_register() { 
 $args = array( 
  'label' => __('Coffee Menu'), 
  'singular_label' => _('Coffee'), 
  'public' => true, 
  'taxonomies' => array('category'),
  'show_ui' => true, 
  'capability_type' => 'post', 
  'hierarchical' => true, 
  'has_archive' => true,
  'supports' => array('title', 'editor', ),
  'rewrite' => array('slug' => 'coffees', 'with_front' => false),
); 
 }

//Register type and custom taxonomy for type. 
register_post_type( 'coffees' , $args );
register_taxonomy("coffee-type", array("coffees"), array(
    "hierarchical" => true,
    "label" => "Coffee Type",
   "singular_label" => "Coffee Type",
   "rewrite" => true
  )
 );

add_action("admin_init", "special_coffee_meta");

function special_coffee_meta (){
 add_meta_box("coffee-meta", "Coffee Options", "special_coffee_options", 
"coffees", "normal", "high");
} 


function special_coffee_options(){ 
 global $post; 
 if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id;
 $custom = get_post_custom($post->ID); 
 $name = $custom["name"][0];
 $description = $custom["description"][0];
 $producer = $custom["producer"][0];
 $region = $custom["region"][0]; 
 $varietal = $custom["varietal"][0]; 
 $process = $custom["process"][0]; 
 $elevation = $custom["elevation"][0]; 
 $cupping = $custom["cupping"][0]; 
 ?> 
 <style type="text/css">
 <?php include('special-coffee.css'); ?>
 </style>

 <div class="special_coffee_extras">
  <div>
   <label>Name:</label>
   <input name="name" value="<?php echo $name; ?>" />
  </div>
  <div>
   <label>Description:</label>
   <input name="decription" value="<?php echo $description; ?>" />
  </div>
  <div>
   <label>Producer:</label>
       <input name="producer" value="<?php echo $producer; ?>" />
     </div>
     <div>
       <label>Region:</label>
       <input name="region" value="<?php echo $region; ?>" />
     </div>
     <div>
      <label>Varietal:</label>
       <textarea name="varietal"><?php echo $varietal; ?>" /></textarea>
     </div>
     <div>
      <label>Process:</label>
       <textarea name="process"><?php echo $process; ?>" /></textarea>
 </div>
  <div>
    <label>Elevation:</label>
   <textarea name="elevation"><?php echo $elevation; ?>" /></textarea>
  </div>
  <div>
  <label>Cupping Notes:</label>
   <textarea name="cupping"><?php echo $cupping; ?>" /></textarea>
  </div>
 </div>
 <?php
   } 

  add_action('save_post', 'special_coffee_save_extras'); 

    function special_coffee_save_extras(){  
    global $post;  
 if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ){
   return $post_id;
  }else{
  update_post_meta($post->ID, "name", $_POST["name"]);
  update_post_meta($post->ID, "description", $_POST["description"]); 
  update_post_meta($post->ID, "producer", $_POST["producer"]); 
  update_post_meta($post->ID, "region", $_POST["region"]);
  update_post_meta($post->ID, "varietal", $_POST["varietal"]);
  update_post_meta($post->ID, "process", $_POST["process"]);
  update_post_meta($post->ID, "elevation", $_POST["elevation"]);
  update_post_meta($post->ID, "cupping", $_POST["cupping"]);
  } 
  }  

?>

1 个答案:

答案 0 :(得分:2)

你需要修理两件事:

- 最后代码遗失}(请记住,不要为PHP填写结束标记以避免以后出现意外问题

- 对于add_meta_boxsave_post的回调,您可能需要再提供1个参数

<?php
function special_coffee_meta (){
    add_meta_box("coffee-meta", "Coffee Options", "special_coffee_options",
        "coffees", "normal", "high");
}


function special_coffee_options($post)
{
    // You can use $post->ID not $post_id
}

add_action('save_post', 'special_coffee_save_extras');

function special_coffee_save_extras($post_id)
{
    //Use $post_id here
}