Skip to content

Commit bd3fbf1

Browse files
committed
Add 3.4.3 Version
1 parent 733fad6 commit bd3fbf1

393 files changed

Lines changed: 72553 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
<?php
2+
3+
if (!class_exists('WP_List_Table')){
4+
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
5+
}
6+
7+
class SwpmPaymentButtonsListTable extends WP_List_Table {
8+
9+
private $per_page;
10+
11+
function __construct() {
12+
global $status, $page;
13+
14+
//Set parent defaults
15+
parent::__construct(array(
16+
'singular' => 'payment button', //singular name of the listed records
17+
'plural' => 'payment buttons', //plural name of the listed records
18+
'ajax' => false //does this table support ajax?
19+
));
20+
21+
$this->per_page = 50;
22+
}
23+
24+
function column_default($item, $column_name) {
25+
//We need to read the values from our CPT and feed the column value for the given column name manually.
26+
27+
switch ($column_name) {
28+
case 'title':
29+
return get_the_title($item['ID']);
30+
break;
31+
case 'membership_level':
32+
return get_post_meta($item['ID'], 'membership_level_id', true);
33+
break;
34+
case 'button_type':
35+
$button_type = get_post_meta($item['ID'], 'button_type', true);
36+
return $button_type;
37+
break;
38+
case 'button_shortcode':
39+
$level_id = get_post_meta($item['ID'], 'membership_level_id', true);
40+
if(!SwpmUtils::membership_level_id_exists($level_id)){
41+
//This membership level doesn't exist. Show an error instead of the shortcode.
42+
$shortcode = 'Error! The membership level you specified in this button does not exist. You may have deleted this level. Edit this button and use a valid membership level.';
43+
} else {
44+
$shortcode = '[swpm_payment_button id='.$item['ID'].']';
45+
}
46+
return $shortcode;
47+
break;
48+
}
49+
}
50+
51+
function column_ID($item) {
52+
53+
$button_type = get_post_meta($item['ID'], 'button_type', true);
54+
//Build row actions
55+
$actions = array(
56+
'edit' => sprintf('<a href="admin.php?page=simple_wp_membership_payments&tab=edit_button&button_id=%s&button_type=%s">Edit</a>', $item['ID'], $button_type),
57+
'delete' => sprintf('<a href="admin.php?page=simple_wp_membership_payments&tab=payment_buttons&action=delete_payment_btn&button_id=%s" onclick="return confirm(\'Are you sure you want to delete this record?\')">Delete</a>', $item['ID']),
58+
);
59+
60+
//Return the refid column contents
61+
return $item['ID'] . $this->row_actions($actions);
62+
}
63+
64+
function column_cb($item) {
65+
return sprintf(
66+
'<input type="checkbox" name="%1$s[]" value="%2$s" />',
67+
/* $1%s */ $this->_args['singular'], //Let's reuse singular label (affiliate)
68+
/* $2%s */ $item['ID'] //The value of the checkbox should be the record's key/id
69+
);
70+
}
71+
72+
function get_columns() {
73+
$columns = array(
74+
'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
75+
'ID' => SwpmUtils::_('Payment Button ID'),
76+
'title' => SwpmUtils::_('Payment Button Title'),
77+
'membership_level' => SwpmUtils::_('Membership Level ID'),
78+
'button_type' => SwpmUtils::_('Button Type'),
79+
'button_shortcode' => SwpmUtils::_('Button Shortcode'),
80+
);
81+
return $columns;
82+
}
83+
84+
function get_sortable_columns() {
85+
$sortable_columns = array();
86+
// $sortable_columns = array(
87+
// 'ID' => array('ID', false), //true means its already sorted
88+
// );
89+
return $sortable_columns;
90+
}
91+
92+
function get_bulk_actions() {
93+
$actions = array(
94+
'delete' => SwpmUtils::_('Delete')
95+
);
96+
return $actions;
97+
}
98+
99+
function process_bulk_action() {
100+
//Detect when a bulk action is being triggered...
101+
if ('delete' === $this->current_action()) {
102+
$records_to_delete = array_map( 'sanitize_text_field', $_REQUEST['paymentbutton'] );
103+
if (empty($records_to_delete)) {
104+
echo '<div id="message" class="updated fade"><p>Error! You need to select multiple records to perform a bulk action!</p></div>';
105+
return;
106+
}
107+
108+
foreach ($records_to_delete as $record_id) {
109+
if(!is_numeric($record_id)){
110+
wp_die('Error! ID must be a numeric number.');
111+
}
112+
wp_delete_post( $record_id );
113+
}
114+
echo '<div id="message" class="updated fade"><p>Selected records deleted successfully!</p></div>';
115+
}
116+
}
117+
118+
function process_delete_action() {
119+
120+
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete_payment_btn') { //Delete link was clicked for a row in list table
121+
$record_id = sanitize_text_field($_REQUEST['button_id']);
122+
if(!is_numeric($record_id)){
123+
wp_die('Error! ID must be a numeric number.');
124+
}
125+
wp_delete_post( $record_id );
126+
$success_msg = '<div id="message" class="updated"><p>';
127+
$success_msg .= SwpmUtils::_('The selected entry was deleted!');
128+
$success_msg .= '</p></div>';
129+
echo $success_msg;
130+
}
131+
}
132+
133+
/**
134+
* Retrieve the current page number
135+
*/
136+
function get_paged() {
137+
return isset($_GET['paged']) ? absint($_GET['paged']) : 1;
138+
}
139+
140+
/**
141+
* Retrieve the total number of CPT items
142+
*/
143+
function get_total_items() {
144+
$counts = wp_count_posts('swpm_payment_button');
145+
$total = 0;
146+
foreach ($counts as $count)
147+
$total += $count;
148+
149+
return $total;
150+
}
151+
152+
function payment_buttons_data() {
153+
$data = array();
154+
$cpt_args = array(
155+
'post_type' => 'swpm_payment_button',
156+
'post_status' => 'publish',
157+
'posts_per_page' => $this->per_page,
158+
'paged' => $this->get_paged()
159+
);
160+
161+
//TODO - Do search and sort stuff (see example code)
162+
163+
//Retrieve all the CPT items
164+
$items = get_posts($cpt_args);
165+
if ($items) {
166+
foreach ($items as $item) {
167+
168+
$membership_level = get_post_meta($item->ID, 'membership_level_id', true);
169+
$data[] = array(
170+
'ID' => $item->ID,
171+
'title' => get_the_title($item->ID),
172+
'membership_level' => $membership_level,
173+
);
174+
}
175+
}
176+
177+
return $data;
178+
}
179+
180+
function prepare_items() {
181+
182+
// Lets decide how many records per page to show
183+
$per_page = $this->per_page;
184+
185+
$columns = $this->get_columns();
186+
$hidden = array();
187+
$sortable = $this->get_sortable_columns();
188+
189+
$this->_column_headers = array($columns, $hidden, $sortable);
190+
191+
$this->process_delete_action();
192+
$this->process_bulk_action();
193+
194+
// Pagination requirement
195+
$current_page = $this->get_pagenum();
196+
$total_items = $this->get_total_items();
197+
198+
// Now we add our *sorted* data to the items property, where it can be used by the rest of the class.
199+
$data = $this->payment_buttons_data();
200+
$this->items = $data;
201+
202+
//pagination requirement
203+
$this->set_pagination_args(array(
204+
'total_items' => $total_items, //WE have to calculate the total number of items
205+
'per_page' => $per_page, //WE have to determine how many items to show on a page
206+
'total_pages' => ceil($total_items / $per_page) //WE have to calculate the total number of pages
207+
));
208+
}
209+
210+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
class SwpmPaymentsAdminMenu {
4+
5+
function __construct() {
6+
7+
}
8+
9+
function handle_main_payments_admin_menu() {
10+
11+
do_action('swpm_payments_menu_start');
12+
13+
$output = '';
14+
$tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : '';
15+
$selected = $tab;
16+
?>
17+
18+
19+
<div class="wrap swpm-admin-menu-wrap"><!-- start wrap -->
20+
21+
<h1><?php echo SwpmUtils::_('Simple Membership::Payments') ?></h1><!-- page title -->
22+
23+
<!-- start nav menu tabs -->
24+
<h2 class="nav-tab-wrapper">
25+
<a class="nav-tab <?php echo ($tab == '') ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_payments"><?php SwpmUtils::e('Transactions'); ?></a>
26+
<a class="nav-tab <?php echo ($tab == 'payment_buttons') ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_payments&tab=payment_buttons"><?php SwpmUtils::e('Manage Payment Buttons'); ?></a>
27+
<a class="nav-tab <?php echo ($tab == 'create_new_button') ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_payments&tab=create_new_button"><?php SwpmUtils::e('Create New Button'); ?></a>
28+
<?php
29+
if ($tab == 'edit_button') {//Only show the "edit button" tab when a button is being edited.
30+
echo '<a class="nav-tab nav-tab-active" href="#">Edit Button</a>';
31+
}
32+
33+
//Trigger hooks that allows an extension to add extra nav tabs in the payments menu.
34+
do_action ('swpm_payments_menu_nav_tabs', $selected);
35+
36+
$menu_tabs = apply_filters('swpm_payments_menu_additional_menu_tabs_array', array());
37+
foreach ($menu_tabs as $menu_action => $title){
38+
?>
39+
<a class="nav-tab <?php echo ($selected == $menu_action) ? 'nav-tab-active' : ''; ?>" href="admin.php?page=simple_wp_membership_payments&tab=<?php echo $menu_action; ?>" ><?php SwpmUtils::e($title); ?></a>
40+
<?php
41+
}
42+
43+
?>
44+
</h2>
45+
<!-- end nav menu tabs -->
46+
47+
<?php
48+
49+
do_action('swpm_payments_menu_after_nav_tabs');
50+
51+
//Allows an addon to completely override the body section of the payments admin menu for a given action.
52+
$output = apply_filters('swpm_payments_menu_body_override', '', $tab);
53+
if (!empty($output)) {
54+
//An addon has overriden the body of this page for the given tab/action. So no need to do anything in core.
55+
echo $output;
56+
echo '</div>';//<!-- end of wrap -->
57+
return;
58+
}
59+
60+
echo '<div id="poststuff"><div id="post-body">';
61+
62+
//TODO - move most of the following includes to functions of this class instead.
63+
64+
//Switch case for the various different tabs handled by the core plugin.
65+
switch ($tab) {
66+
case 'payment_buttons':
67+
include_once(SIMPLE_WP_MEMBERSHIP_PATH . '/views/payments/admin_payment_buttons.php');
68+
break;
69+
case 'create_new_button':
70+
include_once(SIMPLE_WP_MEMBERSHIP_PATH . '/views/payments/admin_create_payment_buttons.php');
71+
break;
72+
case 'edit_button':
73+
include_once(SIMPLE_WP_MEMBERSHIP_PATH . '/views/payments/admin_edit_payment_buttons.php');
74+
break;
75+
case 'all_txns':
76+
include_once(SIMPLE_WP_MEMBERSHIP_PATH . '/views/payments/admin_all_payment_transactions.php');
77+
break;
78+
default:
79+
include_once(SIMPLE_WP_MEMBERSHIP_PATH . '/views/payments/admin_all_payment_transactions.php');
80+
break;
81+
}
82+
83+
echo '</div></div>'; //<!-- end of post-body -->
84+
85+
echo '</div>'; //<!-- end of .wrap -->
86+
}
87+
88+
}
89+
90+

0 commit comments

Comments
 (0)