0

I'm very new to WordPress Development and I'm attempting to make a custom post type business directory style plugin in my plugins folder for my site, but everytime I activate it I get the white screen of death over my entire web site. I've definitely tracked it down to this plugin but I can't see what I've done that's causing it.

<?php
/*
    Plugin Name: Special Coffee CPT
    Plugin URI: http://danijoypractice.x10host.com
    Description: This plugin creates a custom post type & template page
    Author: Danielle Rautiainen
    Version: 1.0
    Author URI: http://danijoypractice.x10host.com
*/

add_action('init', 'local_business_directory_register'); 

function local_business_directory_register() { 

$args = array( 
  'label' => __('Business Directory'), 
  'singular_label' => __('Business'), 
  'public' => true, 
  'taxonomies' => array('category'),
  'show_ui' => true, 
  'capability_type' => 'post', 
  'hierarchical' => true, 
  'has_archive' => true,
  'supports' => array('title', 'editor', ),
  'rewrite' => array('slug' => 'businesses', 'with_front' => false),
  ); 
}


  register_post_type( 'businesses' , $args );
  register_taxonomy("business-type", array("businesses"), array(
  "hierarchical" => true,
  "label" => "Business Type",
  "singular_label" => "Business Type",
  "rewrite" => true
     )
    );

add_action("admin_init", "local_business_directory_meta");

function local_business_directory_meta ()
{
 add_meta_box("business-meta", "Business Options",     "local_business_directory_options", "businesses", "normal", "high");
} 

function local_business_directory_options()
{ 
 global $post; 
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id;
$custom = get_post_custom($post->ID); 
$address = $custom["address"][0];
$website = $custom["website"][0]; 
$phone = $custom["phone"][0]; 
?> 
 <style type="text/css">
 <?php include('business-directory.css'); ?>
 </style>

 <div class="business_directory_extras">
 <?php $website= ($website == "") ? "http://" : $website; ?>
  <div>
   <label>Website:</label>
   <input name="website" value="<?php echo $website; ?>" />
  </div>
  <div>
   <label>Phone:</label>
   <input name="phone" value="<?php echo $phone; ?>" />
  </div>
  <div>
  <label>Address:</label>
   <textarea name="address"><?php echo $address; ?>" /></textarea>
  </div>
 </div> 
 <?php 
} 
add_action('save_post', 'local_business_directory_save_extras'); 
function business_manager_save_extras(){  
global $post;  
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ){

   return $post_id;
   }else{
     update_post_meta($post->ID, "website", $_POST["website"]); 
     update_post_meta($post->ID, "address", $_POST["address"]);
     update_post_meta($post->ID, "phone", $_POST["phone"]);
   } 
  }  

?>

Am I missing something? Any help would be very appreciated!

  • Turn on the PHP Debugging, so you can see PHP errors. There could be anything from missing semicolon to not closing parenthesis properly. – M-R Jan 12 '17 at 20:23
0

You are closing your function right after the $args array. You need to enclose properly

function local_business_directory_register() { 

$args = array( 
  'label' => __('Business Directory'), 
  'singular_label' => __('Business'), 
  'public' => true, 
  'taxonomies' => array('category'),
  'show_ui' => true, 
  'capability_type' => 'post', 
  'hierarchical' => true, 
  'has_archive' => true,
  'supports' => array('title', 'editor', ),
  'rewrite' => array('slug' => 'businesses', 'with_front' => false),
  ); 

  register_post_type( 'businesses' , $args );
  register_taxonomy("business-type", array("businesses"), array(
  "hierarchical" => true,
  "label" => "Business Type",
  "singular_label" => "Business Type",
  "rewrite" => true
     )
    );

}
0

There are a couple of errors in your code.

NOTE: You should debug your errors using your error logs. :|

First of all, you added register_post_type( 'businesses' , $args ); after the closing brace of your local_business_directory_register() function.

Secondly you're referencing $post_id in two different places without the variable being set. Since you define global $post, you can reference the post ID using $post->ID

<?php
/*
    Plugin Name: Special Coffee CPT
    Plugin URI: http://danijoypractice.x10host.com
    Description: This plugin creates a custom post type & template page
    Author: Danielle Rautiainen
    Version: 1.0
    Author URI: http://danijoypractice.x10host.com
*/

add_action('init', 'local_business_directory_register');

function local_business_directory_register() {

    $args = array(
        'label' => __('Business Directory'),
        'singular_label' => __('Business'),
        'public' => true,
        'taxonomies' => array('category'),
        'show_ui' => true,
        'capability_type' => 'post',
        'hierarchical' => true,
        'has_archive' => true,
        'supports' => array('title', 'editor', ),
        'rewrite' => array('slug' => 'businesses', 'with_front' => false),
    );
    register_post_type( 'businesses' , $args );
}


register_taxonomy("business-type", array("businesses"), array(
        "hierarchical" => true,
        "label" => "Business Type",
        "singular_label" => "Business Type",
        "rewrite" => true
    )
);

add_action("admin_init", "local_business_directory_meta");

function local_business_directory_meta ()
{
    add_meta_box("business-meta", "Business Options",     "local_business_directory_options", "businesses", "normal", "high");
}

function local_business_directory_options()
{
    global $post;
    if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post->ID;
    $custom = get_post_custom($post->ID);
    $address = $custom["address"][0];
    $website = $custom["website"][0];
    $phone = $custom["phone"][0];
    ?>
    <style type="text/css">
        <?php include('business-directory.css'); ?>
    </style>

    <div class="business_directory_extras">
        <?php $website= ($website == "") ? "http://" : $website; ?>
        <div>
            <label>Website:</label>
            <input name="website" value="<?php echo $website; ?>" />
        </div>
        <div>
            <label>Phone:</label>
            <input name="phone" value="<?php echo $phone; ?>" />
        </div>
        <div>
            <label>Address:</label>
            <textarea name="address"><?php echo $address; ?>" /></textarea>
        </div>
    </div>
    <?php
}
add_action('save_post', 'local_business_directory_save_extras');
function business_manager_save_extras(){
    global $post;
    if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ){

        return $post->ID;
    }else{
        update_post_meta($post->ID, "website", $_POST["website"]);
        update_post_meta($post->ID, "address", $_POST["address"]);
        update_post_meta($post->ID, "phone", $_POST["phone"]);
    }
}

?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.