| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPAdminify\Inc\Classes; |
| 4 |
|
| 5 |
use WPAdminify\Inc\Admin\AdminSettings; |
| 6 |
use WPAdminify\Inc\Admin\AdminSettingsModel; |
| 7 |
|
| 8 |
// no direct access allowed |
| 9 |
if (!defined('ABSPATH')) exit; |
| 10 |
|
| 11 |
/** |
| 12 |
* Post Columns: Featured Image and ID |
| 13 |
* @package WP Adminify |
| 14 |
* |
| 15 |
* @author WP Adminify <support@wpadminify.com> |
| 16 |
*/ |
| 17 |
|
| 18 |
class CustomAdminColumns extends AdminSettingsModel |
| 19 |
{ |
| 20 |
public function __construct() |
| 21 |
{ |
| 22 |
$this->options = (array) AdminSettings::get_instance()->get(); |
| 23 |
add_action('admin_init', [$this, 'adminify_taxonomy_id_column']); |
| 24 |
add_action('admin_init', [$this, 'adminify_comments_id_column']); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Taxonomy ID Column |
| 29 |
* |
| 30 |
* @return void |
| 31 |
*/ |
| 32 |
public function adminify_taxonomy_id_column() |
| 33 |
{ |
| 34 |
// If not true then return |
| 35 |
if (empty($this->options['taxonomy_id_column'])) { |
| 36 |
return; |
| 37 |
} |
| 38 |
// Restrict the custom column to specific tax_types |
| 39 |
$tax_types = array( |
| 40 |
'category', |
| 41 |
'post_tag', |
| 42 |
'product_cat', |
| 43 |
'product_tag', |
| 44 |
'page_category', |
| 45 |
'page_tag', |
| 46 |
'recipe_category', |
| 47 |
'recipe_tag', |
| 48 |
'recipe_ingredient', |
| 49 |
'recipe_feature', |
| 50 |
'recipe_cuisine', |
| 51 |
'portfolio_category', |
| 52 |
'portfolio_tag', |
| 53 |
'portfolio_client', |
| 54 |
); |
| 55 |
|
| 56 |
if (empty($tax_types)) { |
| 57 |
return; |
| 58 |
} |
| 59 |
|
| 60 |
// Add custom column filter and action |
| 61 |
foreach ($tax_types as $taxonomy) { |
| 62 |
add_action("manage_edit-{$taxonomy}_columns", [$this, 'adminify_taxonomy_id_column_head']); |
| 63 |
add_filter("manage_edit-{$taxonomy}_sortable_columns", [$this, 'adminify_taxonomy_id_column_head']); |
| 64 |
add_filter("manage_{$taxonomy}_custom_column", [$this, 'adminify_taxonomy_id_column_content'], 11, 3); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Taxonomy ID Head |
| 70 |
* |
| 71 |
* @param [type] $column |
| 72 |
* |
| 73 |
* @return void |
| 74 |
*/ |
| 75 |
public function adminify_taxonomy_id_column_head($column) |
| 76 |
{ |
| 77 |
$column['tax_id'] = esc_html__('ID', 'adminify'); |
| 78 |
return $column; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Taxonomy Column Content |
| 83 |
* |
| 84 |
* @param [type] $value |
| 85 |
* @param [type] $name |
| 86 |
* @param [type] $id |
| 87 |
* |
| 88 |
* @return void |
| 89 |
*/ |
| 90 |
function adminify_taxonomy_id_column_content($value, $name, $id) |
| 91 |
{ |
| 92 |
return 'tax_id' === $name ? $id : $value; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
/** |
| 97 |
* Comment ID Columns |
| 98 |
* |
| 99 |
* @return void |
| 100 |
*/ |
| 101 |
public function adminify_comments_id_column() |
| 102 |
{ |
| 103 |
// If not true then return |
| 104 |
if (empty($this->options['comment_id_column'])) { |
| 105 |
return; |
| 106 |
} |
| 107 |
add_filter('manage_edit-comments_columns', [$this, 'adminify_add_comments_columns']); |
| 108 |
add_action('manage_comments_custom_column', [$this, 'adminify_add_comment_columns_content'], 10, 2); |
| 109 |
} |
| 110 |
|
| 111 |
public function adminify_add_comments_columns($columns) |
| 112 |
{ |
| 113 |
$comment_columns = array( |
| 114 |
'adminify_comment_id' => __('ID', 'adminify'), |
| 115 |
'adminify_parent_id' => __('Parent ID', 'adminify') |
| 116 |
); |
| 117 |
$columns = array_slice($columns, 0, 3, true) + $comment_columns + array_slice($columns, 3, NULL, true); |
| 118 |
// return the result |
| 119 |
return $columns; |
| 120 |
} |
| 121 |
|
| 122 |
public function adminify_add_comment_columns_content($column, $comment_ID) |
| 123 |
{ |
| 124 |
global $comment; |
| 125 |
switch ($column): |
| 126 |
case 'adminify_comment_id': { |
| 127 |
echo $comment_ID; // or echo $comment->comment_ID; |
| 128 |
break; |
| 129 |
} |
| 130 |
case 'adminify_parent_id': { |
| 131 |
echo $comment->comment_parent; // this will be printed inside the column |
| 132 |
break; |
| 133 |
} |
| 134 |
endswitch; |
| 135 |
} |
| 136 |
} |
| 137 |
|