Skip to content

Commit c7c181d

Browse files
committed
simplified single source
1 parent fd9e064 commit c7c181d

6 files changed

Lines changed: 93 additions & 88 deletions

File tree

includes/Admin.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ public function archive_box(): OptionBox {
116116
$title = __( 'Disable archiving on', 'augment-types' );
117117
$args = array( 'data_prefix' => 'archive_' );
118118
$types = array_filter(
119-
get_post_types( array( 'public' => true ), 'objects' ),
119+
get_post_types( Archive::TYPE_ARGS, 'objects' ),
120120
function ( $type ) {
121-
return ! in_array( $type->name, array( 'page', 'attachment' ), true );
121+
return ! in_array( $type->name, Archive::EXCLUDED_TYPES, true );
122122
}
123123
);
124124

@@ -133,9 +133,9 @@ public function excerpt_box(): OptionBox {
133133
$title = __( 'Disable exciting excerpts on', 'augment-types' );
134134
$args = array( 'data_prefix' => 'excerpt_' );
135135
$types = array_filter(
136-
get_post_types( array( 'show_ui' => true ), 'objects' ),
136+
get_post_types( Excerpt::TYPE_ARGS, 'objects' ),
137137
function ( $type ) {
138-
if ( in_array( $type->name, array( 'wp_block' ), true ) ) {
138+
if ( in_array( $type->name, Excerpt::EXCLUDED_TYPES, true ) ) {
139139
return false;
140140
}
141141

@@ -156,7 +156,7 @@ public function expire_box(): OptionBox {
156156
$types = array_filter(
157157
get_post_types( array(), 'objects' ),
158158
function ( $type ) {
159-
if ( in_array( $type->name, array( 'attachment', 'page', 'post' ), true ) ) {
159+
if ( in_array( $type->name, array( 'page', 'post' ), true ) ) {
160160
return true;
161161
}
162162

@@ -175,7 +175,7 @@ public function thumbnail_box(): OptionBox {
175175
$title = __( 'Disable thumbnail column on', 'augment-types' );
176176
$args = array( 'data_prefix' => 'thumbnail_' );
177177
$types = array_filter(
178-
get_post_types( array( 'show_ui' => true ), 'objects' ),
178+
get_post_types( Feature::TYPE_ARGS, 'objects' ),
179179
function ( $type ) {
180180
return post_type_supports( $type->name, 'thumbnail' );
181181
}
@@ -192,12 +192,8 @@ public function sort_box(): OptionBox {
192192
$title = __( 'Disable sorting on', 'augment-types' );
193193
$args = array( 'data_prefix' => 'sort_' );
194194
$types = array_filter(
195-
get_post_types( array( 'show_ui' => true ), 'objects' ),
195+
get_post_types( Sort::TYPE_ARGS, 'objects' ),
196196
function ( $type ) {
197-
if ( in_array( $type->name, array( 'wp_block', 'wp_navigation' ), true ) ) {
198-
return false;
199-
}
200-
201197
return ! in_array( $type->name, Sort::EXCLUDED_TYPES, true );
202198
}
203199
);

includes/Archive.php

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -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

includes/Excerpt.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ class Excerpt {
1111

1212
private static $instance;
1313

14+
public const TYPE_ARGS = array(
15+
'show_ui' => true,
16+
);
17+
18+
public const EXCLUDED_TYPES = array(
19+
'wp_block',
20+
);
21+
1422

1523
public static function instance() {
1624

@@ -31,10 +39,16 @@ private function __construct() {
3139
}
3240

3341

42+
protected function disabled_types() {
43+
44+
return array_merge( self::EXCLUDED_TYPES, Admin::instance()->option( 'excerpt_disabled' ) );
45+
46+
}
47+
48+
3449
public function init() {
3550

36-
$args = array( 'show_ui' => true );
37-
$types = get_post_types( $args );
51+
$types = get_post_types( self::TYPE_ARGS );
3852

3953
foreach ( $types as $type ) {
4054
if ( ! post_type_supports( $type, 'excerpt' ) ) {
@@ -54,9 +68,7 @@ public function meta_box( $post_type ) {
5468
return;
5569
}
5670

57-
$settings = Admin::instance()->option( 'excerpt_disabled' );
58-
59-
if ( in_array( $post_type, $settings, true ) ) {
71+
if ( in_array( $post_type, $this->disabled_types(), true ) ) {
6072
return;
6173
}
6274

includes/Expire.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ class Expire {
1313

1414
private static $instance;
1515

16+
public const EXCLUDED_TYPES = array(
17+
'attachment',
18+
);
19+
1620

1721
public static function instance() {
1822

@@ -39,15 +43,16 @@ private function __construct() {
3943
}
4044

4145

42-
public function meta_box( $post_type ) {
46+
protected function disabled_types() {
47+
48+
return array_merge( self::EXCLUDED_TYPES, Admin::instance()->option( 'expire_disabled' ) );
49+
50+
}
4351

44-
if ( 'attachment' === $post_type ) {
45-
return;
46-
}
4752

48-
$settings = Admin::instance()->option( 'expire_disabled' );
53+
public function meta_box( $post_type ) {
4954

50-
if ( in_array( $post_type, $settings, true ) ) {
55+
if ( in_array( $post_type, $this->disabled_types(), true ) ) {
5156
return;
5257
}
5358

@@ -152,9 +157,7 @@ public function maybe_expire( $post ) {
152157

153158
public function column_header( $columns, $post_type = 'page' ) {
154159

155-
$settings = Admin::instance()->option( 'expire_disabled' );
156-
157-
if ( in_array( $post_type, $settings, true ) ) {
160+
if ( in_array( $post_type, $this->disabled_types(), true ) ) {
158161
return $columns;
159162
}
160163

@@ -200,9 +203,7 @@ private function is_valid_screen() {
200203

201204
$screen = get_current_screen();
202205

203-
$settings = Admin::instance()->option( 'expire_disabled' );
204-
205-
if ( in_array( $screen->post_type, $settings, true ) ) {
206+
if ( in_array( $screen->post_type, $this->disabled_types(), true ) ) {
206207
return false;
207208
}
208209

includes/Feature.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ class Feature {
1313

1414
private static $instance;
1515

16+
public const TYPE_ARGS = array(
17+
'show_ui' => true,
18+
);
19+
1620

1721
public static function instance() {
1822

@@ -34,18 +38,23 @@ private function __construct() {
3438
}
3539

3640

37-
public function init() {
41+
protected function disabled_types() {
42+
43+
return Admin::instance()->option( 'thumbnail_disabled' );
44+
45+
}
46+
3847

39-
$types = get_post_types();
48+
public function init() {
4049

41-
$settings = Admin::instance()->option( 'thumbnail_disabled' );
50+
$types = get_post_types( self::TYPE_ARGS );
4251

4352
foreach ( $types as $type ) {
4453
if ( ! post_type_supports( $type, 'thumbnail' ) ) {
4554
continue;
4655
}
4756

48-
if ( in_array( $type, $settings, true ) ) {
57+
if ( in_array( $type, $this->disabled_types(), true ) ) {
4958
continue;
5059
}
5160

@@ -137,9 +146,7 @@ private function is_valid_screen() {
137146
return false;
138147
}
139148

140-
$settings = Admin::instance()->option( 'thumbnail_disabled' );
141-
142-
if ( in_array( $screen->post_type, $settings, true ) ) {
149+
if ( in_array( $screen->post_type, $this->disabled_types(), true ) ) {
143150
return false;
144151
}
145152

0 commit comments

Comments
 (0)