Skip to content

Commit

Permalink
Merge pull request #5 from codepress/placeholders
Browse files Browse the repository at this point in the history
Better use of placeholder
  • Loading branch information
DGStefan authored Aug 25, 2020
2 parents d949e89 + 0337245 commit 99ce003
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 51 deletions.
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Welcome to the Admin Columns column template repository.
Here you will find a starter-kit for creating a new column for Admin Columns. This start-kit will work as a normal WP plugin.

For more information about creating a new field type, please read the following article:
https://www.admincolumns.com/documentation/guides/creating-new-column-type/
https://docs.admincolumns.com/article/21-how-to-create-my-own-column

This template is for Admin Columns ánd Admin Columns Pro.

Expand All @@ -13,22 +13,23 @@ This template is for Admin Columns ánd Admin Columns Pro.
* `/css`: folder for .css files
* `/js`: folder for .js files
* `/languages`: folder for .pot, .po and .mo files
* `ac-COLUMN_NAME.php`: Main plugin file that registers the column
* `ac-PLUGIN_NAME.php`: Main plugin file that registers the column
* `/classes`: folder containing the separate logic classes
* `/classes/ColumnFree.php`: Column class with all column logic for the free version
* `/classes/ColumnPro.php`: Column class with all column logic for the pro version
* `/classes/Editing.php`: Editing Model with all editing related logic
* `/classes/Filtering.php`: Filtering Model with all filtering related logic
* `/classes/Export.php`: Simple Export Model loaded through the Pro column
* `/classes/Filtering.php`: Example Filtering Model loaded through Pro column
* `/classes/SmartFiltering.php`: Example Smart Filtering Comparison (Model) loaded through Pro column
* `/classes/Sorting.php`: Simple Sorting Model loaded through Pro column
* `/classes/Column/Free/COLUMN_NAME.php`: Column class with all column logic for the free version
* `/classes/Column/Pro/COLUMN_NAME.php`: Column class with all column logic for the pro version
* `/classes/Editing/COLUMN_NAME.php`: Editing Model with all editing related logic
* `/classes/Export/COLUMN_NAME.php`: Simple Export Model loaded through the Pro column
* `/classes/Filtering/COLUMN_NAME.php`: Example Filtering Model loaded through Pro column
* `/classes/SmartFiltering/COLUMN_NAME.php`: Example Smart Filtering Comparison (Model) loaded through Pro column
* `/classes/Sorting/COLUMN_NAME.php`: Simple Sorting Model loaded through Pro column
* `readme.txt`: WordPress readme file to be used by the wordpress repository

### step 1.

This template uses `PLACEHOLDERS` such as `COLUMN_NAME` throughout the file names and code. Use the following list of placeholders to do a 'find and replace':

* `PLUGIN_NAME`: Single word, no spaced. Underscrores allowed. Used for the text-domain and plugin description.
* `CUSTOM_NAMESPACE`: Single word, no spaced. Underscrores allowed. Used for the namespace declarations in the different class files.
* `COLUMN_NAME`: Single word, no spaces. Underscores allowed. eg. donate_button
* `COLUMN_LABEL`: Multiple words, can include spaces, visible when selecting a column
* `PLUGIN_URL`: Url to the github or WordPress repository
Expand All @@ -40,16 +41,21 @@ This template uses `PLACEHOLDERS` such as `COLUMN_NAME` throughout the file name

### step 2.

Edit the `ac-COLUMN_NAME.php` file (now renamed using your column name) and change the column type if necessary.
Edit the `ac-PLUGIN_NAME.php` file (now renamed using your plugin name) and change the column type if necessary.

### step 3.

Edit the `ac-column-COLUMN_NAME.php` file (now renamed using your column name) and include your custom code in the appropriate functions.
Edit the `COLUMN_NAME.php` files (now renamed using your column name) and include your custom code in the appropriate functions.

### step 4.

Edit this `README.md` file with the appropriate information and delete all content above and including the following line.

### step 5 (optional).

The structure of this plugin is prepared so that it can contain multiple columns.
If you want to create multiple custom columns in this plugin, you can create a copy of each of the files and use a different name for your files that represents the column classes.

-----------------------

# Admin Columns COLUMN_LABEL Column
Expand All @@ -64,7 +70,7 @@ EXTENDED_DESCRIPTION

### Installation

1. Copy the `ac-column-COLUMN_NAME` folder into your `wp-content/plugins` folder
1. Copy the `ac-column-template` folder into your `wp-content/plugins` folder
2. Activate the COLUMN_LABEL plugin via the plugins admin page
3. Create a new column via Admin Columns and select the COLUMN_LABEL column
4. Please refer to the description for more info regarding the field type settings
Expand Down
18 changes: 9 additions & 9 deletions ac-COLUMN_NAME.php → ac-PLUGIN_NAME.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
Plugin Name: Admin Columns - COLUMN_LABEL
Plugin Name: Admin Columns - PLUGIN_NAME
Plugin URI: PLUGIN_URL
Description: DESCRIPTION
Version: 1.0
Expand All @@ -12,11 +12,11 @@

// 1. Set text domain
/* @link https://codex.wordpress.org/Function_Reference/load_plugin_textdomain */
load_plugin_textdomain( 'ac-COLUMN_NAME', false, plugin_dir_path( __FILE__ ) . '/languages/' );
load_plugin_textdomain( 'ac-CUSTOM_NAMESPACE', false, plugin_dir_path( __FILE__ ) . '/languages/' );

add_action( 'ac/ready', function () {
// We use our autoloader to automatically load all the necessary classes based on the namespace below
\AC\Autoloader::instance()->register_prefix( 'AC\Custom\COLUMN_NAME', __DIR__ . '/classes/' );
\AC\Autoloader::instance()->register_prefix( 'CUSTOM_NAMESPACE', __DIR__ . '/classes/' );

add_action( 'ac/column_types', function ( \AC\ListScreen $list_screen ) {

Expand All @@ -27,30 +27,30 @@
// Register column

// Register a column WITHOUT pro features
// $list_screen->register_column_type( new \AC\Custom\COLUMN_NAME\ColumnFree() );
//$list_screen->register_column_type( new \CUSTOM_NAMESPACE\Column\Free\COLUMN_NAME() );

// Register a column WITH pro features
$list_screen->register_column_type( new \AC\Custom\COLUMN_NAME\ColumnPro() );
$list_screen->register_column_type( new \CUSTOM_NAMESPACE\Column\Pro\COLUMN_NAME() );
}

// Example #2 - for media
// if ( 'attachment' === $list_screen->get_key() ) {
// Register column
// Register column
// }

// Example #3 - for all post types
// if ( \AC\MetaType::POST === $list_screen->get_meta_type() ) {
// Register column
// Register column
// }

// Example #4 - for users
// if ( \AC\MetaType::USER === $list_screen->get_meta_type() ) {
// Register column
// Register column
// }

// Example #4 - for categories on the taxonomy list table
// if ( $list_screen instanceof \ACP\ListScreen\Taxonomy && 'category' === $list_screen->get_taxonomy()) {
// Register column
// Register column
// }

} );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace AC\Custom\COLUMN_NAME;
namespace CUSTOM_NAMESPACE\Column\Free;

class ColumnFree extends \AC\Column {
class COLUMN_NAME extends \AC\Column {

public function __construct() {

Expand Down Expand Up @@ -104,8 +104,8 @@ public function is_valid() {
*/
public function scripts() {

wp_enqueue_script( 'ac-COLUMN_NAME', plugin_dir_url( __FILE__ ) . "../js/column.js" );
wp_enqueue_style( 'ac-COLUMN_NAME', plugin_dir_url( __FILE__ ) . "../css/column.css" );
wp_enqueue_script( 'ac-COLUMN_NAME', plugin_dir_url( __FILE__ ) . "../../../js/column.js" );
wp_enqueue_style( 'ac-COLUMN_NAME', plugin_dir_url( __FILE__ ) . "../../../css/column.css" );
}

}
23 changes: 10 additions & 13 deletions classes/ColumnPro.php → classes/Column/Pro/COLUMN_NAME.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
<?php

namespace AC\Custom\COLUMN_NAME;
namespace CUSTOM_NAMESPACE\Column\Pro;

use ACP\Editing\Editable;
use ACP\Export\Exportable;
use ACP\Filtering\Filterable;
use ACP\Search\Searchable;
use ACP\Sorting\Sortable;
use CUSTOM_NAMESPACE;
use ACP;

class ColumnPro extends ColumnFree
implements Editable, Sortable, Filterable, Exportable, Searchable {
class COLUMN_NAME extends CUSTOM_NAMESPACE\Column\Free\COLUMN_NAME
implements ACP\Editing\Editable, ACP\Sorting\Sortable, ACP\Filtering\Filterable, ACP\Export\Exportable, ACP\Search\Searchable {

public function editing() {
return new Editing( $this );
return new CUSTOM_NAMESPACE\Editing\COLUMN_NAME( $this );
}

public function sorting() {

// Example #1 - Sort any value
return new Sorting( $this );
return new CUSTOM_NAMESPACE\Sorting\COLUMN_NAME( $this );

// The following examples are recommended for large datasets. They are optimised queries and much faster.

Expand All @@ -37,16 +34,16 @@ public function sorting() {
}

public function export() {
return new Export( $this );
return new CUSTOM_NAMESPACE\Export\COLUMN_NAME( $this );
}

public function filtering() {
return new Filtering( $this );
return new CUSTOM_NAMESPACE\Filtering\COLUMN_NAME( $this );
}

// Smart Filtering (internally named: Search)
public function search() {
return new SmartFiltering();
return new CUSTOM_NAMESPACE\SmartFiltering\COLUMN_NAME();
}

}
4 changes: 2 additions & 2 deletions classes/Editing.php → classes/Editing/COLUMN_NAME.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace AC\Custom\COLUMN_NAME;
namespace CUSTOM_NAMESPACE\Editing;

/**
* Editing class. Adds editing functionality to the column.
*/
class Editing extends \ACP\Editing\Model {
class COLUMN_NAME extends \ACP\Editing\Model {

/**
* Editing view settings
Expand Down
4 changes: 2 additions & 2 deletions classes/Export.php → classes/Export/COLUMN_NAME.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace AC\Custom\COLUMN_NAME;
namespace CUSTOM_NAMESPACE\Export;

/**
* Export class. Adds export functionality to the column.
*/
class Export extends \ACP\Export\Model {
class COLUMN_NAME extends \ACP\Export\Model {

public function get_value( $id ) {

Expand Down
4 changes: 2 additions & 2 deletions classes/Filtering.php → classes/Filtering/COLUMN_NAME.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace AC\Custom\COLUMN_NAME;
namespace CUSTOM_NAMESPACE\Filtering;

class Filtering extends \ACP\Filtering\Model {
class COLUMN_NAME extends \ACP\Filtering\Model {

public function get_filtering_data() {
$data = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace AC\Custom\COLUMN_NAME;
namespace CUSTOM_NAMESPACE\SmartFiltering;

class SmartFiltering extends \ACP\Search\Comparison {
class COLUMN_NAME extends \ACP\Search\Comparison {

public function __construct() {
$operators = new \ACP\Search\Operators( [
Expand Down
4 changes: 2 additions & 2 deletions classes/Sorting.php → classes/Sorting/COLUMN_NAME.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace AC\Custom\COLUMN_NAME;
namespace CUSTOM_NAMESPACE\Sorting;

/**
* Sorting class. Adds sorting functionality to the column.
*/
class Sorting extends \ACP\Sorting\Model {
class COLUMN_NAME extends \ACP\Sorting\Model {

/**
* (Optional) Put all the sorting logic here. You can remove this function if you want to sort by raw value only.
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
=== Admin Columns - COLUMN_LABEL Column ===
=== Admin Columns - COLUMN_PLUGIN ===
Contributors: AUTHOR_NAME
Tags: PLUGIN_TAGS
Requires at least: 3.5
Expand All @@ -15,7 +15,7 @@ EXTENDED_DESCRIPTION

== Installation ==

1. Copy the `ac-column-COLUMN_NAME` folder into your `wp-content/plugins` folder
1. Copy the `ac-PLUGIN_NAME` folder into your `wp-content/plugins` folder
2. Activate the COLUMN_LABEL plugin via the plugins admin page
3. Create a new column via Admin Columns and select the COLUMN_LABEL column
4. Please refer to the description for more info regarding the field type settings
Expand Down

0 comments on commit 99ce003

Please sign in to comment.