Skip to content

Commit 84b12ad

Browse files
committed
Make sure that all providers list tables call parent::get_columns to avoid conflicts with filters. Make sure that columns have cb and ID. Closes #49
1 parent 5d1ae67 commit 84b12ad

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

ad-code-manager.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class Ad_Code_Manager
5757
* @since 0.1
5858
*/
5959
function __construct() {
60-
6160
add_action( 'init', array( $this, 'action_load_providers' ) );
6261
add_action( 'init', array( $this, 'action_init' ) );
6362

@@ -133,7 +132,6 @@ function action_load_providers() {
133132
// Nothing to do without a provider
134133
if ( !is_object( $this->current_provider ) )
135134
return ;
136-
137135
/**
138136
* Configuration filter: acm_whitelisted_script_urls
139137
* A security filter to whitelist which ad code script URLs can be added in the admin

common/lib/acm-wp-list-table.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,29 @@ function __construct( $params = array() ) {
2323
* Define the columns that are going to be used in the table
2424
* @return array $columns, the array of columns to use with the table
2525
*/
26-
function get_columns() {
27-
$columns = array(
26+
function get_columns( $columns = false ) {
27+
28+
$default = array(
2829
'cb' => '<input type="checkbox" />',
2930
'id' => __( 'ID', 'ad-code-manager' ),
3031
'name' => __( 'Name', 'ad-code-manager' ),
3132
'priority' => __( 'Priority', 'ad-code-manager' ),
3233
'operator' => __( 'Logical Operator', 'ad-code-manager' ),
3334
'conditionals' => __( 'Conditionals', 'ad-code-manager' ),
3435
);
35-
return apply_filters( 'acm_list_table_columns', $columns );
36+
$columns = apply_filters( 'acm_list_table_columns', !is_array( $columns ) || empty( $columns ) ? $default : $columns );
37+
// Fail-safe for misconfiguration
38+
$required_before = array(
39+
'cb' => '<input type="checkbox" />',
40+
'id' => __( 'ID', 'ad-code-manager' ),
41+
);
42+
$required_after = array(
43+
'priority' => __( 'Priority', 'ad-code-manager' ),
44+
'operator' => __( 'Logical Operator', 'ad-code-manager' ),
45+
'conditionals' => __( 'Conditionals', 'ad-code-manager' ),
46+
);
47+
$columns = array_merge( $required_before, $columns, $required_after );
48+
return $columns;
3649
}
3750

3851
/**

providers/doubleclick-for-publishers.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,6 @@ function __construct() {
8080

8181
parent::__construct();
8282
}
83-
84-
85-
/**
86-
* Filter the columns that can appear in the list table of ad codes
87-
*/
88-
function filter_list_table_columns( $columns ) {
89-
90-
return $columns;
91-
}
9283
}
9384

9485
class Doubleclick_For_Publishers_ACM_WP_List_Table extends ACM_WP_List_Table {
@@ -114,7 +105,7 @@ function get_columns() {
114105
'operator' => __( 'Logical Operator', 'ad-code-manager' ),
115106
'conditionals' => __( 'Conditionals', 'ad-code-manager' ),
116107
);
117-
return apply_filters( 'acm_list_table_columns', $columns );
108+
return parent::get_columns( $columns );
118109
}
119110

120111
/**

providers/google-adsense.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function __construct() {
4848
);
4949

5050
parent::__construct();
51-
}
51+
}
5252
}
5353

5454
/**
@@ -82,8 +82,7 @@ public function get_columns() {
8282
'priority' => __( 'Priority', 'ad-code-manager' ),
8383
'conditionals' => __( 'Conditionals', 'ad-code-manager' ),
8484
);
85-
86-
return apply_filters( 'acm_list_table_columns', $columns );
85+
return parent::get_columns( $columns );
8786
}
8887

8988
/**

0 commit comments

Comments
 (0)