Viewing 6 reply threads
  • Author
    Posts
    • #7536
      cosmocanuck
      Member

      Hi! I’m using best practices to add a custom post type to a new site I’m developing. But I’ve stumbled right at step one! Sigh… I’ve created and activated a simple plugin, to which I’ve added code based on the example here:

      piklist_post_types [Filter]

      Everything in my one PHP file is below – I can’t figure out what I’ve done wrong… hope someone can enlighten me. Thanks!

      Adam

      <?php
      /*
      Plugin Name: Recipes etc with Piklist 
      Description: Adds custom post types and other features using the Piklist plugin.
      Version: 1.0
      Author: Adam Abrams
      Author URI: http://www.adamabramsdesign.com
      Plugin Type: Piklist
      License: GPL2
      */
      
      add_filter('piklist_post_types', 'piklist_demo_post_types');
        function piklist_demo_post_types($post_types)
        {
          $post_types['recipes'] = array(
            'labels' => piklist('post_type_labels', 'Recipes')
            ,'title' => __('Enter a new Recipe')
            ,'menu_icon' => piklist('url', 'piklist') . '/parts/img/piklist-menu-icon.svg'
            ,'page_icon' => piklist('url', 'piklist') . '/parts/img/piklist-page-icon-32.png'
            ,'supports' => array(
              'title'
              ,'post-formats'
            )
            ,'public' => true
            ,'admin_body_class' => array(
              'custom-body-class'
            )
            ,'has_archive' => true
            ,'rewrite' => array(
              'slug' => 'recipe'
            )
            ,'capability_type' => 'post'
            ,'edit_columns' => array(
              'title' => __('Recipe')
              ,'author' => __('Assigned to')
            )
            ,'hide_meta_box' => array(
              ,'author'
            )
            ,'status' => array(
              'new' => array(
                'label' => 'New'
                ,'public' => false
              )
              ,'pending' => array(
                'label' => 'Pending Review'
                ,'public' => false
              )
              ,'demo' => array(
                'label' => 'Recipe'
                ,'public' => true
                ,'exclude_from_search' => true
                ,'show_in_admin_all_list' => true
                ,'show_in_admin_status_list' => true
             )
              ,'lock' => array(
                'label' => 'Lock'
                ,'public' => true
              )
            )
          );
      
          return $post_types;
        }
      
      ?>
    • #7547
      cosmocanuck
      Member

      Continuing to troubleshoot, I tried simply pasting in the untouched sample code above. But now I get the following error when trying to activate it:

      Plugin could not be activated because it triggered a fatal error.
      Parse error: syntax error, unexpected ‘,’, expecting ‘)’ in /nfs/c01/h08/mnt/7211/domains/hons.ca/html/wordpress/wp-content/plugins/piklist-hons/piklist-hons.php on line 39

      Hmmmm? Here is my current contents of the php file (with line 39 indicated by a comment):

      <?php
      /*
      Plugin Name: HON'S Piklist 
      Description: Adds custom post types and other features using the Piklist plugin.
      Version: 1.0
      Author: Adam Abrams
      Author URI: http://www.adamabramsdesign.com
      Plugin Type: Piklist
      */
      
        add_filter('piklist_post_types', 'piklist_demo_post_types');
        function piklist_demo_post_types($post_types)
        {
          $post_types['piklist_demo'] = array(
            'labels' => piklist('post_type_labels', 'Piklist Demo')
            ,'title' => __('Enter a new Demo Title')
            ,'menu_icon' => piklist('url', 'piklist') . '/parts/img/piklist-menu-icon.svg'
            ,'page_icon' => piklist('url', 'piklist') . '/parts/img/piklist-page-icon-32.png'
            ,'supports' => array(
              'title'
              ,'post-formats'
            )
            ,'public' => true
            ,'admin_body_class' => array(
              'custom-body-class'
            )
            ,'has_archive' => true
            ,'rewrite' => array(
              'slug' => 'piklist-demo'
            )
            ,'capability_type' => 'post'
            ,'edit_columns' => array(
              'title' => __('Demo')
              ,'author' => __('Assigned to')
            )
            ,'hide_meta_box' => array(
              ,'author'   /* THIS IS LINE 39  */
            )
            ,'status' => array(
              'new' => array(
                'label' => 'New'
                ,'public' => false
              )
              ,'pending' => array(
                'label' => 'Pending Review'
                ,'public' => false
              )
              ,'demo' => array(
                'label' => 'Demo'
                ,'public' => true
                ,'exclude_from_search' => true
                ,'show_in_admin_all_list' => true
                ,'show_in_admin_status_list' => true
             )
              ,'lock' => array(
                'label' => 'Lock'
                ,'public' => true
              )
            )
          );
          return $post_types;
        }
      
      
    • #7550
      Jason
      Keymaster

      You have an extra comma preceding ‘author’ on line 39. Change ,'author' to 'author'. 🙂

    • #7552
      cosmocanuck
      Member

      Aha. It works! Thanks!

      But y’know what….

      THAT COMMA IS IN THE DEMO CODE.

      argh

      Someone ought to fix that… ;^)

      Thank you!
      adam

    • #7553
      Jason
      Keymaster

      Hey Adam!

      Glad that fixed it! Sorry for the bug in the demo code, I’ll get that fixed immediately! Thanks for pointing that out!

    • #7554
      cosmocanuck
      Member

      Glad to help the site be even better and more accurate!

      All the best!

    • #7555
      Steve
      Keymaster

      Fixed! Thanks, guys.

Viewing 6 reply threads
  • The topic ‘Creating a CPT in a plugin – what am I doing wrong?’ is closed to new replies.