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() { |
|
|
|
|
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 |
|
|
|
|
36
|
|
|
// add_filter( 'manage_edit-tour_sortable_columns', array( $this, 'register_sortable_columns' ) ); |
37
|
|
|
// add_action( 'pre_get_posts', array( $this, 'columns_posts_orderby' ) ); |
|
|
|
|
38
|
|
|
} |
|
|
|
|
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 ) ) { |
|
|
|
|
48
|
|
|
self::$instance = new self(); |
49
|
|
|
} |
|
|
|
|
50
|
|
|
return self::$instance; |
51
|
|
|
} |
|
|
|
|
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Display the importer welcome screen |
55
|
|
|
*/ |
56
|
|
|
public function display_page() { |
57
|
|
|
|
58
|
|
|
} |
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Registers the tour ref column |
62
|
|
|
* |
63
|
|
|
* @param array $columns |
|
|
|
|
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 ) { |
|
|
|
|
75
|
|
|
$new_columns[ $column_key ] = $column_label; |
76
|
|
|
} |
|
|
|
|
77
|
|
|
$columns = $new_columns; |
78
|
|
|
return $columns; |
79
|
|
|
} |
|
|
|
|
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Outputs the tour reference column |
83
|
|
|
* |
84
|
|
|
* @param string $column |
|
|
|
|
85
|
|
|
* @param string $post_id |
|
|
|
|
86
|
|
|
* @return void |
87
|
|
|
*/ |
88
|
|
|
public function output_tour_ref_column( $column, $post_id ) { |
89
|
|
|
if ( 'wetu_ref' === $column ) { |
|
|
|
|
90
|
|
|
echo esc_attr( get_post_meta( $post_id, 'lsx_wetu_ref', true ) ); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
} |
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Register the columns that will be sortable |
96
|
|
|
* |
97
|
|
|
* @param array $columns |
|
|
|
|
98
|
|
|
* @return array |
99
|
|
|
*/ |
100
|
|
|
public function register_sortable_columns( $columns = array() ) { |
101
|
|
|
$columns['wetu_ref'] = 'price_per_month'; |
102
|
|
|
return $columns; |
103
|
|
|
} |
|
|
|
|
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Sort the columns |
107
|
|
|
* |
108
|
|
|
* @param object $query WP_Query() |
|
|
|
|
109
|
|
|
* @return void |
110
|
|
|
*/ |
111
|
|
|
public function columns_posts_orderby( $query ) { |
112
|
|
|
if ( ! is_admin() || ! $query->is_main_query() ) { |
|
|
|
|
113
|
|
|
return; |
114
|
|
|
} |
|
|
|
|
115
|
|
|
if ( 'wetu_ref' === $query->get( 'orderby' ) ) { |
|
|
|
|
116
|
|
|
$query->set( 'orderby', 'meta_value' ); |
117
|
|
|
$query->set( 'meta_key', 'lsx_wetu_reference' ); |
118
|
|
|
} |
|
|
|
|
119
|
|
|
/* |
|
|
|
|
120
|
|
|
if ( $query->is_search() && 'tour' === $query->get( 'post_type' ) ) { |
|
|
|
|
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
|
|
|
}*/ |
|
|
|
|
131
|
|
|
} |
|
|
|
|
132
|
|
|
} |
133
|
|
|
|