Rareloop / lumberjack

Lumberjack is a powerful MVC framework for the modern WordPress developer. Write better, more expressive and easier to maintain code.
https://lumberjack.rareloop.com
MIT License
371 stars 34 forks source link

Post Type not registering #12

Closed lmartins closed 6 years ago

lmartins commented 6 years ago

What are the steps to reproduce this issue?

I'm basically following the steps described on the new documentation for a Bedrock environment, and got stuck in the part where we register a new post type.

I've added the Product class exactly as described in the docs, with the two required methods, and proceeded to register the class in config\posttypes.php.

I've confirmed the Products class is called during the application runtime, but still no product post type available in the admin.

I'm probably missing something, wondering if you could point me help understand what.

What versions of software are you using?

Operating System: OSX

PHP Version: 7.2.5

Lumberjack Version: Core is version 3.2

adamtomat commented 6 years ago

Would you mind sharing your PostType class and your config/posttypes.php file with us please?

We can take a look for you @lmartins

lmartins commented 6 years ago

Absolutely @adamtomat ,

Btw, code is straight from the documentation:

config/posttypes.php:

<?php
return [
/**
 * List all the sub-classes of Rareloop\Lumberjack\Post in your app that you wish to
 * automatically register with WordPress as part of the bootstrap process.
 */
  'register' => [
    App\PostTypes\Product::class,
  ],
];

app\PostTypes\Product.php:

<?php
namespace App\PostTypes;

use Rareloop\Lumberjack\Post;
use Rareloop\Lumberjack\QueryBuilder\Post as QueryBuilderPost;

class Product extends Post
{
  /**
   * Return the key used to register the post type with WordPress
   * First parameter of the `register_post_type` function:
   * https://codex.wordpress.org/Function_Reference/register_post_type
   *
   * @return string
   */
  public static function getPostType()
  {
    return 'products';
  }

  /**
   * Return the config to use to register the post type with WordPress
   * Second parameter of the `register_post_type` function:
   * https://codex.wordpress.org/Function_Reference/register_post_type
   *
   * @return array|null
   */
  protected static function getPostTypeConfig()
  {
    return [
      'labels' => [
        'name' => __('Products'),
        'singular_name' => __('Product'),
        'add_new_item' => __('Add New Product'),
      ],
    ];
  }
}

Thank you!

adamtomat commented 6 years ago

@lmartins Thanks, I am able to replicate the issue locally. Will have a look at what's causing it 👍

adamtomat commented 6 years ago

@lmartins Looks like it's just an issue with documentation again. Your post type has been registered successfully, it's just not public. That's because register_post_type apparently sets public to false by default: https://codex.wordpress.org/Function_Reference/register_post_type#public

Also, the following line should be removed (unless you're using the Query Builder):

use Rareloop\Lumberjack\QueryBuilder\Post as QueryBuilderPost;

I'll update the docs at some point today. Your final Post Type class should look like this:

<?php
namespace App\PostTypes;

use Rareloop\Lumberjack\Post;

class Product extends Post
{
  /**
   * Return the key used to register the post type with WordPress
   * First parameter of the `register_post_type` function:
   * https://codex.wordpress.org/Function_Reference/register_post_type
   *
   * @return string
   */
  public static function getPostType()
  {
    return 'products';
  }

  /**
   * Return the config to use to register the post type with WordPress
   * Second parameter of the `register_post_type` function:
   * https://codex.wordpress.org/Function_Reference/register_post_type
   *
   * @return array|null
   */
  protected static function getPostTypeConfig()
  {
    return [
      'labels' => [
        'name' => __('Products'),
        'singular_name' => __('Product'),
        'add_new_item' => __('Add New Product'),
      ],
      'public' => true,
    ];
  }
}
lmartins commented 6 years ago

Awesome, thanks so much for the feedback @adamtomat !

adamtomat commented 6 years ago

Fixed the documentation.