Skip to content

Commit

Permalink
Merge pull request #13 from ArcFramework/improve_custom_posts
Browse files Browse the repository at this point in the history
Improve custom posts
  • Loading branch information
AndrewFeeney authored Sep 5, 2017
2 parents 6763f4e + 8fffad0 commit 4ec6f55
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Arc/Console/stubs/controller.plain.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

namespace DummyNamespace;

use Arc\Http\ValidatesRequests;
use Illuminate\Http\Request;
use DummyRootNamespace\Http\Controllers\Controller;

class DummyClass extends Controller
{
use ValidatesRequests;

//
}
29 changes: 29 additions & 0 deletions src/Arc/CustomPostTypes/CustomPostTypeServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Arc\CustomPostTypes;

use Illuminate\Support\ServiceProvider;

class CustomPostTypeServiceProvider extends ServiceProvider
{
public function boot()
{
// Register all custom post types
$registrar = $this->app->make('wordpress.custom_post_types');
$registrar->registerAll();
}

public function bootWithoutWordpress()
{
// No op
}

public function register()
{
// Bind the custom post types handler
$this->app->instance(
'wordpress.custom_post_types',
$this->app->make(CustomPostTypes::class)
);
}
}
35 changes: 35 additions & 0 deletions src/Arc/CustomPostTypes/CustomPostTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,40 @@ public function register(CustomPostType $customPostType)
return $original;
});
}

if (method_exists($customPostType, 'adminColumnHeaders')) {
$this->registerAdminColumnHeaders($customPostType);
}

if (method_exists($customPostType, 'adminColumnCells')) {
$this->registerAdminColumnCells($customPostType);
}
}

public function registerAdminColumnHeaders($customPostType)
{
// Set values for admin columns
add_filter(
'manage_edit-'.$customPostType->getSlug().'_columns',
function ($columns) use ($customPostType) {
$headers = [];

foreach ($customPostType->adminColumnHeaders($columns) as $key => $value) {
$headers[$key] = __($value);
}

return $headers;
}
);
}

public function registerAdminColumnCells($customPostType)
{
add_action(
'manage_'.$customPostType->getSlug().'_posts_custom_column',
function ($column, $postId) use ($customPostType) {
echo $customPostType->adminColumnCells($column, $customPostType->find($postId));
}, 10, 2
);
}
}

0 comments on commit 4ec6f55

Please sign in to comment.