@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | if ( ! class_exists( 'WP_List_Table' ) ) { |
| 11 | - include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 11 | + include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | /** |
@@ -16,468 +16,468 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | class WPInv_Subscriptions_List_Table extends WP_List_Table { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * URL of this page |
|
| 21 | - * |
|
| 22 | - * @var string |
|
| 23 | - * @since 1.0.19 |
|
| 24 | - */ |
|
| 25 | - public $base_url; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Query |
|
| 29 | - * |
|
| 30 | - * @var GetPaid_Subscriptions_Query |
|
| 31 | - * @since 1.0.19 |
|
| 32 | - */ |
|
| 33 | - public $query; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Total subscriptions |
|
| 37 | - * |
|
| 38 | - * @var string |
|
| 39 | - * @since 1.0.0 |
|
| 40 | - */ |
|
| 41 | - public $total_count; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Current status subscriptions |
|
| 45 | - * |
|
| 46 | - * @var string |
|
| 47 | - * @since 1.0.0 |
|
| 48 | - */ |
|
| 49 | - public $current_total_count; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Status counts |
|
| 53 | - * |
|
| 54 | - * @var array |
|
| 55 | - * @since 1.0.19 |
|
| 56 | - */ |
|
| 57 | - public $status_counts; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Number of results to show per page |
|
| 61 | - * |
|
| 62 | - * @var int |
|
| 63 | - * @since 1.0.0 |
|
| 64 | - */ |
|
| 65 | - public $per_page = 10; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Constructor function. |
|
| 69 | - */ |
|
| 70 | - public function __construct() { |
|
| 71 | - |
|
| 72 | - parent::__construct( |
|
| 73 | - array( |
|
| 74 | - 'singular' => 'subscription', |
|
| 75 | - 'plural' => 'subscriptions', |
|
| 76 | - ) |
|
| 77 | - ); |
|
| 78 | - |
|
| 79 | - $this->process_bulk_action(); |
|
| 80 | - |
|
| 81 | - $this->prepare_query(); |
|
| 82 | - |
|
| 83 | - $this->base_url = remove_query_arg( 'status' ); |
|
| 84 | - |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Prepares the display query |
|
| 89 | - */ |
|
| 90 | - public function prepare_query() { |
|
| 91 | - |
|
| 92 | - // Prepare query args. |
|
| 93 | - $query = array( |
|
| 94 | - 'number' => $this->per_page, |
|
| 95 | - 'paged' => $this->get_paged(), |
|
| 96 | - 'status' => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? sanitize_text_field( $_GET['status'] ) : 'all', |
|
| 97 | - 'orderby' => ( isset( $_GET['orderby'] ) ) ? sanitize_text_field( $_GET['orderby'] ) : 'id', |
|
| 98 | - 'order' => ( isset( $_GET['order'] ) ) ? sanitize_text_field( $_GET['order'] ) : 'DESC', |
|
| 99 | - 'customer_in' => $this->get_user_in(), |
|
| 100 | - ); |
|
| 101 | - |
|
| 102 | - if ( is_array( $query['customer_in'] ) && empty( $query['customer_in'] ) ) { |
|
| 103 | - $this->total_count = 0; |
|
| 104 | - $this->current_total_count = 0; |
|
| 105 | - $this->items = array(); |
|
| 106 | - $this->status_counts = array(); |
|
| 107 | - return; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - // Prepare class properties. |
|
| 111 | - $this->query = new GetPaid_Subscriptions_Query( $query ); |
|
| 112 | - $this->total_count = $this->query->get_total(); |
|
| 113 | - $this->current_total_count = $this->query->get_total(); |
|
| 114 | - $this->items = $this->query->get_results(); |
|
| 115 | - $this->status_counts = getpaid_get_subscription_status_counts( $query ); |
|
| 116 | - |
|
| 117 | - if ( 'all' != $query['status'] ) { |
|
| 118 | - unset( $query['status'] ); |
|
| 119 | - $this->total_count = getpaid_get_subscriptions( $query, 'count' ); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Get user in. |
|
| 126 | - * |
|
| 127 | - */ |
|
| 128 | - public function get_user_in() { |
|
| 129 | - |
|
| 130 | - // Abort if no user. |
|
| 131 | - if ( empty( $_GET['s'] ) ) { |
|
| 132 | - return null; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - // Or invalid user. |
|
| 136 | - $user = wp_unslash( sanitize_text_field( $_REQUEST['s'] ) ); |
|
| 137 | - |
|
| 138 | - if ( empty( $user ) ) { |
|
| 139 | - return null; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - // Search matching users. |
|
| 143 | - $user = '*' . $user . '*'; |
|
| 144 | - $users = new WP_User_Query( |
|
| 145 | - array( |
|
| 146 | - 'fields' => 'ID', |
|
| 147 | - 'search' => $user, |
|
| 148 | - 'count_total' => false, |
|
| 149 | - ) |
|
| 150 | - ); |
|
| 151 | - |
|
| 152 | - return $users->get_results(); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Gets the list of views available on this table. |
|
| 157 | - * |
|
| 158 | - * The format is an associative array: |
|
| 159 | - * - `'id' => 'link'` |
|
| 160 | - * |
|
| 161 | - * @since 1.0.0 |
|
| 162 | - * |
|
| 163 | - * @return array |
|
| 164 | - */ |
|
| 165 | - public function get_views() { |
|
| 166 | - |
|
| 167 | - $current = isset( $_GET['status'] ) ? sanitize_text_field( $_GET['status'] ) : 'all'; |
|
| 168 | - $views = array( |
|
| 169 | - |
|
| 170 | - 'all' => sprintf( |
|
| 171 | - '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
| 172 | - esc_url( add_query_arg( 'status', false, $this->base_url ) ), |
|
| 173 | - $current === 'all' ? ' class="current"' : '', |
|
| 174 | - __( 'All', 'invoicing' ), |
|
| 175 | - $this->total_count |
|
| 176 | - ), |
|
| 177 | - |
|
| 178 | - ); |
|
| 179 | - |
|
| 180 | - foreach ( array_filter( $this->status_counts ) as $status => $count ) { |
|
| 181 | - |
|
| 182 | - $views[ $status ] = sprintf( |
|
| 183 | - '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
| 184 | - esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ), |
|
| 185 | - $current === $status ? ' class="current"' : '', |
|
| 186 | - esc_html( getpaid_get_subscription_status_label( $status ) ), |
|
| 187 | - $count |
|
| 188 | - ); |
|
| 189 | - |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - return $views; |
|
| 193 | - |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * Render most columns |
|
| 198 | - * |
|
| 199 | - * @access private |
|
| 200 | - * @since 1.0.0 |
|
| 201 | - * @return string |
|
| 202 | - */ |
|
| 203 | - public function column_default( $item, $column_name ) { |
|
| 204 | - return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name ); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * This is how checkbox column renders. |
|
| 209 | - * |
|
| 210 | - * @param WPInv_Subscription $item |
|
| 211 | - * @return string |
|
| 212 | - */ |
|
| 213 | - public function column_cb( $item ) { |
|
| 214 | - return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) ); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Status column |
|
| 219 | - * |
|
| 220 | - * @param WPInv_Subscription $item |
|
| 221 | - * @since 1.0.0 |
|
| 222 | - * @return string |
|
| 223 | - */ |
|
| 224 | - public function column_status( $item ) { |
|
| 225 | - return $item->get_status_label_html(); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Subscription column |
|
| 230 | - * |
|
| 231 | - * @param WPInv_Subscription $item |
|
| 232 | - * @since 1.0.0 |
|
| 233 | - * @return string |
|
| 234 | - */ |
|
| 235 | - public function column_subscription( $item ) { |
|
| 236 | - |
|
| 237 | - $username = __( '(Missing User)', 'invoicing' ); |
|
| 238 | - |
|
| 239 | - $user = get_userdata( $item->get_customer_id() ); |
|
| 240 | - if ( $user ) { |
|
| 241 | - |
|
| 242 | - $username = sprintf( |
|
| 243 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 244 | - absint( $user->ID ), |
|
| 245 | - ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 246 | - ); |
|
| 247 | - |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name |
|
| 251 | - $column_content = sprintf( |
|
| 252 | - _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ), |
|
| 253 | - '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">', |
|
| 254 | - '<strong>' . esc_attr( $item->get_id() ) . '</strong>', |
|
| 19 | + /** |
|
| 20 | + * URL of this page |
|
| 21 | + * |
|
| 22 | + * @var string |
|
| 23 | + * @since 1.0.19 |
|
| 24 | + */ |
|
| 25 | + public $base_url; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Query |
|
| 29 | + * |
|
| 30 | + * @var GetPaid_Subscriptions_Query |
|
| 31 | + * @since 1.0.19 |
|
| 32 | + */ |
|
| 33 | + public $query; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Total subscriptions |
|
| 37 | + * |
|
| 38 | + * @var string |
|
| 39 | + * @since 1.0.0 |
|
| 40 | + */ |
|
| 41 | + public $total_count; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Current status subscriptions |
|
| 45 | + * |
|
| 46 | + * @var string |
|
| 47 | + * @since 1.0.0 |
|
| 48 | + */ |
|
| 49 | + public $current_total_count; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Status counts |
|
| 53 | + * |
|
| 54 | + * @var array |
|
| 55 | + * @since 1.0.19 |
|
| 56 | + */ |
|
| 57 | + public $status_counts; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Number of results to show per page |
|
| 61 | + * |
|
| 62 | + * @var int |
|
| 63 | + * @since 1.0.0 |
|
| 64 | + */ |
|
| 65 | + public $per_page = 10; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Constructor function. |
|
| 69 | + */ |
|
| 70 | + public function __construct() { |
|
| 71 | + |
|
| 72 | + parent::__construct( |
|
| 73 | + array( |
|
| 74 | + 'singular' => 'subscription', |
|
| 75 | + 'plural' => 'subscriptions', |
|
| 76 | + ) |
|
| 77 | + ); |
|
| 78 | + |
|
| 79 | + $this->process_bulk_action(); |
|
| 80 | + |
|
| 81 | + $this->prepare_query(); |
|
| 82 | + |
|
| 83 | + $this->base_url = remove_query_arg( 'status' ); |
|
| 84 | + |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Prepares the display query |
|
| 89 | + */ |
|
| 90 | + public function prepare_query() { |
|
| 91 | + |
|
| 92 | + // Prepare query args. |
|
| 93 | + $query = array( |
|
| 94 | + 'number' => $this->per_page, |
|
| 95 | + 'paged' => $this->get_paged(), |
|
| 96 | + 'status' => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? sanitize_text_field( $_GET['status'] ) : 'all', |
|
| 97 | + 'orderby' => ( isset( $_GET['orderby'] ) ) ? sanitize_text_field( $_GET['orderby'] ) : 'id', |
|
| 98 | + 'order' => ( isset( $_GET['order'] ) ) ? sanitize_text_field( $_GET['order'] ) : 'DESC', |
|
| 99 | + 'customer_in' => $this->get_user_in(), |
|
| 100 | + ); |
|
| 101 | + |
|
| 102 | + if ( is_array( $query['customer_in'] ) && empty( $query['customer_in'] ) ) { |
|
| 103 | + $this->total_count = 0; |
|
| 104 | + $this->current_total_count = 0; |
|
| 105 | + $this->items = array(); |
|
| 106 | + $this->status_counts = array(); |
|
| 107 | + return; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + // Prepare class properties. |
|
| 111 | + $this->query = new GetPaid_Subscriptions_Query( $query ); |
|
| 112 | + $this->total_count = $this->query->get_total(); |
|
| 113 | + $this->current_total_count = $this->query->get_total(); |
|
| 114 | + $this->items = $this->query->get_results(); |
|
| 115 | + $this->status_counts = getpaid_get_subscription_status_counts( $query ); |
|
| 116 | + |
|
| 117 | + if ( 'all' != $query['status'] ) { |
|
| 118 | + unset( $query['status'] ); |
|
| 119 | + $this->total_count = getpaid_get_subscriptions( $query, 'count' ); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Get user in. |
|
| 126 | + * |
|
| 127 | + */ |
|
| 128 | + public function get_user_in() { |
|
| 129 | + |
|
| 130 | + // Abort if no user. |
|
| 131 | + if ( empty( $_GET['s'] ) ) { |
|
| 132 | + return null; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + // Or invalid user. |
|
| 136 | + $user = wp_unslash( sanitize_text_field( $_REQUEST['s'] ) ); |
|
| 137 | + |
|
| 138 | + if ( empty( $user ) ) { |
|
| 139 | + return null; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + // Search matching users. |
|
| 143 | + $user = '*' . $user . '*'; |
|
| 144 | + $users = new WP_User_Query( |
|
| 145 | + array( |
|
| 146 | + 'fields' => 'ID', |
|
| 147 | + 'search' => $user, |
|
| 148 | + 'count_total' => false, |
|
| 149 | + ) |
|
| 150 | + ); |
|
| 151 | + |
|
| 152 | + return $users->get_results(); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Gets the list of views available on this table. |
|
| 157 | + * |
|
| 158 | + * The format is an associative array: |
|
| 159 | + * - `'id' => 'link'` |
|
| 160 | + * |
|
| 161 | + * @since 1.0.0 |
|
| 162 | + * |
|
| 163 | + * @return array |
|
| 164 | + */ |
|
| 165 | + public function get_views() { |
|
| 166 | + |
|
| 167 | + $current = isset( $_GET['status'] ) ? sanitize_text_field( $_GET['status'] ) : 'all'; |
|
| 168 | + $views = array( |
|
| 169 | + |
|
| 170 | + 'all' => sprintf( |
|
| 171 | + '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
| 172 | + esc_url( add_query_arg( 'status', false, $this->base_url ) ), |
|
| 173 | + $current === 'all' ? ' class="current"' : '', |
|
| 174 | + __( 'All', 'invoicing' ), |
|
| 175 | + $this->total_count |
|
| 176 | + ), |
|
| 177 | + |
|
| 178 | + ); |
|
| 179 | + |
|
| 180 | + foreach ( array_filter( $this->status_counts ) as $status => $count ) { |
|
| 181 | + |
|
| 182 | + $views[ $status ] = sprintf( |
|
| 183 | + '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
| 184 | + esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ), |
|
| 185 | + $current === $status ? ' class="current"' : '', |
|
| 186 | + esc_html( getpaid_get_subscription_status_label( $status ) ), |
|
| 187 | + $count |
|
| 188 | + ); |
|
| 189 | + |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + return $views; |
|
| 193 | + |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * Render most columns |
|
| 198 | + * |
|
| 199 | + * @access private |
|
| 200 | + * @since 1.0.0 |
|
| 201 | + * @return string |
|
| 202 | + */ |
|
| 203 | + public function column_default( $item, $column_name ) { |
|
| 204 | + return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name ); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * This is how checkbox column renders. |
|
| 209 | + * |
|
| 210 | + * @param WPInv_Subscription $item |
|
| 211 | + * @return string |
|
| 212 | + */ |
|
| 213 | + public function column_cb( $item ) { |
|
| 214 | + return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) ); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Status column |
|
| 219 | + * |
|
| 220 | + * @param WPInv_Subscription $item |
|
| 221 | + * @since 1.0.0 |
|
| 222 | + * @return string |
|
| 223 | + */ |
|
| 224 | + public function column_status( $item ) { |
|
| 225 | + return $item->get_status_label_html(); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Subscription column |
|
| 230 | + * |
|
| 231 | + * @param WPInv_Subscription $item |
|
| 232 | + * @since 1.0.0 |
|
| 233 | + * @return string |
|
| 234 | + */ |
|
| 235 | + public function column_subscription( $item ) { |
|
| 236 | + |
|
| 237 | + $username = __( '(Missing User)', 'invoicing' ); |
|
| 238 | + |
|
| 239 | + $user = get_userdata( $item->get_customer_id() ); |
|
| 240 | + if ( $user ) { |
|
| 241 | + |
|
| 242 | + $username = sprintf( |
|
| 243 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 244 | + absint( $user->ID ), |
|
| 245 | + ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 246 | + ); |
|
| 247 | + |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name |
|
| 251 | + $column_content = sprintf( |
|
| 252 | + _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ), |
|
| 253 | + '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">', |
|
| 254 | + '<strong>' . esc_attr( $item->get_id() ) . '</strong>', |
|
| 255 | 255 | '</a>', |
| 256 | - $username |
|
| 257 | - ); |
|
| 258 | - |
|
| 259 | - $row_actions = array(); |
|
| 260 | - |
|
| 261 | - // View subscription. |
|
| 262 | - $view_url = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ) ); |
|
| 263 | - $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>'; |
|
| 264 | - |
|
| 265 | - // View invoice. |
|
| 266 | - $invoice = get_post( $item->get_parent_invoice_id() ); |
|
| 267 | - |
|
| 268 | - if ( ! empty( $invoice ) ) { |
|
| 269 | - $invoice_url = get_edit_post_link( $invoice ); |
|
| 270 | - $row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>'; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - $delete_url = esc_url( |
|
| 274 | - wp_nonce_url( |
|
| 275 | - add_query_arg( |
|
| 276 | - array( |
|
| 277 | - 'getpaid-admin-action' => 'subscription_manual_delete', |
|
| 278 | - 'id' => $item->get_id(), |
|
| 279 | - ) |
|
| 280 | - ), |
|
| 281 | - 'getpaid-nonce', |
|
| 282 | - 'getpaid-nonce' |
|
| 283 | - ) |
|
| 284 | - ); |
|
| 285 | - $row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>'; |
|
| 286 | - |
|
| 287 | - $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) ); |
|
| 288 | - |
|
| 289 | - return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * Renewal date column |
|
| 294 | - * |
|
| 295 | - * @param WPInv_Subscription $item |
|
| 296 | - * @since 1.0.0 |
|
| 297 | - * @return string |
|
| 298 | - */ |
|
| 299 | - public function column_renewal_date( $item ) { |
|
| 300 | - return getpaid_format_date_value( $item->get_expiration() ); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * Start date column |
|
| 305 | - * |
|
| 306 | - * @param WPInv_Subscription $item |
|
| 307 | - * @since 1.0.0 |
|
| 308 | - * @return string |
|
| 309 | - */ |
|
| 310 | - public function column_start_date( $item ) { |
|
| 311 | - |
|
| 312 | - $gateway = $item->get_parent_invoice()->get_gateway_title(); |
|
| 313 | - |
|
| 314 | - if ( empty( $gateway ) ) { |
|
| 315 | - return getpaid_format_date_value( $item->get_date_created() ); |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $item ); |
|
| 319 | - if ( ! empty( $url ) ) { |
|
| 320 | - |
|
| 321 | - return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf( |
|
| 322 | - __( 'Via %s', 'invoicing' ), |
|
| 323 | - '<strong><a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</a></strong>' |
|
| 324 | - ); |
|
| 325 | - |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf( |
|
| 329 | - __( 'Via %s', 'invoicing' ), |
|
| 330 | - '<strong>' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</strong>' |
|
| 331 | - ); |
|
| 332 | - |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * Amount column |
|
| 337 | - * |
|
| 338 | - * @param WPInv_Subscription $item |
|
| 339 | - * @since 1.0.19 |
|
| 340 | - * @return string |
|
| 341 | - */ |
|
| 342 | - public static function column_amount( $item ) { |
|
| 343 | - $amount = getpaid_get_formatted_subscription_amount( $item ); |
|
| 344 | - return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>"; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * Billing Times column |
|
| 349 | - * |
|
| 350 | - * @param WPInv_Subscription $item |
|
| 351 | - * @since 1.0.0 |
|
| 352 | - * @return string |
|
| 353 | - */ |
|
| 354 | - public function column_renewals( $item ) { |
|
| 355 | - $max_bills = $item->get_bill_times(); |
|
| 356 | - return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? '∞' : $max_bills ); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * Product ID column |
|
| 361 | - * |
|
| 362 | - * @param WPInv_Subscription $item |
|
| 363 | - * @since 1.0.0 |
|
| 364 | - * @return string |
|
| 365 | - */ |
|
| 366 | - public function column_item( $item ) { |
|
| 367 | - $subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() ); |
|
| 368 | - |
|
| 369 | - if ( empty( $subscription_group ) ) { |
|
| 370 | - return $this->generate_item_markup( $item->get_product_id() ); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - $markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 374 | - return implode( ' | ', $markup ); |
|
| 375 | - |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * Generates the items markup. |
|
| 380 | - * |
|
| 381 | - * @param int $item_id |
|
| 382 | - * @since 1.0.0 |
|
| 383 | - * @return string |
|
| 384 | - */ |
|
| 385 | - public static function generate_item_markup( $item_id ) { |
|
| 386 | - $item = get_post( $item_id ); |
|
| 387 | - |
|
| 388 | - if ( ! empty( $item ) ) { |
|
| 389 | - $link = get_edit_post_link( $item ); |
|
| 390 | - $link = esc_url( $link ); |
|
| 391 | - $name = esc_html( get_the_title( $item ) ); |
|
| 392 | - return wpinv_current_user_can_manage_invoicing() ? "<a href='$link'>$name</a>" : $name; |
|
| 393 | - } else { |
|
| 394 | - return sprintf( __( 'Item #%s', 'invoicing' ), $item_id ); |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - /** |
|
| 400 | - * Retrieve the current page number |
|
| 401 | - * |
|
| 402 | - * @return int |
|
| 403 | - */ |
|
| 404 | - public function get_paged() { |
|
| 405 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * Setup the final data for the table |
|
| 410 | - * |
|
| 411 | - */ |
|
| 412 | - public function prepare_items() { |
|
| 413 | - |
|
| 414 | - $columns = $this->get_columns(); |
|
| 415 | - $hidden = array(); |
|
| 416 | - $sortable = $this->get_sortable_columns(); |
|
| 417 | - |
|
| 418 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 419 | - |
|
| 420 | - $this->set_pagination_args( |
|
| 421 | - array( |
|
| 422 | - 'total_items' => $this->current_total_count, |
|
| 423 | - 'per_page' => $this->per_page, |
|
| 424 | - 'total_pages' => ceil( $this->current_total_count / $this->per_page ), |
|
| 425 | - ) |
|
| 426 | - ); |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * Table columns |
|
| 431 | - * |
|
| 432 | - * @return array |
|
| 433 | - */ |
|
| 434 | - public function get_columns() { |
|
| 435 | - $columns = array( |
|
| 436 | - 'cb' => '<input type="checkbox" />', |
|
| 437 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 438 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 439 | - 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
| 440 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 441 | - 'item' => __( 'Items', 'invoicing' ), |
|
| 442 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 443 | - ); |
|
| 444 | - |
|
| 445 | - return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns ); |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - /** |
|
| 449 | - * Sortable table columns. |
|
| 450 | - * |
|
| 451 | - * @return array |
|
| 452 | - */ |
|
| 453 | - public function get_sortable_columns() { |
|
| 454 | - $sortable = array( |
|
| 455 | - 'subscription' => array( 'id', true ), |
|
| 456 | - 'start_date' => array( 'created', true ), |
|
| 457 | - 'renewal_date' => array( 'expiration', true ), |
|
| 458 | - 'renewals' => array( 'bill_times', true ), |
|
| 459 | - 'item' => array( 'product_id', true ), |
|
| 460 | - 'status' => array( 'status', true ), |
|
| 461 | - ); |
|
| 462 | - |
|
| 463 | - return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable ); |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * Whether the table has items to display or not |
|
| 468 | - * |
|
| 469 | - * @return bool |
|
| 470 | - */ |
|
| 471 | - public function has_items() { |
|
| 472 | - return ! empty( $this->current_total_count ); |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - /** |
|
| 476 | - * Processes bulk actions. |
|
| 477 | - * |
|
| 478 | - */ |
|
| 479 | - public function process_bulk_action() { |
|
| 480 | - |
|
| 481 | - } |
|
| 256 | + $username |
|
| 257 | + ); |
|
| 258 | + |
|
| 259 | + $row_actions = array(); |
|
| 260 | + |
|
| 261 | + // View subscription. |
|
| 262 | + $view_url = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ) ); |
|
| 263 | + $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>'; |
|
| 264 | + |
|
| 265 | + // View invoice. |
|
| 266 | + $invoice = get_post( $item->get_parent_invoice_id() ); |
|
| 267 | + |
|
| 268 | + if ( ! empty( $invoice ) ) { |
|
| 269 | + $invoice_url = get_edit_post_link( $invoice ); |
|
| 270 | + $row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>'; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + $delete_url = esc_url( |
|
| 274 | + wp_nonce_url( |
|
| 275 | + add_query_arg( |
|
| 276 | + array( |
|
| 277 | + 'getpaid-admin-action' => 'subscription_manual_delete', |
|
| 278 | + 'id' => $item->get_id(), |
|
| 279 | + ) |
|
| 280 | + ), |
|
| 281 | + 'getpaid-nonce', |
|
| 282 | + 'getpaid-nonce' |
|
| 283 | + ) |
|
| 284 | + ); |
|
| 285 | + $row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>'; |
|
| 286 | + |
|
| 287 | + $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) ); |
|
| 288 | + |
|
| 289 | + return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Renewal date column |
|
| 294 | + * |
|
| 295 | + * @param WPInv_Subscription $item |
|
| 296 | + * @since 1.0.0 |
|
| 297 | + * @return string |
|
| 298 | + */ |
|
| 299 | + public function column_renewal_date( $item ) { |
|
| 300 | + return getpaid_format_date_value( $item->get_expiration() ); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * Start date column |
|
| 305 | + * |
|
| 306 | + * @param WPInv_Subscription $item |
|
| 307 | + * @since 1.0.0 |
|
| 308 | + * @return string |
|
| 309 | + */ |
|
| 310 | + public function column_start_date( $item ) { |
|
| 311 | + |
|
| 312 | + $gateway = $item->get_parent_invoice()->get_gateway_title(); |
|
| 313 | + |
|
| 314 | + if ( empty( $gateway ) ) { |
|
| 315 | + return getpaid_format_date_value( $item->get_date_created() ); |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $item ); |
|
| 319 | + if ( ! empty( $url ) ) { |
|
| 320 | + |
|
| 321 | + return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf( |
|
| 322 | + __( 'Via %s', 'invoicing' ), |
|
| 323 | + '<strong><a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</a></strong>' |
|
| 324 | + ); |
|
| 325 | + |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf( |
|
| 329 | + __( 'Via %s', 'invoicing' ), |
|
| 330 | + '<strong>' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</strong>' |
|
| 331 | + ); |
|
| 332 | + |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * Amount column |
|
| 337 | + * |
|
| 338 | + * @param WPInv_Subscription $item |
|
| 339 | + * @since 1.0.19 |
|
| 340 | + * @return string |
|
| 341 | + */ |
|
| 342 | + public static function column_amount( $item ) { |
|
| 343 | + $amount = getpaid_get_formatted_subscription_amount( $item ); |
|
| 344 | + return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>"; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * Billing Times column |
|
| 349 | + * |
|
| 350 | + * @param WPInv_Subscription $item |
|
| 351 | + * @since 1.0.0 |
|
| 352 | + * @return string |
|
| 353 | + */ |
|
| 354 | + public function column_renewals( $item ) { |
|
| 355 | + $max_bills = $item->get_bill_times(); |
|
| 356 | + return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? '∞' : $max_bills ); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * Product ID column |
|
| 361 | + * |
|
| 362 | + * @param WPInv_Subscription $item |
|
| 363 | + * @since 1.0.0 |
|
| 364 | + * @return string |
|
| 365 | + */ |
|
| 366 | + public function column_item( $item ) { |
|
| 367 | + $subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() ); |
|
| 368 | + |
|
| 369 | + if ( empty( $subscription_group ) ) { |
|
| 370 | + return $this->generate_item_markup( $item->get_product_id() ); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + $markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
| 374 | + return implode( ' | ', $markup ); |
|
| 375 | + |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * Generates the items markup. |
|
| 380 | + * |
|
| 381 | + * @param int $item_id |
|
| 382 | + * @since 1.0.0 |
|
| 383 | + * @return string |
|
| 384 | + */ |
|
| 385 | + public static function generate_item_markup( $item_id ) { |
|
| 386 | + $item = get_post( $item_id ); |
|
| 387 | + |
|
| 388 | + if ( ! empty( $item ) ) { |
|
| 389 | + $link = get_edit_post_link( $item ); |
|
| 390 | + $link = esc_url( $link ); |
|
| 391 | + $name = esc_html( get_the_title( $item ) ); |
|
| 392 | + return wpinv_current_user_can_manage_invoicing() ? "<a href='$link'>$name</a>" : $name; |
|
| 393 | + } else { |
|
| 394 | + return sprintf( __( 'Item #%s', 'invoicing' ), $item_id ); |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + /** |
|
| 400 | + * Retrieve the current page number |
|
| 401 | + * |
|
| 402 | + * @return int |
|
| 403 | + */ |
|
| 404 | + public function get_paged() { |
|
| 405 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * Setup the final data for the table |
|
| 410 | + * |
|
| 411 | + */ |
|
| 412 | + public function prepare_items() { |
|
| 413 | + |
|
| 414 | + $columns = $this->get_columns(); |
|
| 415 | + $hidden = array(); |
|
| 416 | + $sortable = $this->get_sortable_columns(); |
|
| 417 | + |
|
| 418 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 419 | + |
|
| 420 | + $this->set_pagination_args( |
|
| 421 | + array( |
|
| 422 | + 'total_items' => $this->current_total_count, |
|
| 423 | + 'per_page' => $this->per_page, |
|
| 424 | + 'total_pages' => ceil( $this->current_total_count / $this->per_page ), |
|
| 425 | + ) |
|
| 426 | + ); |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * Table columns |
|
| 431 | + * |
|
| 432 | + * @return array |
|
| 433 | + */ |
|
| 434 | + public function get_columns() { |
|
| 435 | + $columns = array( |
|
| 436 | + 'cb' => '<input type="checkbox" />', |
|
| 437 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 438 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 439 | + 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
| 440 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 441 | + 'item' => __( 'Items', 'invoicing' ), |
|
| 442 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 443 | + ); |
|
| 444 | + |
|
| 445 | + return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns ); |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * Sortable table columns. |
|
| 450 | + * |
|
| 451 | + * @return array |
|
| 452 | + */ |
|
| 453 | + public function get_sortable_columns() { |
|
| 454 | + $sortable = array( |
|
| 455 | + 'subscription' => array( 'id', true ), |
|
| 456 | + 'start_date' => array( 'created', true ), |
|
| 457 | + 'renewal_date' => array( 'expiration', true ), |
|
| 458 | + 'renewals' => array( 'bill_times', true ), |
|
| 459 | + 'item' => array( 'product_id', true ), |
|
| 460 | + 'status' => array( 'status', true ), |
|
| 461 | + ); |
|
| 462 | + |
|
| 463 | + return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable ); |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * Whether the table has items to display or not |
|
| 468 | + * |
|
| 469 | + * @return bool |
|
| 470 | + */ |
|
| 471 | + public function has_items() { |
|
| 472 | + return ! empty( $this->current_total_count ); |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * Processes bulk actions. |
|
| 477 | + * |
|
| 478 | + */ |
|
| 479 | + public function process_bulk_action() { |
|
| 480 | + |
|
| 481 | + } |
|
| 482 | 482 | |
| 483 | 483 | } |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | <?php |
| 45 | 45 | |
| 46 | 46 | if ( wpinv_is_gateway_active( $id ) ) { |
| 47 | - echo "<i class='text-success fa fa-check'></i>"; |
|
| 47 | + echo "<i class='text-success fa fa-check'></i>"; |
|
| 48 | 48 | } else { |
| 49 | - echo "<i class='text-dark fa fa-times'></i>"; |
|
| 49 | + echo "<i class='text-dark fa fa-times'></i>"; |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | ?> |
@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | $supports = apply_filters( 'getapid_gateway_supports_subscription', $supports, $id ); |
| 59 | 59 | |
| 60 | 60 | if ( $supports ) { |
| 61 | - echo "<i class='text-success fa fa-check'></i>"; |
|
| 61 | + echo "<i class='text-success fa fa-check'></i>"; |
|
| 62 | 62 | } else { |
| 63 | - echo "<i class='text-dark fa fa-times'></i>"; |
|
| 63 | + echo "<i class='text-dark fa fa-times'></i>"; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | ?> |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | <input type="checkbox" name="plugins[<?php echo esc_attr( $plugin['slug'] ); ?>]" value="<?php echo esc_attr( $plugin['file'] ); ?>" class="custom-control-input" |
| 28 | 28 | <?php |
| 29 | 29 | if ( is_plugin_active( $plugin['slug'] ) ) { |
| 30 | - echo 'checked';} |
|
| 30 | + echo 'checked';} |
|
| 31 | 31 | ?> |
| 32 | 32 | > |
| 33 | 33 | <label class="custom-control-label" for="ac-setting-updates"></label> |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | - exit; // Exit if accessed directly |
|
| 10 | + exit; // Exit if accessed directly |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
@@ -15,22 +15,22 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | class GetPaid_Meta_Box_Invoice_Shipping_Address { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Output the metabox. |
|
| 20 | - * |
|
| 21 | - * @param WP_Post $post |
|
| 22 | - */ |
|
| 23 | - public static function output( $post ) { |
|
| 18 | + /** |
|
| 19 | + * Output the metabox. |
|
| 20 | + * |
|
| 21 | + * @param WP_Post $post |
|
| 22 | + */ |
|
| 23 | + public static function output( $post ) { |
|
| 24 | 24 | |
| 25 | - // Retrieve shipping address. |
|
| 26 | - $shipping_address = get_post_meta( $post->ID, 'shipping_address', true ); |
|
| 25 | + // Retrieve shipping address. |
|
| 26 | + $shipping_address = get_post_meta( $post->ID, 'shipping_address', true ); |
|
| 27 | 27 | |
| 28 | - // Abort if it is invalid. |
|
| 29 | - if ( ! is_array( $shipping_address ) ) { |
|
| 30 | - return; |
|
| 31 | - } |
|
| 28 | + // Abort if it is invalid. |
|
| 29 | + if ( ! is_array( $shipping_address ) ) { |
|
| 30 | + return; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - ?> |
|
| 33 | + ?> |
|
| 34 | 34 | |
| 35 | 35 | <div class="bsui"> |
| 36 | 36 | |
@@ -68,31 +68,31 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | <?php |
| 70 | 70 | |
| 71 | - } |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Prepares a value. |
|
| 75 | - * |
|
| 76 | - * @param array $address |
|
| 77 | - * @param string $key |
|
| 78 | - * @return string |
|
| 79 | - */ |
|
| 80 | - public static function prepare_for_display( $address, $key ) { |
|
| 73 | + /** |
|
| 74 | + * Prepares a value. |
|
| 75 | + * |
|
| 76 | + * @param array $address |
|
| 77 | + * @param string $key |
|
| 78 | + * @return string |
|
| 79 | + */ |
|
| 80 | + public static function prepare_for_display( $address, $key ) { |
|
| 81 | 81 | |
| 82 | - // Prepare the value. |
|
| 83 | - $value = $address[ $key ]; |
|
| 82 | + // Prepare the value. |
|
| 83 | + $value = $address[ $key ]; |
|
| 84 | 84 | |
| 85 | - if ( $key == 'country' ) { |
|
| 86 | - $value = wpinv_country_name( $value ); |
|
| 87 | - } |
|
| 85 | + if ( $key == 'country' ) { |
|
| 86 | + $value = wpinv_country_name( $value ); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - if ( $key == 'state' ) { |
|
| 90 | - $country = isset( $address['country'] ) ? $address['country'] : wpinv_get_default_country(); |
|
| 91 | - $value = wpinv_state_name( $value, $country ); |
|
| 92 | - } |
|
| 89 | + if ( $key == 'state' ) { |
|
| 90 | + $country = isset( $address['country'] ) ? $address['country'] : wpinv_get_default_country(); |
|
| 91 | + $value = wpinv_state_name( $value, $country ); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - return esc_html( $value ); |
|
| 94 | + return esc_html( $value ); |
|
| 95 | 95 | |
| 96 | - } |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | 98 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 11 | - exit; // Exit if accessed directly |
|
| 11 | + exit; // Exit if accessed directly |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | /** |
@@ -17,10 +17,10 @@ discard block |
||
| 17 | 17 | class GetPaid_Meta_Box_Discount_Details { |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | - * Output the metabox. |
|
| 21 | - * |
|
| 22 | - * @param WP_Post $post |
|
| 23 | - */ |
|
| 20 | + * Output the metabox. |
|
| 21 | + * |
|
| 22 | + * @param WP_Post $post |
|
| 23 | + */ |
|
| 24 | 24 | public static function output( $post ) { |
| 25 | 25 | |
| 26 | 26 | // Prepare the discount. |
@@ -396,35 +396,35 @@ discard block |
||
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | /** |
| 399 | - * Save meta box data. |
|
| 400 | - * |
|
| 401 | - * @param int $post_id |
|
| 402 | - */ |
|
| 403 | - public static function save( $post_id ) { |
|
| 399 | + * Save meta box data. |
|
| 400 | + * |
|
| 401 | + * @param int $post_id |
|
| 402 | + */ |
|
| 403 | + public static function save( $post_id ) { |
|
| 404 | 404 | |
| 405 | 405 | // Prepare the discount. |
| 406 | 406 | $discount = new WPInv_Discount( $post_id ); |
| 407 | 407 | |
| 408 | 408 | // Load new data. |
| 409 | 409 | $discount->set_props( |
| 410 | - array( |
|
| 411 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null, |
|
| 412 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null, |
|
| 413 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
| 414 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
| 415 | - 'is_single_use' => ! empty( $_POST['wpinv_discount_single_use'] ), |
|
| 410 | + array( |
|
| 411 | + 'code' => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null, |
|
| 412 | + 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null, |
|
| 413 | + 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
| 414 | + 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
| 415 | + 'is_single_use' => ! empty( $_POST['wpinv_discount_single_use'] ), |
|
| 416 | 416 | 'type' => isset( $_POST['wpinv_discount_type'] ) ? wpinv_clean( $_POST['wpinv_discount_type'] ) : null, |
| 417 | - 'is_recurring' => ! empty( $_POST['wpinv_discount_recurring'] ), |
|
| 418 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(), |
|
| 419 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(), |
|
| 417 | + 'is_recurring' => ! empty( $_POST['wpinv_discount_recurring'] ), |
|
| 418 | + 'items' => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(), |
|
| 419 | + 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(), |
|
| 420 | 420 | 'required_items' => isset( $_POST['wpinv_discount_required_items'] ) ? wpinv_clean( $_POST['wpinv_discount_required_items'] ) : array(), |
| 421 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null, |
|
| 422 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null, |
|
| 423 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null, |
|
| 424 | - ) |
|
| 421 | + 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null, |
|
| 422 | + 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null, |
|
| 423 | + 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null, |
|
| 424 | + ) |
|
| 425 | 425 | ); |
| 426 | 426 | |
| 427 | - $discount->save(); |
|
| 428 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
| 429 | - } |
|
| 427 | + $discount->save(); |
|
| 428 | + do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
| 429 | + } |
|
| 430 | 430 | } |
@@ -5,110 +5,110 @@ discard block |
||
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 8 | - exit; // Exit if accessed directly |
|
| 8 | + exit; // Exit if accessed directly |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | if ( ! class_exists( 'GetPaid_Admin_Profile', false ) ) : |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * GetPaid_Admin_Profile Class. |
|
| 15 | - */ |
|
| 16 | - class GetPaid_Admin_Profile { |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * Hook in tabs. |
|
| 20 | - */ |
|
| 21 | - public function __construct() { |
|
| 22 | - add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
| 23 | - add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
| 24 | - |
|
| 25 | - add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) ); |
|
| 26 | - add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) ); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Get Address Fields for the edit user pages. |
|
| 31 | - * |
|
| 32 | - * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned |
|
| 33 | - */ |
|
| 34 | - public function get_customer_meta_fields() { |
|
| 35 | - |
|
| 36 | - $show_fields = apply_filters( |
|
| 37 | - 'getpaid_customer_meta_fields', |
|
| 38 | - array( |
|
| 39 | - 'billing' => array( |
|
| 40 | - 'title' => __( 'Billing Details (GetPaid)', 'invoicing' ), |
|
| 41 | - 'fields' => array( |
|
| 42 | - '_wpinv_first_name' => array( |
|
| 43 | - 'label' => __( 'First name', 'invoicing' ), |
|
| 44 | - 'description' => '', |
|
| 45 | - ), |
|
| 46 | - '_wpinv_last_name' => array( |
|
| 47 | - 'label' => __( 'Last name', 'invoicing' ), |
|
| 48 | - 'description' => '', |
|
| 49 | - ), |
|
| 50 | - '_wpinv_company' => array( |
|
| 51 | - 'label' => __( 'Company', 'invoicing' ), |
|
| 52 | - 'description' => '', |
|
| 53 | - ), |
|
| 54 | - '_wpinv_company_id' => array( |
|
| 55 | - 'label' => __( 'Company ID', 'invoicing' ), |
|
| 56 | - 'description' => '', |
|
| 57 | - ), |
|
| 58 | - '_wpinv_address' => array( |
|
| 59 | - 'label' => __( 'Address', 'invoicing' ), |
|
| 60 | - 'description' => '', |
|
| 61 | - ), |
|
| 62 | - '_wpinv_city' => array( |
|
| 63 | - 'label' => __( 'City', 'invoicing' ), |
|
| 64 | - 'description' => '', |
|
| 65 | - ), |
|
| 66 | - '_wpinv_zip' => array( |
|
| 67 | - 'label' => __( 'Postcode / ZIP', 'invoicing' ), |
|
| 68 | - 'description' => '', |
|
| 69 | - ), |
|
| 70 | - '_wpinv_country' => array( |
|
| 71 | - 'label' => __( 'Country / Region', 'invoicing' ), |
|
| 72 | - 'description' => '', |
|
| 73 | - 'class' => 'getpaid_js_field-country', |
|
| 74 | - 'type' => 'select', |
|
| 75 | - 'options' => array( '' => __( 'Select a country / region…', 'invoicing' ) ) + wpinv_get_country_list(), |
|
| 76 | - ), |
|
| 77 | - '_wpinv_state' => array( |
|
| 78 | - 'label' => __( 'State / County', 'invoicing' ), |
|
| 79 | - 'description' => __( 'State / County or state code', 'invoicing' ), |
|
| 80 | - 'class' => 'getpaid_js_field-state regular-text', |
|
| 81 | - ), |
|
| 82 | - '_wpinv_phone' => array( |
|
| 83 | - 'label' => __( 'Phone', 'invoicing' ), |
|
| 84 | - 'description' => '', |
|
| 85 | - ), |
|
| 86 | - '_wpinv_vat_number' => array( |
|
| 87 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
| 88 | - 'description' => '', |
|
| 89 | - ), |
|
| 90 | - ), |
|
| 91 | - ), |
|
| 92 | - ) |
|
| 93 | - ); |
|
| 94 | - return $show_fields; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Show Address Fields on edit user pages. |
|
| 99 | - * |
|
| 100 | - * @param WP_User $user |
|
| 101 | - */ |
|
| 102 | - public function add_customer_meta_fields( $user ) { |
|
| 103 | - |
|
| 104 | - if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) { |
|
| 105 | - return; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - $show_fields = $this->get_customer_meta_fields(); |
|
| 109 | - |
|
| 110 | - foreach ( $show_fields as $fieldset_key => $fieldset ) : |
|
| 111 | - ?> |
|
| 13 | + /** |
|
| 14 | + * GetPaid_Admin_Profile Class. |
|
| 15 | + */ |
|
| 16 | + class GetPaid_Admin_Profile { |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * Hook in tabs. |
|
| 20 | + */ |
|
| 21 | + public function __construct() { |
|
| 22 | + add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
| 23 | + add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
| 24 | + |
|
| 25 | + add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) ); |
|
| 26 | + add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) ); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Get Address Fields for the edit user pages. |
|
| 31 | + * |
|
| 32 | + * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned |
|
| 33 | + */ |
|
| 34 | + public function get_customer_meta_fields() { |
|
| 35 | + |
|
| 36 | + $show_fields = apply_filters( |
|
| 37 | + 'getpaid_customer_meta_fields', |
|
| 38 | + array( |
|
| 39 | + 'billing' => array( |
|
| 40 | + 'title' => __( 'Billing Details (GetPaid)', 'invoicing' ), |
|
| 41 | + 'fields' => array( |
|
| 42 | + '_wpinv_first_name' => array( |
|
| 43 | + 'label' => __( 'First name', 'invoicing' ), |
|
| 44 | + 'description' => '', |
|
| 45 | + ), |
|
| 46 | + '_wpinv_last_name' => array( |
|
| 47 | + 'label' => __( 'Last name', 'invoicing' ), |
|
| 48 | + 'description' => '', |
|
| 49 | + ), |
|
| 50 | + '_wpinv_company' => array( |
|
| 51 | + 'label' => __( 'Company', 'invoicing' ), |
|
| 52 | + 'description' => '', |
|
| 53 | + ), |
|
| 54 | + '_wpinv_company_id' => array( |
|
| 55 | + 'label' => __( 'Company ID', 'invoicing' ), |
|
| 56 | + 'description' => '', |
|
| 57 | + ), |
|
| 58 | + '_wpinv_address' => array( |
|
| 59 | + 'label' => __( 'Address', 'invoicing' ), |
|
| 60 | + 'description' => '', |
|
| 61 | + ), |
|
| 62 | + '_wpinv_city' => array( |
|
| 63 | + 'label' => __( 'City', 'invoicing' ), |
|
| 64 | + 'description' => '', |
|
| 65 | + ), |
|
| 66 | + '_wpinv_zip' => array( |
|
| 67 | + 'label' => __( 'Postcode / ZIP', 'invoicing' ), |
|
| 68 | + 'description' => '', |
|
| 69 | + ), |
|
| 70 | + '_wpinv_country' => array( |
|
| 71 | + 'label' => __( 'Country / Region', 'invoicing' ), |
|
| 72 | + 'description' => '', |
|
| 73 | + 'class' => 'getpaid_js_field-country', |
|
| 74 | + 'type' => 'select', |
|
| 75 | + 'options' => array( '' => __( 'Select a country / region…', 'invoicing' ) ) + wpinv_get_country_list(), |
|
| 76 | + ), |
|
| 77 | + '_wpinv_state' => array( |
|
| 78 | + 'label' => __( 'State / County', 'invoicing' ), |
|
| 79 | + 'description' => __( 'State / County or state code', 'invoicing' ), |
|
| 80 | + 'class' => 'getpaid_js_field-state regular-text', |
|
| 81 | + ), |
|
| 82 | + '_wpinv_phone' => array( |
|
| 83 | + 'label' => __( 'Phone', 'invoicing' ), |
|
| 84 | + 'description' => '', |
|
| 85 | + ), |
|
| 86 | + '_wpinv_vat_number' => array( |
|
| 87 | + 'label' => __( 'VAT Number', 'invoicing' ), |
|
| 88 | + 'description' => '', |
|
| 89 | + ), |
|
| 90 | + ), |
|
| 91 | + ), |
|
| 92 | + ) |
|
| 93 | + ); |
|
| 94 | + return $show_fields; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Show Address Fields on edit user pages. |
|
| 99 | + * |
|
| 100 | + * @param WP_User $user |
|
| 101 | + */ |
|
| 102 | + public function add_customer_meta_fields( $user ) { |
|
| 103 | + |
|
| 104 | + if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) { |
|
| 105 | + return; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + $show_fields = $this->get_customer_meta_fields(); |
|
| 109 | + |
|
| 110 | + foreach ( $show_fields as $fieldset_key => $fieldset ) : |
|
| 111 | + ?> |
|
| 112 | 112 | <h2><?php echo esc_html( $fieldset['title'] ); ?></h2> |
| 113 | 113 | <table class="form-table" id="<?php echo esc_attr( 'getpaid-fieldset-' . $fieldset_key ); ?>"> |
| 114 | 114 | <?php foreach ( $fieldset['fields'] as $key => $field ) : ?> |
@@ -120,9 +120,9 @@ discard block |
||
| 120 | 120 | <?php if ( ! empty( $field['type'] ) && 'select' === $field['type'] ) : ?> |
| 121 | 121 | <select name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" class="<?php echo esc_attr( $field['class'] ); ?> wpi_select2" style="width: 25em;"> |
| 122 | 122 | <?php |
| 123 | - $selected = esc_attr( get_user_meta( $user->ID, $key, true ) ); |
|
| 124 | - foreach ( $field['options'] as $option_key => $option_value ) : |
|
| 125 | - ?> |
|
| 123 | + $selected = esc_attr( get_user_meta( $user->ID, $key, true ) ); |
|
| 124 | + foreach ( $field['options'] as $option_key => $option_value ) : |
|
| 125 | + ?> |
|
| 126 | 126 | <option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( $selected, $option_key, true ); ?>><?php echo esc_html( $option_value ); ?></option> |
| 127 | 127 | <?php endforeach; ?> |
| 128 | 128 | </select> |
@@ -137,52 +137,52 @@ discard block |
||
| 137 | 137 | <?php endforeach; ?> |
| 138 | 138 | </table> |
| 139 | 139 | <?php |
| 140 | - endforeach; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Save Address Fields on edit user pages. |
|
| 145 | - * |
|
| 146 | - * @param int $user_id User ID of the user being saved |
|
| 147 | - */ |
|
| 148 | - public function save_customer_meta_fields( $user_id ) { |
|
| 149 | - if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) { |
|
| 150 | - return; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - $save_fields = $this->get_customer_meta_fields(); |
|
| 154 | - |
|
| 155 | - foreach ( $save_fields as $fieldset ) { |
|
| 156 | - |
|
| 157 | - foreach ( $fieldset['fields'] as $key => $field ) { |
|
| 158 | - |
|
| 159 | - if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) { |
|
| 160 | - update_user_meta( $user_id, $key, ! empty( $_POST[ $key ] ) ); |
|
| 161 | - } elseif ( isset( $_POST[ $key ] ) ) { |
|
| 162 | - update_user_meta( $user_id, $key, wpinv_clean( $_POST[ $key ] ) ); |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Get user meta for a given key, with fallbacks to core user info for pre-existing fields. |
|
| 170 | - * |
|
| 171 | - * @since 3.1.0 |
|
| 172 | - * @param int $user_id User ID of the user being edited |
|
| 173 | - * @param string $key Key for user meta field |
|
| 174 | - * @return string |
|
| 175 | - */ |
|
| 176 | - protected function get_user_meta( $user_id, $key ) { |
|
| 177 | - $value = get_user_meta( $user_id, $key, true ); |
|
| 178 | - $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' ); |
|
| 179 | - if ( ! $value && in_array( $key, $existing_fields ) ) { |
|
| 180 | - $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true ); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - return $value; |
|
| 184 | - } |
|
| 185 | - } |
|
| 140 | + endforeach; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Save Address Fields on edit user pages. |
|
| 145 | + * |
|
| 146 | + * @param int $user_id User ID of the user being saved |
|
| 147 | + */ |
|
| 148 | + public function save_customer_meta_fields( $user_id ) { |
|
| 149 | + if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) { |
|
| 150 | + return; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + $save_fields = $this->get_customer_meta_fields(); |
|
| 154 | + |
|
| 155 | + foreach ( $save_fields as $fieldset ) { |
|
| 156 | + |
|
| 157 | + foreach ( $fieldset['fields'] as $key => $field ) { |
|
| 158 | + |
|
| 159 | + if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) { |
|
| 160 | + update_user_meta( $user_id, $key, ! empty( $_POST[ $key ] ) ); |
|
| 161 | + } elseif ( isset( $_POST[ $key ] ) ) { |
|
| 162 | + update_user_meta( $user_id, $key, wpinv_clean( $_POST[ $key ] ) ); |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Get user meta for a given key, with fallbacks to core user info for pre-existing fields. |
|
| 170 | + * |
|
| 171 | + * @since 3.1.0 |
|
| 172 | + * @param int $user_id User ID of the user being edited |
|
| 173 | + * @param string $key Key for user meta field |
|
| 174 | + * @return string |
|
| 175 | + */ |
|
| 176 | + protected function get_user_meta( $user_id, $key ) { |
|
| 177 | + $value = get_user_meta( $user_id, $key, true ); |
|
| 178 | + $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' ); |
|
| 179 | + if ( ! $value && in_array( $key, $existing_fields ) ) { |
|
| 180 | + $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true ); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + return $value; |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | 187 | endif; |
| 188 | 188 | |
@@ -57,8 +57,8 @@ discard block |
||
| 57 | 57 | 'getpaid-nonce', |
| 58 | 58 | 'getpaid-nonce' |
| 59 | 59 | ); |
| 60 | - $anchor = __( 'Deactivate', 'invoicing' ); |
|
| 61 | - $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
| 60 | + $anchor = __( 'Deactivate', 'invoicing' ); |
|
| 61 | + $title = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' ); |
|
| 62 | 62 | $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
| 63 | 63 | |
| 64 | 64 | } elseif ( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) { |
@@ -73,8 +73,8 @@ discard block |
||
| 73 | 73 | 'getpaid-nonce', |
| 74 | 74 | 'getpaid-nonce' |
| 75 | 75 | ); |
| 76 | - $anchor = __( 'Activate', 'invoicing' ); |
|
| 77 | - $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
| 76 | + $anchor = __( 'Activate', 'invoicing' ); |
|
| 77 | + $title = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' ); |
|
| 78 | 78 | $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
| 79 | 79 | |
| 80 | 80 | } |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | 'getpaid-nonce' |
| 92 | 92 | ) |
| 93 | 93 | ); |
| 94 | - $anchor = __( 'Delete', 'invoicing' ); |
|
| 95 | - $title = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' ); |
|
| 94 | + $anchor = __( 'Delete', 'invoicing' ); |
|
| 95 | + $title = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' ); |
|
| 96 | 96 | $row_actions['delete'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>"; |
| 97 | 97 | |
| 98 | 98 | $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
@@ -118,13 +118,13 @@ discard block |
||
| 118 | 118 | $types = wpinv_get_discount_types(); |
| 119 | 119 | |
| 120 | 120 | foreach ( $types as $name => $type ) { |
| 121 | - echo '<option value="' . esc_attr( $name ) . '"'; |
|
| 121 | + echo '<option value="' . esc_attr( $name ) . '"'; |
|
| 122 | 122 | |
| 123 | - if ( isset( $_GET['discount_type'] ) ) { |
|
| 124 | - selected( $name, sanitize_text_field( $_GET['discount_type'] ) ); |
|
| 123 | + if ( isset( $_GET['discount_type'] ) ) { |
|
| 124 | + selected( $name, sanitize_text_field( $_GET['discount_type'] ) ); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
| 127 | + echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
| 128 | 128 | } |
| 129 | 129 | ?> |
| 130 | 130 | </select> |
@@ -151,15 +151,15 @@ discard block |
||
| 151 | 151 | // Filter vat rule type |
| 152 | 152 | if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) { |
| 153 | 153 | $meta_query[] = array( |
| 154 | - 'key' => '_wpi_discount_type', |
|
| 155 | - 'value' => sanitize_key( urldecode( $_GET['discount_type'] ) ), |
|
| 156 | - 'compare' => '=', |
|
| 157 | - ); |
|
| 158 | - } |
|
| 154 | + 'key' => '_wpi_discount_type', |
|
| 155 | + 'value' => sanitize_key( urldecode( $_GET['discount_type'] ) ), |
|
| 156 | + 'compare' => '=', |
|
| 157 | + ); |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | 160 | if ( ! empty( $meta_query ) ) { |
| 161 | 161 | $vars['meta_query'] = $meta_query; |
| 162 | - } |
|
| 162 | + } |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | return $vars; |
@@ -24,14 +24,14 @@ discard block |
||
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | - * Highlights sub menus. |
|
| 28 | - */ |
|
| 29 | - public function set_admin_menu_class() { |
|
| 30 | - global $current_screen, $parent_file, $submenu_file; |
|
| 27 | + * Highlights sub menus. |
|
| 28 | + */ |
|
| 29 | + public function set_admin_menu_class() { |
|
| 30 | + global $current_screen, $parent_file, $submenu_file; |
|
| 31 | 31 | |
| 32 | 32 | if ( ! empty( $current_screen->id ) && in_array( $current_screen->id, array( 'wpi_discount', 'wpi_payment_form', 'wpi_invoice' ) ) ) { |
| 33 | - $parent_file = 'wpinv'; |
|
| 34 | - $submenu_file = 'edit.php?post_type=' . $current_screen->id; |
|
| 33 | + $parent_file = 'wpinv'; |
|
| 34 | + $submenu_file = 'edit.php?post_type=' . $current_screen->id; |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | } |
@@ -165,8 +165,8 @@ discard block |
||
| 165 | 165 | foreach ( wpinv_get_settings_tabs() as $tab_id => $tab_name ) { |
| 166 | 166 | $tab_url = add_query_arg( |
| 167 | 167 | array( |
| 168 | - 'settings-updated' => false, |
|
| 169 | - 'tab' => $tab_id, |
|
| 168 | + 'settings-updated' => false, |
|
| 169 | + 'tab' => $tab_id, |
|
| 170 | 170 | ), |
| 171 | 171 | 'admin.php?page=wpinv-settings' |
| 172 | 172 | ); |
@@ -193,9 +193,9 @@ discard block |
||
| 193 | 193 | $number++; |
| 194 | 194 | $tab_url = add_query_arg( |
| 195 | 195 | array( |
| 196 | - 'settings-updated' => false, |
|
| 197 | - 'tab' => $active_tab, |
|
| 198 | - 'section' => $section_id, |
|
| 196 | + 'settings-updated' => false, |
|
| 197 | + 'tab' => $active_tab, |
|
| 198 | + 'section' => $section_id, |
|
| 199 | 199 | ), |
| 200 | 200 | admin_url( 'admin.php?page=wpinv-settings' ) |
| 201 | 201 | ); |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * |
| 7 | 7 | */ |
| 8 | 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | - exit; |
|
| 9 | + exit; |
|
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 12 | /** |
@@ -15,92 +15,92 @@ discard block |
||
| 15 | 15 | class WPInv_Admin_Addons extends Ayecode_Addons { |
| 16 | 16 | |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Get the extensions page tabs. |
|
| 20 | - * |
|
| 21 | - * @return array of tabs. |
|
| 22 | - */ |
|
| 23 | - public function get_tabs() { |
|
| 24 | - $tabs = array( |
|
| 25 | - 'addons' => __( 'Addons', 'invoicing' ), |
|
| 18 | + /** |
|
| 19 | + * Get the extensions page tabs. |
|
| 20 | + * |
|
| 21 | + * @return array of tabs. |
|
| 22 | + */ |
|
| 23 | + public function get_tabs() { |
|
| 24 | + $tabs = array( |
|
| 25 | + 'addons' => __( 'Addons', 'invoicing' ), |
|
| 26 | 26 | 'gateways' => __( 'Payment Gateways', 'invoicing' ), |
| 27 | 27 | 'recommended_plugins' => __( 'Recommended plugins', 'invoicing' ), |
| 28 | 28 | 'membership' => __( 'Membership', 'invoicing' ), |
| 29 | - ); |
|
| 30 | - |
|
| 31 | - return $tabs; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Get section content for the addons screen. |
|
| 36 | - * |
|
| 37 | - * @param string $section_id |
|
| 38 | - * |
|
| 39 | - * @return array |
|
| 40 | - */ |
|
| 41 | - public function get_section_data( $section_id ) { |
|
| 42 | - $section = self::get_tab( $section_id ); |
|
| 43 | - $api_url = 'https://wpinvoicing.com/edd-api/v2/products/'; |
|
| 44 | - $section_data = new stdClass(); |
|
| 45 | - |
|
| 46 | - if ( $section_id == 'recommended_plugins' ) { |
|
| 47 | - $section_data->products = self::get_recommend_wp_plugins_edd_formatted(); |
|
| 48 | - } elseif ( ! empty( $section ) ) { |
|
| 49 | - if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing |
|
| 50 | - //if ( 1==1) { |
|
| 51 | - |
|
| 52 | - $query_args = array( |
|
| 53 | - 'category' => $section_id, |
|
| 54 | - 'number' => 100, |
|
| 55 | - ); |
|
| 56 | - $query_args = apply_filters( 'wpeu_edd_api_query_args', $query_args, $api_url, $section_id ); |
|
| 57 | - |
|
| 58 | - $raw_section = wp_safe_remote_get( |
|
| 29 | + ); |
|
| 30 | + |
|
| 31 | + return $tabs; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Get section content for the addons screen. |
|
| 36 | + * |
|
| 37 | + * @param string $section_id |
|
| 38 | + * |
|
| 39 | + * @return array |
|
| 40 | + */ |
|
| 41 | + public function get_section_data( $section_id ) { |
|
| 42 | + $section = self::get_tab( $section_id ); |
|
| 43 | + $api_url = 'https://wpinvoicing.com/edd-api/v2/products/'; |
|
| 44 | + $section_data = new stdClass(); |
|
| 45 | + |
|
| 46 | + if ( $section_id == 'recommended_plugins' ) { |
|
| 47 | + $section_data->products = self::get_recommend_wp_plugins_edd_formatted(); |
|
| 48 | + } elseif ( ! empty( $section ) ) { |
|
| 49 | + if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing |
|
| 50 | + //if ( 1==1) { |
|
| 51 | + |
|
| 52 | + $query_args = array( |
|
| 53 | + 'category' => $section_id, |
|
| 54 | + 'number' => 100, |
|
| 55 | + ); |
|
| 56 | + $query_args = apply_filters( 'wpeu_edd_api_query_args', $query_args, $api_url, $section_id ); |
|
| 57 | + |
|
| 58 | + $raw_section = wp_safe_remote_get( |
|
| 59 | 59 | esc_url_raw( add_query_arg( $query_args, $api_url ) ), |
| 60 | 60 | array( |
| 61 | - 'user-agent' => 'Invoicing Addons Page', |
|
| 62 | - 'timeout' => 15, |
|
| 61 | + 'user-agent' => 'Invoicing Addons Page', |
|
| 62 | + 'timeout' => 15, |
|
| 63 | 63 | ) |
| 64 | 64 | ); |
| 65 | 65 | |
| 66 | - if ( ! is_wp_error( $raw_section ) ) { |
|
| 67 | - $section_data = json_decode( wp_remote_retrieve_body( $raw_section ) ); |
|
| 66 | + if ( ! is_wp_error( $raw_section ) ) { |
|
| 67 | + $section_data = json_decode( wp_remote_retrieve_body( $raw_section ) ); |
|
| 68 | 68 | |
| 69 | - if ( ! empty( $section_data->products ) ) { |
|
| 70 | - set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS ); |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - } |
|
| 69 | + if ( ! empty( $section_data->products ) ) { |
|
| 70 | + set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS ); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - $products = isset( $section_data->products ) ? $section_data->products : array(); |
|
| 77 | - if ( 'addons' == $section_id ) { |
|
| 78 | - |
|
| 79 | - $quotes = new stdClass(); |
|
| 80 | - $quotes->info = new stdClass(); |
|
| 81 | - $quotes->info->id = ''; |
|
| 82 | - $quotes->info->slug = 'invoicing-quotes'; |
|
| 83 | - $quotes->info->title = __( 'Quotes', 'invoicing' ); |
|
| 84 | - $quotes->info->excerpt = __( 'Create quotes and estimates', 'invoicing' ); |
|
| 85 | - $quotes->info->link = 'https://wordpress.org/plugins/invoicing-quotes/'; |
|
| 86 | - $quotes->info->thumbnail = WPINV_PLUGIN_URL . 'assets/images/Quotes-1-768x384.png'; |
|
| 87 | - |
|
| 88 | - $products[] = $quotes; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - return apply_filters( 'wpi_addons_section_data', $products, $section_id ); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Outputs a button. |
|
| 96 | - *ccc |
|
| 97 | - * @param string $url |
|
| 98 | - * @param string $text |
|
| 99 | - * @param string $theme |
|
| 100 | - * @param string $plugin |
|
| 101 | - */ |
|
| 102 | - public function output_button( $addon ) { |
|
| 103 | - $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
| 76 | + $products = isset( $section_data->products ) ? $section_data->products : array(); |
|
| 77 | + if ( 'addons' == $section_id ) { |
|
| 78 | + |
|
| 79 | + $quotes = new stdClass(); |
|
| 80 | + $quotes->info = new stdClass(); |
|
| 81 | + $quotes->info->id = ''; |
|
| 82 | + $quotes->info->slug = 'invoicing-quotes'; |
|
| 83 | + $quotes->info->title = __( 'Quotes', 'invoicing' ); |
|
| 84 | + $quotes->info->excerpt = __( 'Create quotes and estimates', 'invoicing' ); |
|
| 85 | + $quotes->info->link = 'https://wordpress.org/plugins/invoicing-quotes/'; |
|
| 86 | + $quotes->info->thumbnail = WPINV_PLUGIN_URL . 'assets/images/Quotes-1-768x384.png'; |
|
| 87 | + |
|
| 88 | + $products[] = $quotes; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + return apply_filters( 'wpi_addons_section_data', $products, $section_id ); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Outputs a button. |
|
| 96 | + *ccc |
|
| 97 | + * @param string $url |
|
| 98 | + * @param string $text |
|
| 99 | + * @param string $theme |
|
| 100 | + * @param string $plugin |
|
| 101 | + */ |
|
| 102 | + public function output_button( $addon ) { |
|
| 103 | + $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
| 104 | 104 | // $button_text = __('Free','invoicing'); |
| 105 | 105 | // $licensing = false; |
| 106 | 106 | // $installed = false; |
@@ -112,128 +112,128 @@ discard block |
||
| 112 | 112 | // $install_status = 'get'; |
| 113 | 113 | // $onclick = ''; |
| 114 | 114 | |
| 115 | - $wp_org_themes = array( 'supreme-directory', 'directory-starter' ); |
|
| 116 | - |
|
| 117 | - $button_args = array( |
|
| 118 | - 'type' => ($current_tab == 'addons' || $current_tab == 'gateways') ? 'addons' : $current_tab, |
|
| 119 | - 'id' => isset( $addon->info->id ) ? absint( $addon->info->id ) : '', |
|
| 120 | - 'title' => isset( $addon->info->title ) ? $addon->info->title : '', |
|
| 121 | - 'button_text' => __( 'Free', 'invoicing' ), |
|
| 122 | - 'price_text' => __( 'Free', 'invoicing' ), |
|
| 123 | - 'link' => isset( $addon->info->link ) ? $addon->info->link : '', // link to product |
|
| 124 | - 'url' => isset( $addon->info->link ) ? $addon->info->link : '', // button url |
|
| 125 | - 'class' => 'button-primary', |
|
| 126 | - 'install_status' => 'get', |
|
| 127 | - 'installed' => false, |
|
| 128 | - 'price' => '', |
|
| 129 | - 'licensing' => isset( $addon->licensing->enabled ) && $addon->licensing->enabled ? true : false, |
|
| 130 | - 'license' => isset( $addon->licensing->license ) && $addon->licensing->license ? $addon->licensing->license : '', |
|
| 131 | - 'onclick' => '', |
|
| 132 | - 'slug' => isset( $addon->info->slug ) ? $addon->info->slug : '', |
|
| 133 | - 'active' => false, |
|
| 134 | - 'file' => '', |
|
| 135 | - 'update_url' => '', |
|
| 136 | - ); |
|
| 137 | - |
|
| 138 | - if ( 'invoicing-quotes' == $addon->info->slug || 'getpaid-stripe-payments' == $addon->info->slug || ( $current_tab == 'recommended_plugins' && isset( $addon->info->slug ) && $addon->info->slug ) ) { |
|
| 139 | - include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api.. |
|
| 140 | - $status = install_plugin_install_status( |
|
| 115 | + $wp_org_themes = array( 'supreme-directory', 'directory-starter' ); |
|
| 116 | + |
|
| 117 | + $button_args = array( |
|
| 118 | + 'type' => ($current_tab == 'addons' || $current_tab == 'gateways') ? 'addons' : $current_tab, |
|
| 119 | + 'id' => isset( $addon->info->id ) ? absint( $addon->info->id ) : '', |
|
| 120 | + 'title' => isset( $addon->info->title ) ? $addon->info->title : '', |
|
| 121 | + 'button_text' => __( 'Free', 'invoicing' ), |
|
| 122 | + 'price_text' => __( 'Free', 'invoicing' ), |
|
| 123 | + 'link' => isset( $addon->info->link ) ? $addon->info->link : '', // link to product |
|
| 124 | + 'url' => isset( $addon->info->link ) ? $addon->info->link : '', // button url |
|
| 125 | + 'class' => 'button-primary', |
|
| 126 | + 'install_status' => 'get', |
|
| 127 | + 'installed' => false, |
|
| 128 | + 'price' => '', |
|
| 129 | + 'licensing' => isset( $addon->licensing->enabled ) && $addon->licensing->enabled ? true : false, |
|
| 130 | + 'license' => isset( $addon->licensing->license ) && $addon->licensing->license ? $addon->licensing->license : '', |
|
| 131 | + 'onclick' => '', |
|
| 132 | + 'slug' => isset( $addon->info->slug ) ? $addon->info->slug : '', |
|
| 133 | + 'active' => false, |
|
| 134 | + 'file' => '', |
|
| 135 | + 'update_url' => '', |
|
| 136 | + ); |
|
| 137 | + |
|
| 138 | + if ( 'invoicing-quotes' == $addon->info->slug || 'getpaid-stripe-payments' == $addon->info->slug || ( $current_tab == 'recommended_plugins' && isset( $addon->info->slug ) && $addon->info->slug ) ) { |
|
| 139 | + include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api.. |
|
| 140 | + $status = install_plugin_install_status( |
|
| 141 | 141 | array( |
| 142 | - 'slug' => $button_args['slug'], |
|
| 143 | - 'version' => '', |
|
| 142 | + 'slug' => $button_args['slug'], |
|
| 143 | + 'version' => '', |
|
| 144 | 144 | ) |
| 145 | 145 | ); |
| 146 | - $button_args['install_status'] = isset( $status['status'] ) ? $status['status'] : 'install'; |
|
| 147 | - $button_args['file'] = isset( $status['file'] ) ? $status['file'] : ''; |
|
| 148 | - } elseif ( ($current_tab == 'addons' || $current_tab == 'gateways') && isset( $addon->info->id ) && $addon->info->id ) { |
|
| 149 | - include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api.. |
|
| 150 | - if ( ! empty( $addon->licensing->edd_slug ) ) { |
|
| 146 | + $button_args['install_status'] = isset( $status['status'] ) ? $status['status'] : 'install'; |
|
| 147 | + $button_args['file'] = isset( $status['file'] ) ? $status['file'] : ''; |
|
| 148 | + } elseif ( ($current_tab == 'addons' || $current_tab == 'gateways') && isset( $addon->info->id ) && $addon->info->id ) { |
|
| 149 | + include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; //for plugins_api.. |
|
| 150 | + if ( ! empty( $addon->licensing->edd_slug ) ) { |
|
| 151 | 151 | $button_args['slug'] = $addon->licensing->edd_slug;} |
| 152 | - $status = self::install_plugin_install_status( $addon ); |
|
| 153 | - $button_args['file'] = isset( $status['file'] ) ? $status['file'] : ''; |
|
| 154 | - if ( isset( $status['status'] ) ) { |
|
| 152 | + $status = self::install_plugin_install_status( $addon ); |
|
| 153 | + $button_args['file'] = isset( $status['file'] ) ? $status['file'] : ''; |
|
| 154 | + if ( isset( $status['status'] ) ) { |
|
| 155 | 155 | $button_args['install_status'] = $status['status'];} |
| 156 | - $button_args['update_url'] = 'https://wpinvoicing.com'; |
|
| 157 | - } elseif ( $current_tab == 'themes' && isset( $addon->info->id ) && $addon->info->id ) { |
|
| 158 | - if ( ! empty( $addon->licensing->edd_slug ) ) { |
|
| 156 | + $button_args['update_url'] = 'https://wpinvoicing.com'; |
|
| 157 | + } elseif ( $current_tab == 'themes' && isset( $addon->info->id ) && $addon->info->id ) { |
|
| 158 | + if ( ! empty( $addon->licensing->edd_slug ) ) { |
|
| 159 | 159 | $button_args['slug'] = $addon->licensing->edd_slug;} |
| 160 | - $button_args['installed'] = self::is_theme_installed( $addon ); |
|
| 161 | - if ( ! in_array( $button_args['slug'], $wp_org_themes ) ) { |
|
| 162 | - $button_args['update_url'] = 'https://wpinvoicing.com'; |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - // set price |
|
| 167 | - if ( isset( $addon->pricing ) && ! empty( $addon->pricing ) ) { |
|
| 168 | - if ( is_object( $addon->pricing ) ) { |
|
| 169 | - $prices = (array)$addon->pricing; |
|
| 170 | - $button_args['price'] = reset( $prices ); |
|
| 171 | - } elseif ( isset( $addon->pricing ) ) { |
|
| 172 | - $button_args['price'] = $addon->pricing; |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - // set price text |
|
| 177 | - if ( $button_args['price'] && $button_args['price'] != '0.00' ) { |
|
| 178 | - $button_args['price_text'] = sprintf( __( 'From: $%d', 'invoicing' ), $button_args['price'] ); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // set if installed |
|
| 182 | - if ( in_array( $button_args['install_status'], array( 'installed', 'latest_installed', 'update_available', 'newer_installed' ) ) ) { |
|
| 183 | - $button_args['installed'] = true; |
|
| 184 | - } |
|
| 160 | + $button_args['installed'] = self::is_theme_installed( $addon ); |
|
| 161 | + if ( ! in_array( $button_args['slug'], $wp_org_themes ) ) { |
|
| 162 | + $button_args['update_url'] = 'https://wpinvoicing.com'; |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + // set price |
|
| 167 | + if ( isset( $addon->pricing ) && ! empty( $addon->pricing ) ) { |
|
| 168 | + if ( is_object( $addon->pricing ) ) { |
|
| 169 | + $prices = (array)$addon->pricing; |
|
| 170 | + $button_args['price'] = reset( $prices ); |
|
| 171 | + } elseif ( isset( $addon->pricing ) ) { |
|
| 172 | + $button_args['price'] = $addon->pricing; |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + // set price text |
|
| 177 | + if ( $button_args['price'] && $button_args['price'] != '0.00' ) { |
|
| 178 | + $button_args['price_text'] = sprintf( __( 'From: $%d', 'invoicing' ), $button_args['price'] ); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // set if installed |
|
| 182 | + if ( in_array( $button_args['install_status'], array( 'installed', 'latest_installed', 'update_available', 'newer_installed' ) ) ) { |
|
| 183 | + $button_args['installed'] = true; |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | 186 | // print_r($button_args); |
| 187 | - // set if active |
|
| 188 | - if ( $button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes') ) { |
|
| 189 | - if ( $button_args['type'] != 'themes' ) { |
|
| 190 | - $button_args['active'] = is_plugin_active( $button_args['file'] ); |
|
| 191 | - } else { |
|
| 192 | - $button_args['active'] = self::is_theme_active( $addon ); |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - // set button text and class |
|
| 197 | - if ( $button_args['active'] ) { |
|
| 198 | - $button_args['button_text'] = __( 'Active', 'invoicing' ); |
|
| 199 | - $button_args['class'] = ' button-secondary disabled '; |
|
| 200 | - } elseif ( $button_args['installed'] ) { |
|
| 201 | - $button_args['button_text'] = __( 'Activate', 'invoicing' ); |
|
| 202 | - |
|
| 203 | - if ( $button_args['type'] != 'themes' ) { |
|
| 204 | - if ( current_user_can( 'manage_options' ) ) { |
|
| 205 | - $button_args['url'] = wp_nonce_url( admin_url( 'plugins.php?action=activate&plugin=' . $button_args['file'] ), 'activate-plugin_' . $button_args['file'] ); |
|
| 206 | - } else { |
|
| 207 | - $button_args['url'] = '#'; |
|
| 208 | - } |
|
| 209 | - } else { |
|
| 210 | - if ( current_user_can( 'switch_themes' ) ) { |
|
| 211 | - $button_args['url'] = self::get_theme_activation_url( $addon ); |
|
| 212 | - } else { |
|
| 213 | - $button_args['url'] = '#'; |
|
| 214 | - } |
|
| 215 | - } |
|
| 187 | + // set if active |
|
| 188 | + if ( $button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes') ) { |
|
| 189 | + if ( $button_args['type'] != 'themes' ) { |
|
| 190 | + $button_args['active'] = is_plugin_active( $button_args['file'] ); |
|
| 191 | + } else { |
|
| 192 | + $button_args['active'] = self::is_theme_active( $addon ); |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + // set button text and class |
|
| 197 | + if ( $button_args['active'] ) { |
|
| 198 | + $button_args['button_text'] = __( 'Active', 'invoicing' ); |
|
| 199 | + $button_args['class'] = ' button-secondary disabled '; |
|
| 200 | + } elseif ( $button_args['installed'] ) { |
|
| 201 | + $button_args['button_text'] = __( 'Activate', 'invoicing' ); |
|
| 202 | + |
|
| 203 | + if ( $button_args['type'] != 'themes' ) { |
|
| 204 | + if ( current_user_can( 'manage_options' ) ) { |
|
| 205 | + $button_args['url'] = wp_nonce_url( admin_url( 'plugins.php?action=activate&plugin=' . $button_args['file'] ), 'activate-plugin_' . $button_args['file'] ); |
|
| 206 | + } else { |
|
| 207 | + $button_args['url'] = '#'; |
|
| 208 | + } |
|
| 209 | + } else { |
|
| 210 | + if ( current_user_can( 'switch_themes' ) ) { |
|
| 211 | + $button_args['url'] = self::get_theme_activation_url( $addon ); |
|
| 212 | + } else { |
|
| 213 | + $button_args['url'] = '#'; |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | 216 | } else { |
| 217 | - if ( $button_args['type'] == 'recommended_plugins' ) { |
|
| 218 | - $button_args['button_text'] = __( 'Install', 'invoicing' ); |
|
| 219 | - } else { |
|
| 220 | - $button_args['button_text'] = __( 'Get it', 'invoicing' ); |
|
| 217 | + if ( $button_args['type'] == 'recommended_plugins' ) { |
|
| 218 | + $button_args['button_text'] = __( 'Install', 'invoicing' ); |
|
| 219 | + } else { |
|
| 220 | + $button_args['button_text'] = __( 'Get it', 'invoicing' ); |
|
| 221 | 221 | |
| 222 | - /*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){ |
|
| 222 | + /*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){ |
|
| 223 | 223 | $button_args['button_text'] = __('Install','invoicing'); |
| 224 | 224 | $button_args['url'] = self::get_theme_install_url($button_args['slug']); |
| 225 | 225 | $button_args['onclick'] = 'gd_set_button_installing(this);'; |
| 226 | 226 | }*/ |
| 227 | 227 | |
| 228 | - } |
|
| 229 | - } |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - // filter the button arguments |
|
| 232 | - $button_args = apply_filters( 'edd_api_button_args', $button_args ); |
|
| 231 | + // filter the button arguments |
|
| 232 | + $button_args = apply_filters( 'edd_api_button_args', $button_args ); |
|
| 233 | 233 | // print_r($button_args); |
| 234 | - // set price text |
|
| 235 | - if ( isset( $button_args['price_text'] ) ) { |
|
| 236 | - ?> |
|
| 234 | + // set price text |
|
| 235 | + if ( isset( $button_args['price_text'] ) ) { |
|
| 236 | + ?> |
|
| 237 | 237 | <a |
| 238 | 238 | target="_blank" |
| 239 | 239 | class="addons-price-text" |
@@ -241,9 +241,9 @@ discard block |
||
| 241 | 241 | <?php echo esc_html( $button_args['price_text'] ); ?> |
| 242 | 242 | </a> |
| 243 | 243 | <?php |
| 244 | - } |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - ?> |
|
| 246 | + ?> |
|
| 247 | 247 | <a |
| 248 | 248 | data-licence="<?php echo esc_attr( $button_args['license'] ); ?>" |
| 249 | 249 | data-licensing="<?php echo $button_args['licensing'] ? 1 : 0; ?>" |
@@ -267,33 +267,33 @@ discard block |
||
| 267 | 267 | </a> |
| 268 | 268 | <?php |
| 269 | 269 | |
| 270 | - } |
|
| 271 | - |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * Handles output of the addons page in admin. |
|
| 275 | - */ |
|
| 276 | - public function output() { |
|
| 277 | - $tabs = self::get_tabs(); |
|
| 278 | - $sections = self::get_sections(); |
|
| 279 | - $theme = wp_get_theme(); |
|
| 280 | - $section_keys = array_keys( $sections ); |
|
| 281 | - $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys ); |
|
| 282 | - $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
| 283 | - include_once WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php'; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * A list of recommended wp.org plugins. |
|
| 288 | - * @return array |
|
| 289 | - */ |
|
| 290 | - public function get_recommend_wp_plugins() { |
|
| 291 | - $plugins = array( |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * Handles output of the addons page in admin. |
|
| 275 | + */ |
|
| 276 | + public function output() { |
|
| 277 | + $tabs = self::get_tabs(); |
|
| 278 | + $sections = self::get_sections(); |
|
| 279 | + $theme = wp_get_theme(); |
|
| 280 | + $section_keys = array_keys( $sections ); |
|
| 281 | + $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys ); |
|
| 282 | + $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
| 283 | + include_once WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php'; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * A list of recommended wp.org plugins. |
|
| 288 | + * @return array |
|
| 289 | + */ |
|
| 290 | + public function get_recommend_wp_plugins() { |
|
| 291 | + $plugins = array( |
|
| 292 | 292 | 'invoicing-quotes' => array( |
| 293 | 293 | 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
| 294 | 294 | 'slug' => 'invoicing-quotes', |
| 295 | - 'name' => 'Quotes', |
|
| 296 | - 'thumbnail' => 'https://ps.w.org/invoicing-quotes/assets/banner-772x250.png', |
|
| 295 | + 'name' => 'Quotes', |
|
| 296 | + 'thumbnail' => 'https://ps.w.org/invoicing-quotes/assets/banner-772x250.png', |
|
| 297 | 297 | 'desc' => __( 'Allows you to create quotes, send them to clients and convert them to Invoices when accepted by the customer.', 'invoicing' ), |
| 298 | 298 | ), |
| 299 | 299 | 'geodirectory' => array( |
@@ -308,8 +308,8 @@ discard block |
||
| 308 | 308 | 'name' => 'UsersWP', |
| 309 | 309 | 'desc' => __( 'Allow frontend user login and registration as well as have slick profile pages.', 'invoicing' ), |
| 310 | 310 | ), |
| 311 | - ); |
|
| 311 | + ); |
|
| 312 | 312 | |
| 313 | - return $plugins; |
|
| 314 | - } |
|
| 313 | + return $plugins; |
|
| 314 | + } |
|
| 315 | 315 | } |