Skip to content

Commit 787c0c1

Browse files
authored
Merge pull request #696 from ProgressPlanner/ari/reduce-code-duplication
Reduce code duplication
2 parents 785e679 + e31cbd2 commit 787c0c1

9 files changed

Lines changed: 68 additions & 86 deletions

classes/admin/widgets/class-badge-streak-content.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,4 @@ final class Badge_Streak_Content extends Badge_Streak {
2525
* @var bool
2626
*/
2727
protected $force_last_column = true;
28-
29-
/**
30-
* Enqueue styles.
31-
*
32-
* @return void
33-
*/
34-
public function enqueue_styles() {
35-
\progress_planner()->get_admin__enqueue()->enqueue_style( 'progress-planner/page-widgets/badge-streak' );
36-
}
3728
}

classes/admin/widgets/class-badge-streak-maintenance.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,4 @@ final class Badge_Streak_Maintenance extends Badge_Streak {
2525
* @var bool
2626
*/
2727
protected $force_last_column = true;
28-
29-
/**
30-
* Enqueue styles.
31-
*
32-
* @return void
33-
*/
34-
public function enqueue_styles() {
35-
\progress_planner()->get_admin__enqueue()->enqueue_style( 'progress-planner/page-widgets/badge-streak' );
36-
}
3728
}

classes/admin/widgets/class-badge-streak.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ abstract class Badge_Streak extends Widget {
1919
*/
2020
protected $id = 'badge-streak';
2121

22+
/**
23+
* Enqueue styles.
24+
*
25+
* @return void
26+
*/
27+
public function enqueue_styles() {
28+
\progress_planner()->get_admin__enqueue()->enqueue_style( 'progress-planner/page-widgets/badge-streak' );
29+
}
30+
2231
/**
2332
* Get the badge.
2433
*

classes/rest/class-base.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@
1212
*/
1313
abstract class Base {
1414

15+
/**
16+
* Constructor.
17+
*/
18+
public function __construct() {
19+
\add_action( 'rest_api_init', [ $this, 'register_rest_endpoint' ] );
20+
}
21+
22+
/**
23+
* Register REST endpoint.
24+
*
25+
* Child classes must implement this method to define their REST endpoints.
26+
*
27+
* @return void
28+
*/
29+
abstract public function register_rest_endpoint();
30+
1531
/**
1632
* Get client IP address.
1733
*

classes/rest/class-stats.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@
1818
* Rest_API_Stats class.
1919
*/
2020
class Stats extends Base {
21-
/**
22-
* Constructor.
23-
*/
24-
public function __construct() {
25-
\add_action( 'rest_api_init', [ $this, 'register_rest_endpoint' ] );
26-
}
2721

2822
/**
2923
* Register the REST-API endpoint.

classes/rest/class-tasks.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@
1414
* Rest_API_Tasks class.
1515
*/
1616
class Tasks extends Base {
17-
/**
18-
* Constructor.
19-
*/
20-
public function __construct() {
21-
\add_action( 'rest_api_init', [ $this, 'register_rest_endpoint' ] );
22-
}
2317

2418
/**
2519
* Register the REST-API endpoint.

classes/suggested-tasks/data-collector/class-base-data-collector.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,43 @@ protected function set_cached_data( string $key, $value ) {
104104
$data[ $key ] = $value;
105105
\progress_planner()->get_settings()->set( static::CACHE_KEY, $data );
106106
}
107+
108+
/**
109+
* Get filtered public taxonomies.
110+
*
111+
* Returns public taxonomies with exclusions applied via filter.
112+
*
113+
* @return array<string, string> Array of public taxonomy names.
114+
*/
115+
protected function get_filtered_public_taxonomies() {
116+
/**
117+
* Array of public taxonomy names where both keys and values are taxonomy names.
118+
*
119+
* @var array<string, string> $public_taxonomies
120+
*/
121+
$public_taxonomies = \get_taxonomies( [ 'public' => true ], 'names' );
122+
123+
/**
124+
* Array of public taxonomies to exclude from queries.
125+
*
126+
* @var array<string> $exclude_public_taxonomies
127+
*/
128+
$exclude_public_taxonomies = \apply_filters(
129+
'progress_planner_exclude_public_taxonomies',
130+
[
131+
'post_format',
132+
'product_shipping_class',
133+
'prpl_recommendations_provider',
134+
'gblocks_pattern_collections',
135+
]
136+
);
137+
138+
foreach ( $exclude_public_taxonomies as $taxonomy ) {
139+
if ( isset( $public_taxonomies[ $taxonomy ] ) ) {
140+
unset( $public_taxonomies[ $taxonomy ] );
141+
}
142+
}
143+
144+
return $public_taxonomies;
145+
}
107146
}

classes/suggested-tasks/data-collector/class-terms-without-description.php

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -76,34 +76,8 @@ public function update_terms_without_description_cache() {
7676
protected function calculate_data() {
7777
global $wpdb;
7878

79-
// Get registered and public taxonomies.
80-
/**
81-
* Array of public taxonomy names where both keys and values are taxonomy names.
82-
*
83-
* @var array<string, string> $public_taxonomies
84-
*/
85-
$public_taxonomies = \get_taxonomies( [ 'public' => true ], 'names' );
86-
87-
/**
88-
* Array of public taxonomies to exclude from the terms without description query.
89-
*
90-
* @var array<string> $exclude_public_taxonomies
91-
*/
92-
$exclude_public_taxonomies = \apply_filters(
93-
'progress_planner_exclude_public_taxonomies',
94-
[
95-
'post_format',
96-
'product_shipping_class',
97-
'prpl_recommendations_provider',
98-
'gblocks_pattern_collections',
99-
]
100-
);
101-
102-
foreach ( $exclude_public_taxonomies as $taxonomy ) {
103-
if ( isset( $public_taxonomies[ $taxonomy ] ) ) {
104-
unset( $public_taxonomies[ $taxonomy ] );
105-
}
106-
}
79+
// Get registered and public taxonomies with exclusions applied.
80+
$public_taxonomies = $this->get_filtered_public_taxonomies();
10781

10882
// Exclude the Uncategorized category.
10983
$uncategorized_category_id = ( new Uncategorized_Category() )->collect();

classes/suggested-tasks/data-collector/class-terms-without-posts.php

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -85,34 +85,8 @@ public function update_terms_without_posts_cache() {
8585
protected function calculate_data() {
8686
global $wpdb;
8787

88-
// Get registered and public taxonomies.
89-
/**
90-
* Array of public taxonomy names where both keys and values are taxonomy names.
91-
*
92-
* @var array<string, string> $public_taxonomies
93-
*/
94-
$public_taxonomies = \get_taxonomies( [ 'public' => true ], 'names' );
95-
96-
/**
97-
* Array of public taxonomies to exclude from the terms without posts query.
98-
*
99-
* @var array<string> $exclude_public_taxonomies
100-
*/
101-
$exclude_public_taxonomies = \apply_filters(
102-
'progress_planner_exclude_public_taxonomies',
103-
[
104-
'post_format',
105-
'product_shipping_class',
106-
'prpl_recommendations_provider',
107-
'gblocks_pattern_collections',
108-
]
109-
);
110-
111-
foreach ( $exclude_public_taxonomies as $taxonomy ) {
112-
if ( isset( $public_taxonomies[ $taxonomy ] ) ) {
113-
unset( $public_taxonomies[ $taxonomy ] );
114-
}
115-
}
88+
// Get registered and public taxonomies with exclusions applied.
89+
$public_taxonomies = $this->get_filtered_public_taxonomies();
11690

11791
/**
11892
* Array of term IDs to exclude from the terms without description query.

0 commit comments

Comments
 (0)