Passed
Push — master ( 1931dd...40edde )
by Nirjhar
02:32
created

PLUGIN_CPT::taxonomy_args()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 1
dl 0
loc 16
rs 9.9
c 0
b 0
f 0
1
<?php
2
if ( ! defined( 'ABSPATH' ) ) exit;
3
4
/**
5
 * Custom post type class
6
 *
7
 * @author     Nirjhar Lo
8
 * @package    wp-plugin-framework
9
 */
10
if ( ! class_exists( 'PLUGIN_CPT' ) ) {
11
12
	class PLUGIN_CPT {
13
14
		/**
15
		 * @var Array
16
		 */
17
		private $labels;
18
19
		/**
20
		 * @var Array
21
		 */
22
		private $args;
23
24
		/**
25
		 * @var String
26
		 */
27
		private static $menu_svg = '';
28
29
30
		/**
31
		 * Integrate the shortcode
32
		 *
33
		 * @return Void
34
		 */
35
		public function __construct() {
36
37
			$this->labels = $this->labels();
38
			$this->args = $this->args( $this->labels );
39
40
			$this->taxonomy_labels = $this->taxonomy_labels();
0 ignored issues
show
Bug Best Practice introduced by
The property taxonomy_labels does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
41
			$this->taxonomy_args = $this->taxonomy_args( $this->taxonomy_labels );
0 ignored issues
show
Bug Best Practice introduced by
The property taxonomy_args does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
42
43
			//register_post_type( 'cpt_name', $this->args );
44
			//add_filter( 'post_updated_messages', array( $this, 'group_updated_messages' ) );
45
46
			//register_taxonomy( 'custom_tax', array( 'cpt_name' ), $this->taxonomy_args );
47
		}
48
49
50
		/**
51
		 * Define the labels
52
		 *
53
		 * @return Array
54
		 */
55
		public function labels() {
56
57
	      $labels = array(
58
	        'name'                => _x( '', 'Post Type General Name', 'textdomain' ),
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

58
	        'name'                => /** @scrutinizer ignore-call */ _x( '', 'Post Type General Name', 'textdomain' ),
Loading history...
59
	        'singular_name'       => _x( '', 'Post Type Singular Name', 'textdomain' ),
60
	        'menu_name'           => __( '', 'textdomain' ),
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

60
	        'menu_name'           => /** @scrutinizer ignore-call */ __( '', 'textdomain' ),
Loading history...
61
	        'parent_item_colon'   => __( '', 'textdomain' ),
62
	        'all_items'           => __( '', 'textdomain' ),
63
	        'view_item'           => __( '', 'textdomain' ),
64
	        'add_new_item'        => __( '', 'textdomain' ),
65
	        'add_new'             => __( '', 'textdomain' ),
66
	        'edit_item'           => __( '', 'textdomain' ),
67
	        'update_item'         => __( '', 'textdomain' ),
68
	        'search_items'        => __( '', 'textdomain' ),
69
	        'not_found'           => __( '', 'textdomain' ),
70
	        'not_found_in_trash'  => __( '', 'textdomain' ),
71
	      );
72
73
	      return $labels;
74
	    }
75
76
77
		/**
78
		 * Define the arguments for custom post type
79
		 *
80
		 * @param Array $labels
81
		 *
82
		 * @return Array
83
		 */
84
	    public function args( $labels ) {
85
86
	      $args = array(
87
	          'label'               => __( '', 'textdomain' ),
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

87
	          'label'               => /** @scrutinizer ignore-call */ __( '', 'textdomain' ),
Loading history...
88
	          'description'         => __( '', 'textdomain' ),
89
	          'labels'              => $labels,
90
	          'supports'            => array( 'title', 'editor', 'thumbnail' ),
91
	          'taxonomies'          => array( 'custom_tax', 'post_tag' ),
92
	          'hierarchical'        => true,
93
	          'public'              => true,
94
			  'rewrite'			  	=> array( 'slug' => 'slug_name' ),
95
	          'show_ui'             => true,
96
	          'show_in_menu'        => true,
97
			  'menu_icon' 			=> 'data:image/svg+xml;base64,' . self::$menu_svg,
98
	          'show_in_nav_menus'   => true,
99
	          'show_in_admin_bar'   => true,
100
	          'menu_position'       => 5,
101
	          'can_export'          => true,
102
	          'has_archive'         => true,
103
	          'exclude_from_search' => false,
104
	          'publicly_queryable'  => true,
105
	          'capability_type'     => 'post',
106
	          'show_in_rest'        => true,
107
			  //Controls WP REST API behaviour
108
			  'rest_controller_class' => 'WP_REST_Posts_Controller',
109
	      );
110
111
	      return $args;
112
	    }
113
114
115
		/**
116
	 	 * Modify the cpt messages
117
		 *
118
		 * @param Array $messages
119
		 *
120
		 * @return Array
121
	 	 */
122
		 public function cpt_updated_messages( $messages ) {
123
124
			 global $post, $post_ID;
125
126
			 $messages['cpt_name'] = array(
127
				 0 => '',
128
				 1 => sprintf( __( 'CPT updated. <a href="%s">View CPT</a>', 'textdomain' ), esc_url( get_permalink( $post_ID ) ) ),
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

128
				 1 => sprintf( __( 'CPT updated. <a href="%s">View CPT</a>', 'textdomain' ), esc_url( /** @scrutinizer ignore-call */ get_permalink( $post_ID ) ) ),
Loading history...
Bug introduced by
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 ignore-call  annotation

128
				 1 => sprintf( /** @scrutinizer ignore-call */ __( 'CPT updated. <a href="%s">View CPT</a>', 'textdomain' ), esc_url( get_permalink( $post_ID ) ) ),
Loading history...
Bug introduced by
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 ignore-call  annotation

128
				 1 => sprintf( __( 'CPT updated. <a href="%s">View CPT</a>', 'textdomain' ), /** @scrutinizer ignore-call */ esc_url( get_permalink( $post_ID ) ) ),
Loading history...
129
				 2 => __( 'field updated.', 'textdomain' ),
130
				 3 => __( 'field deleted.', 'textdomain' ),
131
				 4 => __( 'CPT updated.', 'textdomain' ),
132
				 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
Bug introduced by
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 ignore-call  annotation

132
				 5 => ( isset( $_GET['revision'] ) ? sprintf( __( 'CPT restored to revision from %s', 'textdomain' ), /** @scrutinizer ignore-call */ wp_post_revision_title( (int) $_GET['revision'], false ) ) : false ),
Loading history...
133
				 6 => sprintf( __( 'CPT published. <a href="%s">View Cpt</a>', 'textdomain' ), esc_url( get_permalink( $post_ID ) ) ),
134
				 7 => __( 'CPT saved.', 'textdomain' ),
135
				 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
Bug introduced by
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 ignore-call  annotation

135
				 8 => sprintf( __( 'CPT submitted. <a target="_blank" href="%s">Preview cpt</a>', 'textdomain' ), esc_url( /** @scrutinizer ignore-call */ add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ),
Loading history...
136
				 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
Bug introduced by
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 ignore-call  annotation

136
				 9 => sprintf( __( 'CPT scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview cpt</a>', 'textdomain' ), /** @scrutinizer ignore-call */ date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ) ),
Loading history...
137
				 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 ) ) ) ),
138
			 );
139
140
			 return $messages;
141
		 }
142
143
144
		 /**
145
 	 	  * Taxonomy labels
146
 		  *
147
 		  * @return Array
148
 	 	  */
149
		 public function taxonomy_labels() {
150
151
			 $labels = array(
152
			     'name'              => _x( 'Taxonomy', 'taxonomy general name', 'textdomain' ),
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

152
			     'name'              => /** @scrutinizer ignore-call */ _x( 'Taxonomy', 'taxonomy general name', 'textdomain' ),
Loading history...
153
			     'singular_name'     => _x( 'Taxonomy', 'taxonomy singular name', 'textdomain' ),
154
			     'search_items'      => __( 'Search Taxonomy', 'textdomain' ),
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

154
			     'search_items'      => /** @scrutinizer ignore-call */ __( 'Search Taxonomy', 'textdomain' ),
Loading history...
155
			     'all_items'         => __( 'All Taxonomies', 'textdomain' ),
156
			     'parent_item'       => __( 'Parent Taxonomy', 'textdomain' ),
157
			     'parent_item_colon' => __( 'Parent Taxonomy:', 'textdomain' ),
158
			     'edit_item'         => __( 'Edit Taxonomy', 'textdomain' ),
159
			     'update_item'       => __( 'Update Taxonomy', 'textdomain' ),
160
			     'add_new_item'      => __( 'Add New Taxonomy', 'textdomain' ),
161
			     'new_item_name'     => __( 'New Taxonomy Name', 'textdomain' ),
162
			     'menu_name'         => __( 'Taxonomy', 'textdomain' ),
163
			);
164
165
			return $labels;
166
		 }
167
168
169
		 /**
170
 		 * Define the arguments for custom taxonomy
171
 		 *
172
 		 * @param Array $labels
173
 		 *
174
 		 * @return Array
175
 		 */
176
 	    public function taxonomy_args( $labels ) {
177
178
 	      $args = array(
179
			  	'hierarchical'          => true,
180
    			'labels'                => $labels,
181
    			'show_ui'               => true,
182
    			'show_admin_column'     => true,
183
    			'query_var'             => true,
184
    			'rewrite'               => array( 'slug' => 'custom_tax' ),
185
    			'show_in_rest'          => true,
186
    			'rest_base'             => 'custom_tax',
187
				//Controls WP REST API behaviour
188
    			'rest_controller_class' => 'WP_REST_Terms_Controller',
189
 	      );
190
191
 	      return $args;
192
 	    }
193
	}
194
}
195