1 | <?php |
||||||
2 | /** |
||||||
3 | * The Post Columns code for the Importer Plugin |
||||||
4 | * |
||||||
5 | * @package lsx_wetu_importer |
||||||
6 | * @author LightSpeed |
||||||
7 | * @license GPL-3.0+ |
||||||
8 | * @link |
||||||
9 | * @copyright 2019 LightSpeed |
||||||
10 | **/ |
||||||
11 | |||||||
12 | /** |
||||||
13 | * The Post Columns code for the Importer Plugin |
||||||
14 | */ |
||||||
15 | class LSX_WETU_Importer_Post_Columns { |
||||||
16 | |||||||
17 | /** |
||||||
18 | * Holds instance of the class |
||||||
19 | * |
||||||
20 | * @var object |
||||||
21 | */ |
||||||
22 | private static $instance; |
||||||
23 | |||||||
24 | /** |
||||||
25 | * Initialize the plugin by setting localization, filters, and administration functions. |
||||||
26 | * |
||||||
27 | * @since 1.0.0 |
||||||
28 | * |
||||||
29 | * @access private |
||||||
30 | */ |
||||||
31 | public function __construct() { |
||||||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||||||
32 | add_filter( 'manage_tour_posts_columns', array( $this, 'register_tour_columns' ) ); |
||||||
33 | add_action( 'manage_tour_posts_custom_column', array( $this, 'output_tour_ref_column' ), 10, 2 ); |
||||||
34 | |||||||
35 | // Sortables Columns, sorting needs to be fixed |
||||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
43% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||||||
36 | // add_filter( 'manage_edit-tour_sortable_columns', array( $this, 'register_sortable_columns' ) ); |
||||||
37 | // add_action( 'pre_get_posts', array( $this, 'columns_posts_orderby' ) ); |
||||||
0 ignored issues
–
show
|
|||||||
38 | } |
||||||
0 ignored issues
–
show
|
|||||||
39 | |||||||
40 | /** |
||||||
41 | * Return an instance of this class. |
||||||
42 | * |
||||||
43 | * @return object |
||||||
44 | */ |
||||||
45 | public static function get_instance() { |
||||||
46 | // If the single instance hasn't been set, set it now. |
||||||
47 | if ( ! isset( self::$instance ) ) { |
||||||
0 ignored issues
–
show
|
|||||||
48 | self::$instance = new self(); |
||||||
49 | } |
||||||
0 ignored issues
–
show
|
|||||||
50 | return self::$instance; |
||||||
51 | } |
||||||
0 ignored issues
–
show
|
|||||||
52 | |||||||
53 | /** |
||||||
54 | * Display the importer welcome screen |
||||||
55 | */ |
||||||
56 | public function display_page() { |
||||||
57 | |||||||
58 | } |
||||||
0 ignored issues
–
show
|
|||||||
59 | |||||||
60 | /** |
||||||
61 | * Registers the tour ref column |
||||||
62 | * |
||||||
63 | * @param array $columns |
||||||
0 ignored issues
–
show
|
|||||||
64 | * @return array |
||||||
65 | */ |
||||||
66 | public function register_tour_columns( $columns ) { |
||||||
67 | $new_columns = array( |
||||||
68 | 'cb' => $columns['cb'], |
||||||
69 | 'title' => $columns['title'], |
||||||
70 | 'wetu_ref' => __( 'Ref', 'lsx-wetu-importer' ), |
||||||
71 | ); |
||||||
72 | unset( $columns['cb'] ); |
||||||
73 | unset( $columns['title'] ); |
||||||
74 | foreach ( $columns as $column_key => $column_label ) { |
||||||
0 ignored issues
–
show
|
|||||||
75 | $new_columns[ $column_key ] = $column_label; |
||||||
76 | } |
||||||
0 ignored issues
–
show
|
|||||||
77 | $columns = $new_columns; |
||||||
78 | return $columns; |
||||||
79 | } |
||||||
0 ignored issues
–
show
|
|||||||
80 | |||||||
81 | /** |
||||||
82 | * Outputs the tour reference column |
||||||
83 | * |
||||||
84 | * @param string $column |
||||||
0 ignored issues
–
show
|
|||||||
85 | * @param string $post_id |
||||||
0 ignored issues
–
show
|
|||||||
86 | * @return void |
||||||
87 | */ |
||||||
88 | public function output_tour_ref_column( $column, $post_id ) { |
||||||
89 | if ( 'wetu_ref' === $column ) { |
||||||
0 ignored issues
–
show
|
|||||||
90 | echo esc_attr( get_post_meta( $post_id, 'lsx_wetu_ref', true ) ); |
||||||
0 ignored issues
–
show
$post_id of type string is incompatible with the type integer expected by parameter $post_id of get_post_meta() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() It seems like
get_post_meta($post_id, 'lsx_wetu_ref', true) can also be of type false ; however, parameter $text of esc_attr() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
91 | } |
||||||
92 | } |
||||||
0 ignored issues
–
show
|
|||||||
93 | |||||||
94 | /** |
||||||
95 | * Register the columns that will be sortable |
||||||
96 | * |
||||||
97 | * @param array $columns |
||||||
0 ignored issues
–
show
|
|||||||
98 | * @return array |
||||||
99 | */ |
||||||
100 | public function register_sortable_columns( $columns = array() ) { |
||||||
101 | $columns['wetu_ref'] = 'price_per_month'; |
||||||
102 | return $columns; |
||||||
103 | } |
||||||
0 ignored issues
–
show
|
|||||||
104 | |||||||
105 | /** |
||||||
106 | * Sort the columns |
||||||
107 | * |
||||||
108 | * @param object $query WP_Query() |
||||||
0 ignored issues
–
show
|
|||||||
109 | * @return void |
||||||
110 | */ |
||||||
111 | public function columns_posts_orderby( $query ) { |
||||||
112 | if ( ! is_admin() || ! $query->is_main_query() ) { |
||||||
0 ignored issues
–
show
|
|||||||
113 | return; |
||||||
114 | } |
||||||
0 ignored issues
–
show
|
|||||||
115 | if ( 'wetu_ref' === $query->get( 'orderby' ) ) { |
||||||
0 ignored issues
–
show
|
|||||||
116 | $query->set( 'orderby', 'meta_value' ); |
||||||
117 | $query->set( 'meta_key', 'lsx_wetu_reference' ); |
||||||
118 | } |
||||||
0 ignored issues
–
show
|
|||||||
119 | /* |
||||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
58% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||||||
120 | if ( $query->is_search() && 'tour' === $query->get( 'post_type' ) ) { |
||||||
0 ignored issues
–
show
|
|||||||
121 | $meta_query = array( |
||||||
122 | 'relation' => 'OR', |
||||||
123 | array( |
||||||
124 | 'key' => 'lsx_wetu_ref', |
||||||
125 | 'value' => get_search_query(), |
||||||
126 | 'compare' => 'LIKE', |
||||||
127 | ), |
||||||
128 | ); |
||||||
129 | $query->set( 'meta_query', $meta_query ); |
||||||
130 | }*/ |
||||||
0 ignored issues
–
show
|
|||||||
131 | } |
||||||
0 ignored issues
–
show
|
|||||||
132 | } |
||||||
133 |