class-woothemes-updater-licenses-table.php
5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if( ! class_exists( 'WP_List_Table' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
}
class WooThemes_Updater_Licenses_Table extends WP_List_Table {
public $per_page = 100;
public $data;
/**
* Constructor.
* @since 1.0.0
*/
public function __construct( $args = array() ) {
global $status, $page;
parent::__construct( array(
'singular' => 'license', //singular name of the listed records
'plural' => 'licenses', //plural name of the listed records
'ajax' => false //does this table support ajax?
) );
$status = 'all';
$page = $this->get_pagenum();
$this->data = array();
// Make sure this file is loaded, so we have access to plugins_api(), etc.
require_once( ABSPATH . '/wp-admin/includes/plugin-install.php' );
parent::__construct( $args );
} // End __construct()
/**
* Text to display if no items are present.
* @since 1.0.0
* @return void
*/
public function no_items () {
echo wpautop( __( 'No WooThemes products found.', 'woothemes-updater' ) );
} // End no_items(0)
/**
* The content of each column.
* @param array $item The current item in the list.
* @param string $column_name The key of the current column.
* @since 1.0.0
* @return string Output for the current column.
*/
public function column_default ( $item, $column_name ) {
switch( $column_name ) {
case 'product':
case 'product_status':
case 'product_version':
case 'license_expiry':
return $item[$column_name];
break;
}
} // End column_default()
/**
* Retrieve an array of sortable columns.
* @since 1.0.0
* @return array
*/
public function get_sortable_columns () {
return array();
} // End get_sortable_columns()
/**
* Retrieve an array of columns for the list table.
* @since 1.0.0
* @return array Key => Value pairs.
*/
public function get_columns () {
$columns = array(
'product_name' => __( 'Product', 'woothemes-updater' ),
'product_version' => __( 'Version', 'woothemes-updater' ),
'product_status' => __( 'Key', 'woothemes-updater' ),
'product_expiry' => __( 'Renews On', 'woothemes-updater' )
);
return $columns;
} // End get_columns()
/**
* Content for the "product_name" column.
* @param array $item The current item.
* @since 1.0.0
* @return string The content of this column.
*/
public function column_product_name ( $item ) {
return wpautop( '<strong>' . $item['product_name'] . '</strong>' );
} // End column_product_name()
/**
* Content for the "product_version" column.
* @param array $item The current item.
* @since 1.0.0
* @return string The content of this column.
*/
public function column_product_version ( $item ) {
if ( isset( $item['latest_version'], $item['product_version'] ) && version_compare( $item['product_version'], $item['latest_version'], '<' ) ) {
$version_text = '<strong>' . $item['product_version'] . '<span class="update-available"> - ' . sprintf( __( 'version %1$s available', 'woothemes-updater' ), esc_html( $item['latest_version'] ) ) . '</span></strong>' . "\n";
} else {
$version_text = '<strong class="latest-version">' . $item['product_version'] . '</strong>' . "\n";
}
return wpautop( $version_text );
} // End column_product_version()
/**
* Content for the "status" column.
* @param array $item The current item.
* @since 1.0.0
* @return string The content of this column.
*/
public function column_product_status ( $item ) {
$response = '';
if ( 'active' == $item['product_status'] ) {
$deactivate_url = wp_nonce_url( add_query_arg( 'action', 'deactivate-product', add_query_arg( 'filepath', $item['product_file_path'], add_query_arg( 'page', 'woothemes-helper', network_admin_url( 'index.php' ) ) ) ), 'bulk-licenses' );
$response = '<a href="' . esc_url( $deactivate_url ) . '">' . __( 'Deactivate', 'woothemes-updater' ) . '</a>' . "\n";
} else {
$response .= '<input name="license_keys[' . esc_attr( $item['product_file_path'] ) . ']" id="license_keys-' . esc_attr( $item['product_file_path'] ) . '" type="text" value="" size="37" aria-required="true" placeholder="' . esc_attr__( 'Place your subscription key here', 'woothemes-updater' ) . '" />' . "\n";
}
return $response;
} // End column_status()
public function column_product_expiry ( $item ) {
if ( '-' != $item['license_expiry'] && 'Please activate' != $item['license_expiry'] ) {
$renew_link = add_query_arg( array( 'utm_source' => 'product', 'utm_medium' => 'upsell', 'utm_campaign' => 'licenserenewal' ), 'https://www.woothemes.com/my-account/my-subscriptions/' );
$date = new DateTime( $item['license_expiry'] );
$date_string = $date->format( get_option( 'date_format' ) );
return $date_string;
}
return esc_html( $item['license_expiry'] );
}
/**
* Retrieve an array of possible bulk actions.
* @since 1.0.0
* @return array
*/
public function get_bulk_actions () {
$actions = array();
return $actions;
} // End get_bulk_actions()
/**
* Prepare an array of items to be listed.
* @since 1.0.0
* @return array Prepared items.
*/
public function prepare_items () {
$columns = $this->get_columns();
$hidden = array();
$sortable = $this->get_sortable_columns();
$this->_column_headers = array( $columns, $hidden, $sortable );
$total_items = count( $this->data );
$this->set_pagination_args( array(
'total_items' => $total_items, //WE have to calculate the total number of items
'per_page' => $total_items //WE have to determine how many items to show on a page
) );
$this->items = $this->data;
} // End prepare_items()
} // End Class
?>