WordPress插入错误



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

"解析错误:语法错误,意外的'global'(t_global)/home/dh_xr8y2y/grindnriseweb.xyz/wp-content/wp-content/plugins/plugins/special-coffee/special-coffee/special-coffee/special-coffee.php/strong>我已经发布了下面的代码,我不太确定需要修复什么以激活代码。这是在我的插件文件夹中保存的,称为Special-Coffee> Special-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"]);
  } 
  }  
?>

您需要修复2件事:

- 您的代码在结尾处错过}(请记住,不要为PHP放置标签以避免有不必要的麻烦

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

<?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
}

最新更新