From bb9baa1a98932f09bd3bf40214254a15316dd6ed Mon Sep 17 00:00:00 2001 From: Joe Maller Date: Mon, 9 Sep 2024 17:17:19 -0400 Subject: [PATCH] update example --- example/composer.json | 2 +- example/docker-compose.yml | 2 +- example/lib/CPT/News.php | 38 ++++++++++++++++++++++++++++++++++---- example/main.php | 4 ++-- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/example/composer.json b/example/composer.json index f50549e..0e3d70f 100644 --- a/example/composer.json +++ b/example/composer.json @@ -10,6 +10,6 @@ } }, "require": { - "ideasonpurpose/wp-data-model": "0.7.1" + "ideasonpurpose/wp-data-model": "^0.7.6" } } diff --git a/example/docker-compose.yml b/example/docker-compose.yml index a26ef9e..99accd2 100644 --- a/example/docker-compose.yml +++ b/example/docker-compose.yml @@ -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 diff --git a/example/lib/CPT/News.php b/example/lib/CPT/News.php index ebf1f54..23eb0f9 100644 --- a/example/lib/CPT/News.php +++ b/example/lib/CPT/News.php @@ -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 = [ @@ -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', @@ -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( @@ -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() { diff --git a/example/main.php b/example/main.php index 97d20db..f7fe41e 100644 --- a/example/main.php +++ b/example/main.php @@ -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 */