-1

I am trying to activate a plugin for a Wordpress website I am working on and this is what my error says:

"Parse error: syntax error, unexpected 'global' (T_GLOBAL) in /home/dh_xr8y2y/grindnriseweb.xyz/wp-content/plugins/special-coffee/special-coffee.php on line 104" I have posted the code below and I am not quite sure what I need to fix to activate my code. This is saved under my plugins folder called special-coffee > special-coffee.php. I appreciate your help in advance.

<?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"]);
  } 
  }  

?>
John Conde
  • 217,595
  • 99
  • 455
  • 496
  • use this one https://generatewp.com/ – Ravi Patel Sep 17 '17 at 14:41
  • 1
    Considering source code snippets don't have line numbers with them on Stack Overflow, how about finding the line (104) that caused the problem? In fact, if you find that line, maybe you can figure out what's wroing in it yourself. – O. Jones Sep 17 '17 at 18:16
  • Welcome to Stack Overflow. What have you already tried yourself to debug this? Please review [How much research effort is expected?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users). Stack Overflow is not a debugging service. This is caused by a syntax error, so you need to debug your code to find it - as O. Jones says, the error message even gives you a line number to start with. – FluffyKitten Sep 18 '17 at 00:54

1 Answers1

2

You need to repair 2 things:

-Your code miss } at the end (and remember, don't put closing tag for PHP to avoid unwanted troubles later

-For callback of add_meta_box and save_post, you may need to give 1 more param like following

<?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
}
Quique
  • 47
  • 1
  • 5
  • Hey! So I used your feedback and removed the ?> tag at the very end and added }. Also, I added ($post_id) to save_extras function and $post to options function but it still didn't fix it :( – user2502459 Sep 17 '17 at 15:07