nirjharlo /
wp-plugin-framework
| 1 | <?php |
||||||||
| 2 | namespace NirjharLo\WP_Plugin_Framework\Src; |
||||||||
| 3 | |||||||||
| 4 | if ( ! defined( 'ABSPATH' ) ) exit; |
||||||||
| 5 | |||||||||
| 6 | /** |
||||||||
| 7 | * Custom post type class |
||||||||
| 8 | * |
||||||||
| 9 | * @author Nirjhar Lo |
||||||||
| 10 | * @package wp-plugin-framework |
||||||||
| 11 | */ |
||||||||
| 12 | if ( ! class_exists( 'Cpt' ) ) { |
||||||||
| 13 | |||||||||
| 14 | class Cpt { |
||||||||
| 15 | |||||||||
| 16 | /** |
||||||||
| 17 | * @var Array |
||||||||
| 18 | */ |
||||||||
| 19 | private $labels; |
||||||||
| 20 | |||||||||
| 21 | /** |
||||||||
| 22 | * @var Array |
||||||||
| 23 | */ |
||||||||
| 24 | private $args; |
||||||||
| 25 | |||||||||
| 26 | /** |
||||||||
| 27 | * @var String |
||||||||
| 28 | */ |
||||||||
| 29 | private static $menu_svg = ''; |
||||||||
| 30 | |||||||||
| 31 | |||||||||
| 32 | /** |
||||||||
| 33 | * Integrate the shortcode |
||||||||
| 34 | * |
||||||||
| 35 | * @return Void |
||||||||
| 36 | */ |
||||||||
| 37 | public function __construct() { |
||||||||
| 38 | |||||||||
| 39 | $this->labels = $this->labels(); |
||||||||
| 40 | $this->args = $this->args( $this->labels ); |
||||||||
| 41 | |||||||||
| 42 | $this->taxonomy_labels = $this->taxonomy_labels(); |
||||||||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||||||
| 43 | $this->taxonomy_args = $this->taxonomy_args( $this->taxonomy_labels ); |
||||||||
|
0 ignored issues
–
show
|
|||||||||
| 44 | |||||||||
| 45 | //register_post_type( 'cpt_name', $this->args ); |
||||||||
| 46 | //add_filter( 'post_updated_messages', array( $this, 'group_updated_messages' ) ); |
||||||||
| 47 | |||||||||
| 48 | //register_taxonomy( 'custom_tax', array( 'cpt_name' ), $this->taxonomy_args ); |
||||||||
| 49 | } |
||||||||
| 50 | |||||||||
| 51 | |||||||||
| 52 | /** |
||||||||
| 53 | * Define the labels |
||||||||
| 54 | * |
||||||||
| 55 | * @return Array |
||||||||
| 56 | */ |
||||||||
| 57 | public function labels() { |
||||||||
| 58 | |||||||||
| 59 | $labels = array( |
||||||||
| 60 | 'name' => _x( '', 'Post Type General Name', 'textdomain' ), |
||||||||
|
0 ignored issues
–
show
The function
_x was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||
| 61 | 'singular_name' => _x( '', 'Post Type Singular Name', 'textdomain' ), |
||||||||
| 62 | 'menu_name' => __( '', 'textdomain' ), |
||||||||
|
0 ignored issues
–
show
The function
__ was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||
| 63 | 'parent_item_colon' => __( '', 'textdomain' ), |
||||||||
| 64 | 'all_items' => __( '', 'textdomain' ), |
||||||||
| 65 | 'view_item' => __( '', 'textdomain' ), |
||||||||
| 66 | 'add_new_item' => __( '', 'textdomain' ), |
||||||||
| 67 | 'add_new' => __( '', 'textdomain' ), |
||||||||
| 68 | 'edit_item' => __( '', 'textdomain' ), |
||||||||
| 69 | 'update_item' => __( '', 'textdomain' ), |
||||||||
| 70 | 'search_items' => __( '', 'textdomain' ), |
||||||||
| 71 | 'not_found' => __( '', 'textdomain' ), |
||||||||
| 72 | 'not_found_in_trash' => __( '', 'textdomain' ), |
||||||||
| 73 | ); |
||||||||
| 74 | |||||||||
| 75 | return $labels; |
||||||||
| 76 | } |
||||||||
| 77 | |||||||||
| 78 | |||||||||
| 79 | /** |
||||||||
| 80 | * Define the arguments for custom post type |
||||||||
| 81 | * |
||||||||
| 82 | * @param Array $labels |
||||||||
| 83 | * |
||||||||
| 84 | * @return Array |
||||||||
| 85 | */ |
||||||||
| 86 | public function args( $labels ) { |
||||||||
| 87 | |||||||||
| 88 | $args = array( |
||||||||
| 89 | 'label' => __( '', 'textdomain' ), |
||||||||
|
0 ignored issues
–
show
The function
__ was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||
| 90 | 'description' => __( '', 'textdomain' ), |
||||||||
| 91 | 'labels' => $labels, |
||||||||
| 92 | 'supports' => array( 'title', 'editor', 'thumbnail' ), |
||||||||
| 93 | 'taxonomies' => array( 'custom_tax', 'post_tag' ), |
||||||||
| 94 | 'hierarchical' => true, |
||||||||
| 95 | 'public' => true, |
||||||||
| 96 | 'rewrite' => array( 'slug' => 'slug_name' ), |
||||||||
| 97 | 'show_ui' => true, |
||||||||
| 98 | 'show_in_menu' => true, |
||||||||
| 99 | 'menu_icon' => 'data:image/svg+xml;base64,' . self::$menu_svg, |
||||||||
| 100 | 'show_in_nav_menus' => true, |
||||||||
| 101 | 'show_in_admin_bar' => true, |
||||||||
| 102 | 'menu_position' => 5, |
||||||||
| 103 | 'can_export' => true, |
||||||||
| 104 | 'has_archive' => true, |
||||||||
| 105 | 'exclude_from_search' => false, |
||||||||
| 106 | 'publicly_queryable' => true, |
||||||||
| 107 | 'capability_type' => 'post', |
||||||||
| 108 | 'show_in_rest' => true, |
||||||||
| 109 | //Controls WP REST API behaviour |
||||||||
| 110 | 'rest_controller_class' => 'WP_REST_Posts_Controller', |
||||||||
| 111 | ); |
||||||||
| 112 | |||||||||
| 113 | return $args; |
||||||||
| 114 | } |
||||||||
| 115 | |||||||||
| 116 | |||||||||
| 117 | /** |
||||||||
| 118 | * Modify the cpt messages |
||||||||
| 119 | * |
||||||||
| 120 | * @param Array $messages |
||||||||
| 121 | * |
||||||||
| 122 | * @return Array |
||||||||
| 123 | */ |
||||||||
| 124 | public function cpt_updated_messages( $messages ) { |
||||||||
| 125 | |||||||||
| 126 | global $post, $post_ID; |
||||||||
| 127 | |||||||||
| 128 | $messages['cpt_name'] = array( |
||||||||
| 129 | 0 => '', |
||||||||
| 130 | 1 => sprintf( __( 'CPT updated. <a href="%s">View CPT</a>', 'textdomain' ), esc_url( get_permalink( $post_ID ) ) ), |
||||||||
|
0 ignored issues
–
show
The function
esc_url was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
The function
get_permalink was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
The function
__ was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||
| 131 | 2 => __( 'field updated.', 'textdomain' ), |
||||||||
| 132 | 3 => __( 'field deleted.', 'textdomain' ), |
||||||||
| 133 | 4 => __( 'CPT updated.', 'textdomain' ), |
||||||||
| 134 | 5 => ( isset( $_GET['revision'] ) ? sprintf( __( 'CPT restored to revision from %s', 'textdomain' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false ), |
||||||||
|
0 ignored issues
–
show
The function
wp_post_revision_title was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||
| 135 | 6 => sprintf( __( 'CPT published. <a href="%s">View Cpt</a>', 'textdomain' ), esc_url( get_permalink( $post_ID ) ) ), |
||||||||
| 136 | 7 => __( 'CPT saved.', 'textdomain' ), |
||||||||
| 137 | 8 => sprintf( __( 'CPT submitted. <a target="_blank" href="%s">Preview cpt</a>', 'textdomain' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ), |
||||||||
|
0 ignored issues
–
show
The function
add_query_arg was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||
| 138 | 9 => sprintf( __( 'CPT scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview cpt</a>', 'textdomain' ), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ) ), |
||||||||
|
0 ignored issues
–
show
The function
date_i18n was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||
| 139 | 10 => sprintf( __( 'CPT draft updated. <a target="_blank" href="%s">Preview cpt</a>', 'textdomain' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ), |
||||||||
| 140 | ); |
||||||||
| 141 | |||||||||
| 142 | return $messages; |
||||||||
| 143 | } |
||||||||
| 144 | |||||||||
| 145 | |||||||||
| 146 | /** |
||||||||
| 147 | * Taxonomy labels |
||||||||
| 148 | * |
||||||||
| 149 | * @return Array |
||||||||
| 150 | */ |
||||||||
| 151 | public function taxonomy_labels() { |
||||||||
| 152 | |||||||||
| 153 | $labels = array( |
||||||||
| 154 | 'name' => _x( 'Taxonomy', 'taxonomy general name', 'textdomain' ), |
||||||||
|
0 ignored issues
–
show
The function
_x was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||
| 155 | 'singular_name' => _x( 'Taxonomy', 'taxonomy singular name', 'textdomain' ), |
||||||||
| 156 | 'search_items' => __( 'Search Taxonomy', 'textdomain' ), |
||||||||
|
0 ignored issues
–
show
The function
__ was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||||
| 157 | 'all_items' => __( 'All Taxonomies', 'textdomain' ), |
||||||||
| 158 | 'parent_item' => __( 'Parent Taxonomy', 'textdomain' ), |
||||||||
| 159 | 'parent_item_colon' => __( 'Parent Taxonomy:', 'textdomain' ), |
||||||||
| 160 | 'edit_item' => __( 'Edit Taxonomy', 'textdomain' ), |
||||||||
| 161 | 'update_item' => __( 'Update Taxonomy', 'textdomain' ), |
||||||||
| 162 | 'add_new_item' => __( 'Add New Taxonomy', 'textdomain' ), |
||||||||
| 163 | 'new_item_name' => __( 'New Taxonomy Name', 'textdomain' ), |
||||||||
| 164 | 'menu_name' => __( 'Taxonomy', 'textdomain' ), |
||||||||
| 165 | ); |
||||||||
| 166 | |||||||||
| 167 | return $labels; |
||||||||
| 168 | } |
||||||||
| 169 | |||||||||
| 170 | |||||||||
| 171 | /** |
||||||||
| 172 | * Define the arguments for custom taxonomy |
||||||||
| 173 | * |
||||||||
| 174 | * @param Array $labels |
||||||||
| 175 | * |
||||||||
| 176 | * @return Array |
||||||||
| 177 | */ |
||||||||
| 178 | public function taxonomy_args( $labels ) { |
||||||||
| 179 | |||||||||
| 180 | $args = array( |
||||||||
| 181 | 'hierarchical' => true, |
||||||||
| 182 | 'labels' => $labels, |
||||||||
| 183 | 'show_ui' => true, |
||||||||
| 184 | 'show_admin_column' => true, |
||||||||
| 185 | 'query_var' => true, |
||||||||
| 186 | 'rewrite' => array( 'slug' => 'custom_tax' ), |
||||||||
| 187 | 'show_in_rest' => true, |
||||||||
| 188 | 'rest_base' => 'custom_tax', |
||||||||
| 189 | //Controls WP REST API behaviour |
||||||||
| 190 | 'rest_controller_class' => 'WP_REST_Terms_Controller', |
||||||||
| 191 | ); |
||||||||
| 192 | |||||||||
| 193 | return $args; |
||||||||
| 194 | } |
||||||||
| 195 | } |
||||||||
| 196 | } |
||||||||
| 197 |