golden hour
/home/godaofbq/hyperbaric-revolution.com/wp-content/plugins/discountify/core/admin/settings
⬆️ Go Up
Upload
File/Folder
Size
Actions
.htaccess
237 B
Del
OK
form.php
1.26 KB
Del
OK
settings-fields.php
9.28 KB
Del
OK
settings.php
4.19 KB
Del
OK
tab-content
-
Del
OK
table.php
7.68 KB
Del
OK
Edit: table.php
<?php namespace Discountify\Core\Admin\Settings; defined('ABSPATH') || exit; use Discountify\Utils\Helper; if ( ! class_exists( 'WP_List_Table' )){ require_once ABSPATH . 'wp-admin/inclueds/class-wp-list-table.php'; } class Table extends \WP_List_Table{ public $singular_name; public $plural_name; public $id = ''; public $columns = []; /** * Show list */ function __construct($all_data_of_table){ $this->singular_name = $all_data_of_table['singular_name']; $this->plural_name = $all_data_of_table['plural_name']; $this->columns = $all_data_of_table['columns']; parent::__construct( [ 'singular' => $this->singular_name , 'plural' => $this->plural_name , 'ajax' => true ]); } protected function column_discount_name( $item ) { $_wpnonce = esc_attr( wp_create_nonce( 'delete-rules-nonce' ) ); $actions = array( 'delete' => sprintf( '<a href="?page=%s&action=%s&id=%s&_wpnonce=%s" aria-label="%s" role="button">%s</a>', 'discountify-rules', 'delete', $item['ID'], $_wpnonce, __( 'Delete', 'discountify' ), __( 'Delete', 'discountify' ) ), 'edit' => sprintf( '<a href="?page=%s&rule=%s&id=%s" aria-label="%s" role="button">%s</a>', 'discountify-rules', 'update-rule', $item['ID'], __( 'Edit', 'discountify' ), __( 'Edit', 'discountify' ) ), ); return $item['discount_name'] . $this->row_actions( $actions ); } /** * Get column header function */ public function get_columns(){ return $this->columns; } public function extra_tablenav($which){ $rules = Helper::instance()->rules_type(true); $submit = array( 'id' => 'filter-by-rules' ); ?> <div class="alignleft actions bulkactions"> <input type="hidden" name="discount_rules" class="discount_rules" value=""/> <select name="rules_type" class="filter_rules_type"> <?php if ( count($rules)> 0 ) { $discount_rules = !empty($_POST['discount_rules']) ? $_POST['discount_rules'] : ''; ?> <option value=""><?php esc_html_e('Select Discount Rules','discountify')?></option> <?php foreach ($rules as $key => $value) { $selected = $discount_rules == $key ? 'selected' : ''; ?> <option <?php echo esc_attr($selected);?> value="<?php echo esc_html($key);?>"><?php echo esc_html($value);?></option> <?php } } else { ?><option value=""><?php esc_html_e('No rules found','discountify')?></option><?php } ?> </select> </div> <?php submit_button( esc_html__( 'Filter By Rules','discountify' ), '', 'filter-by-rules', false, $submit ); } /** * Render the bulk edit checkbox * * @param array $item * * @return string */ function column_cb( $item ) { return sprintf( '<input type="checkbox" name="bulk-delete[]" value="%1$s" />', $item['ID'] ); } /** * Delete data */ public function process_bulk_action() { $action = $this->current_action(); if ( 'delete' === $action && isset( $_GET['_wpnonce'] ) && ! empty( $_GET['_wpnonce'] ) ) { $nonce = filter_input( INPUT_GET, '_wpnonce', FILTER_SANITIZE_SPECIAL_CHARS ); if ( ! wp_verify_nonce( $nonce, 'delete-rules-nonce' ) ) { wp_die( __( 'Security check failed!', 'discountify' ) ); } $id = $_GET['id']; wp_delete_post( $id, true ); } if( 'trash'===$action ) { $delete_ids = esc_sql( $_POST['bulk-delete'] ); foreach ( $delete_ids as $did ) { wp_delete_post ($did, true); } wp_redirect( esc_url( add_query_arg() ) ); exit; } } /** * Get Bulk options */ public function get_bulk_actions() { $actions = array(); $actions['trash'] = esc_html__( 'Move to Trash','discountify' ); return $actions; } /** * Sortable column function */ public function get_sortable_columns() { unset($this->columns['cb']); unset($this->columns['enable_rules']); return $this->columns; } /** * Display all row function */ protected function column_default( $item , $column_name ){ switch( $column_name ) { case 'discount_in': $discount_name = ''; if ( $item[$column_name] == 'product' && !empty($item['filter_by_products']) ) { $discount_name = '<strong>'.esc_html__( 'Products:','discountify' ).'</strong>'.' '.$this->get_discount_in( $item['filter_by_products'] ); } else if ( $item[$column_name] == 'category' && !empty($item['filter_by_category'])) { $discount_name = '<strong>'.esc_html__( 'Categories:','discountify' ).'</strong>'.' '.$this->get_discount_in( $item['filter_by_category'] , 'category' ); } return $discount_name; case "enable_rules": $class = $item[$column_name] == 'yes' ? 'success' : 'error'; $rules = $item[$column_name] == 'yes' ? esc_html__('Enable','discountify') : esc_html__('Disable','discountify'); return '<span class="status '.esc_attr($class).'">'. $rules .'</span>'; case "created_date": return date_i18n(get_the_date( get_option( 'date_format' ) , $item['ID'])); case $column_name: return $item[$column_name]; default: isset( $item[$column_name] ) ? $item[$column_name] : ''; break; } } private function get_discount_in( $item , $type = 'product' ){ $name = array(); foreach ($item as $key => $value) { if ( $type == 'product' ) { $name[] = get_the_title($value); } else { $term = get_term_by( 'id', $value, 'product_cat', 'ARRAY_A' ); $name[] = !empty($term['name']) ? $term['name'] : ''; } } return implode(', ', $name); } /** * Main query and show function */ public function preparing_items(){ $per_page = 20; $column = $this->get_columns(); $hidden = array(); $meta_data = array(); $sortable = $this->get_sortable_columns(); $this->_column_headers = [ $column , $hidden , $sortable ]; $current_page = $this->get_pagenum(); $offset = ( $current_page - 1) * $per_page; $this->process_bulk_action(); if ( isset( $_REQUEST['orderby']) && isset( $_REQUEST['order']) ) { $args['orderby'] = sanitize_key($_REQUEST['orderby']); $args['order'] = sanitize_key($_REQUEST['order']); } $args['limit'] = $per_page; $args['offset'] = $offset; if ( !empty( $_POST['discount_rules'] ) ) { $meta_data = array(array( 'key' => 'rules_type', 'value' => $_POST['discount_rules'], 'compare' => '=' )); } $get_data = Helper::get_all_rules( $args['limit'] , $meta_data ); $this->set_pagination_args( [ 'total_items' => count( (array) Helper::get_all_rules()), 'per_page' => $per_page, ] ); $this->items = $get_data; } }
Save