@@ -13,6 +13,15 @@ class Archive {
1313
1414 private static $ instance ;
1515
16+ public const TYPE_ARGS = array (
17+ 'public ' => true ,
18+ );
19+
20+ public const EXCLUDED_TYPES = array (
21+ 'page ' ,
22+ 'attachment ' ,
23+ );
24+
1625
1726 public static function instance () {
1827
@@ -42,6 +51,13 @@ private function __construct() {
4251 }
4352
4453
54+ protected function disabled_types () {
55+
56+ return array_merge ( self ::EXCLUDED_TYPES , Admin::instance ()->option ( 'archive_disabled ' ) );
57+
58+ }
59+
60+
4561 public function init () {
4662
4763 $ args = array (
@@ -70,17 +86,14 @@ public function rewrites() {
7086
7187 add_rewrite_tag ( '%at-archive% ' , '([^&]+) ' );
7288
73- $ args = array ( 'public ' => true );
74- $ types = get_post_types ( $ args , 'objects ' );
75-
76- $ settings = Admin::instance ()->option ( 'archive_disabled ' );
89+ $ types = get_post_types ( self ::TYPE_ARGS , 'objects ' );
7790
7891 foreach ( $ types as $ type ) {
79- if ( in_array ( $ type ->name , $ settings , true ) ) {
92+ if ( ' post ' === $ type ->name ) {
8093 continue ;
8194 }
8295
83- if ( in_array ( $ type ->name , array ( ' post ' , ' page ' , ' attachment ' ), true ) ) {
96+ if ( in_array ( $ type ->name , $ this -> disabled_types ( ), true ) ) {
8497 continue ;
8598 }
8699
@@ -98,7 +111,7 @@ public function rewrites() {
98111 add_rewrite_rule ( '^ ' . $ slug . '/archive/page/([0-9]+)/?$ ' , 'index.php?post_type= ' . $ type ->name . '&paged=$matches[1]&at-archive=true ' , 'top ' );
99112 }
100113
101- if ( in_array ( 'post ' , $ settings , true ) ) {
114+ if ( in_array ( 'post ' , $ this -> disabled_types () , true ) ) {
102115 return ;
103116 }
104117
@@ -116,13 +129,7 @@ public function post_js() {
116129
117130 global $ post ;
118131
119- $ settings = Admin::instance ()->option ( 'archive_disabled ' );
120-
121- if ( in_array ( $ post ->post_type , $ settings , true ) ) {
122- return ;
123- }
124-
125- if ( 'attachment ' === $ post ->post_type ) {
132+ if ( in_array ( $ post ->post_type , $ this ->disabled_types (), true ) ) {
126133 return ;
127134 }
128135
@@ -167,13 +174,7 @@ public function edit_js() {
167174
168175 global $ typenow ;
169176
170- $ settings = Admin::instance ()->option ( 'archive_disabled ' );
171-
172- if ( in_array ( $ typenow , $ settings , true ) ) {
173- return ;
174- }
175-
176- if ( 'attachment ' === $ typenow ) {
177+ if ( in_array ( $ typenow , $ this ->disabled_types (), true ) ) {
177178 return ;
178179 }
179180
@@ -202,9 +203,7 @@ public function edit_js() {
202203
203204 public function post_states ( $ states , $ post ) {
204205
205- $ settings = Admin::instance ()->option ( 'archive_disabled ' );
206-
207- if ( in_array ( $ post ->post_type , $ settings , true ) ) {
206+ if ( in_array ( $ post ->post_type , $ this ->disabled_types (), true ) ) {
208207 return $ states ;
209208 }
210209
@@ -248,9 +247,7 @@ public function set_status( $query ) {
248247
249248 public function reserve_slug ( $ is_bad , $ slug , $ post_type , $ post_parent = null ) {
250249
251- $ settings = Admin::instance ()->option ( 'archive_disabled ' );
252-
253- if ( in_array ( $ post_type , $ settings , true ) ) {
250+ if ( in_array ( $ post_type , $ this ->disabled_types (), true ) ) {
254251 return $ is_bad ;
255252 }
256253
@@ -265,13 +262,7 @@ public function reserve_slug( $is_bad, $slug, $post_type, $post_parent = null )
265262
266263 public function meta_box ( $ post_type ) {
267264
268- if ( 'attachment ' === $ post_type ) {
269- return ;
270- }
271-
272- $ settings = Admin::instance ()->option ( 'archive_disabled ' );
273-
274- if ( in_array ( $ post_type , $ settings , true ) ) {
265+ if ( in_array ( $ post_type , $ this ->disabled_types (), true ) ) {
275266 return ;
276267 }
277268
@@ -383,9 +374,7 @@ private function is_valid_screen() {
383374
384375 $ screen = get_current_screen ();
385376
386- $ settings = Admin::instance ()->option ( 'archive_disabled ' );
387-
388- if ( in_array ( $ screen ->post_type , $ settings , true ) ) {
377+ if ( in_array ( $ screen ->post_type , $ this ->disabled_types (), true ) ) {
389378 return false ;
390379 }
391380
0 commit comments