Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
joemaller committed Sep 9, 2024
1 parent 2d52271 commit bb9baa1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion example/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
}
},
"require": {
"ideasonpurpose/wp-data-model": "0.7.1"
"ideasonpurpose/wp-data-model": "^0.7.6"
}
}
2 changes: 1 addition & 1 deletion example/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ services:
# Utility service for running composer, provides a local volume for storing access tokens
# https://hub.docker.com/_/composer
composer:
image: composer:2.5
image: composer:2.7
user: "${UID:-1000}:${GID:-1000}"
environment:
COMPOSER_HOME: /.composer
Expand Down
38 changes: 34 additions & 4 deletions example/lib/CPT/News.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ class News extends WP\CPT
public function props()
{
$this->type = 'news';
$this->rewrite_base = $this->type;

$this->define();
$this->styles();

// add_filter("manage_edit-{$this->type}_columns", [$this, 'addColumns']);
// add_action("manage_{$this->type}_posts_custom_column", [$this, 'renderColumns'], 10, 2);
}

public function define()
{

$labels = WP\DataModel::postTypeLabels($this->type);

$this->args = [
Expand All @@ -29,7 +30,7 @@ public function define()
'show_ui' => true,
'show_in_rest' => true,
'rest_base' => 'news',
'has_archive' => $this->rewrite_base,
'has_archive' => true,
'show_in_menu' => true,
'exclude_from_search' => false,
'capability_type' => 'post',
Expand All @@ -41,7 +42,15 @@ public function define()
],
'query_var' => true,
'menu_position' => $this->menu_index,
'supports' => ['title', 'editor', 'thumbnail', 'excerpt', 'revisions', 'author', 'custom-fields'],
'supports' => [
'title',
'editor',
'thumbnail',
'excerpt',
'revisions',
'author',
'custom-fields',
],
'menu_icon' =>
'data:image/svg+xml;base64,' .
base64_encode(
Expand All @@ -51,6 +60,27 @@ public function define()
];
}

public function addColumns($cols)
{
$newCols = [];

foreach ($cols as $key => $value) {
$newCols[$key] = $value;
if ($key === 'cb') {
// $newCols['example_column'] = 'Example Column';
}
}
return $newCols;
}

public function renderColumns($col, $id)
{
switch ($col) {
case 'example_column':
// echo column content
break;
}
}

public function styles()
{
Expand Down
4 changes: 2 additions & 2 deletions example/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Plugin URI: https://www.github.com/ideasonpurpose
* Description: Custom Post Types and Taxonomies for the Example website.
* Version: 0.1.0
* Requires at least: 6
* Requires PHP: 8
* Requires at least: 6.6
* Requires PHP: 8.2
* Author: Ideas On Purpose
* Author URI: https://www.ideasonpurpose.com
*/
Expand Down

0 comments on commit bb9baa1

Please sign in to comment.