Plugin Directory

Changeset 3277147


Ignore:
Timestamp:
04/19/2025 10:53:43 AM (10 months ago)
Author:
quyle91
Message:

Adminz new release date 19/04/2025 17:53:36,17

Location:
administrator-z/trunk
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • administrator-z/trunk/administrator-z.php

    r3273833 r3277147  
    77 * Author: quyle91
    88 * Author URI: http://quyle91.github.io
    9  * Version: 2025.04.16
     9 * Version: 2025.04.19
    1010 * License: GPL2
    1111 * Text Domain: administrator-z
     
    4141
    4242define('ADMINZ', true);
    43 define('ADMINZ_VERSION', '2025.04.16');
     43define('ADMINZ_VERSION', '2025.04.19');
    4444define('ADMINZ_DATA_VERSION', 1);
    4545define('ADMINZ_FILE', __FILE__);
  • administrator-z/trunk/assets/js/adminz.js

    r3267405 r3277147  
    672672        toggle_setup = (element) => {
    673673            element.onclick = () => {
     674                console.log(element);
    674675                // single structure
    675676                const target = element.getAttribute('data-target');
  • administrator-z/trunk/includes/shortcodes/flatsome-slider.php

    r3251526 r3277147  
    464464
    465465            #<?php echo esc_attr( $_id ); ?> .slider img{
    466                 width: unset;
     466                width: 100%;
    467467            }
    468468
  • administrator-z/trunk/src/Controller/AdministratorZ.php

    r3271332 r3277147  
    6161            function () {
    6262                $list = [
     63                    'Page - Preload images',
    6364                    'Flatsome - Active on anchor link',
    6465                    'Woocommerce - Checkout field validate',
     
    7172                    'Wordpress menu toggle button',
    7273                    'Flatsome element: ACF',
    73                     'Tools/ Request logs',
    74                     'Tools/ Email logs - move from mailer',
    75                     'Wpcf7/ Thankyou',
    76                     'Tools/ Server tools',
    77                     'Wordpress/ Login footer text',
    78                     'Flatsome/ Slider auto free scroll',
    79                     'Wordpress/ Quiz login',
    8074                ];
    8175
  • administrator-z/trunk/src/Controller/Flatsome.php

    r3273833 r3277147  
    493493                    'is-smaller',
    494494                    'is-xsmall',
    495                     'is-xxsmall'
     495                    'is-xxsmall',
     496                    'heading-font'
    496497                ];
    497498
  • administrator-z/trunk/src/Controller/Wordpress.php

    r3271332 r3277147  
    174174        if ($this->settings['add_toggle_button'] ?? "") {
    175175            adminz_add_admin_body_class('adminz_menus_toggle_button');
     176        }
     177
     178        //
     179        if (($this->settings['enable_preload_images'] ?? "") == 'on') {
     180            $a = new \Adminz\Helper\Page();
     181            $a->setup_preload_img();
    176182        }
    177183
     
    677683        );
    678684
     685        // add section
     686        add_settings_section(
     687            'adminz_pages',
     688            'Pages',
     689            function () {
     690                //
     691            },
     692            $this->id
     693        );
     694
     695        // field
     696        add_settings_field(
     697            wp_rand(),
     698            'Preload images',
     699            function () {
     700                // field
     701                echo adminz_field([
     702                    'field'     => 'input',
     703                    'attribute' => [
     704                        'type' => 'checkbox',
     705                        'name' => $this->option_name . '[enable_preload_images]',
     706                    ],
     707                    'value'     => $this->settings['enable_preload_images'] ?? "",
     708                ]);
     709            },
     710            $this->id,
     711            'adminz_pages'
     712        );
     713
    679714
    680715        // add section
     
    765800        );
    766801
    767 
    768 
    769802        // add section
    770803        add_settings_section(
    771804            'adminz_posttype',
    772             'Post types admin',
     805            'Post types admin column',
    773806            function () {
    774807            },
     
    862895        add_settings_section(
    863896            'adminz_term_taxonomy',
    864             'Term Taxonomies',
     897            'Term Taxonomies admin column',
    865898            function () {
    866899            },
     
    9811014        add_settings_section(
    9821015            'adminz_wordpress_content',
    983             'Content',
     1016            'Content Replace',
    9841017            function () {
    9851018            },
  • administrator-z/trunk/src/Helper/WoocommerceOrderItem.php

    r3267405 r3277147  
    11<?php
     2// Chỉ nên copy file này vì chưa finish
    23// hỗ trợ cho việc truyền từ $_POST vào cart item data, order item meta, và email
    34// chỉ áp dụng cho 1 key/ 1 label, với số nhiều thì gọi nhiều lần.
    45// Meta data sẽ được giữ nguyên khi recalculate order
     6// js mẫu và function custom item price ko hỗ trợ, tham khảo code ở ví dụ
    57
    68namespace Adminz\Helper;
    79
    810class WoocommerceOrderItem {
     11
     12    const VERSION = '16.04.2025';
    913
    1014    public $item_label;
     
    7579    function raw_woocommerce_checkout_create_order_line_item() {
    7680        add_action('woocommerce_checkout_create_order_line_item', function ($item, $cart_item_key, $values, $order) {
    77             if ($this->item_label) {
    78                 $value = $values[$this->item_key];
    79                 // $value bắt buộc phải có giá trị thì mới dc đưa vào order
    80                 // và phải xử lý từ bước cart
    81                 $item->add_meta_data(
    82                     $this->item_key,
    83                     $value
    84                 );
    85             }
     81            $value = $values[$this->item_key];
     82            // $value bắt buộc phải có giá trị thì mới dc đưa vào order
     83            // và phải xử lý từ bước cart
     84            $item->add_meta_data(
     85                $this->item_key,
     86                $value
     87            );
    8688        }, 10, 4);
     89    }
     90
     91    function is_edit_order_admin() {
     92        // Kiểm tra nếu đang ở màn hình edit order (HPOS hoặc classic) thì bỏ qua
     93        if (is_admin() && function_exists('get_current_screen')) {
     94            $screen = get_current_screen();
     95            if ($screen && ($screen->id === 'shop_order' || $screen->id === 'woocommerce_page_wc-orders')) {
     96                return true;
     97            }
     98        }
     99    }
     100
     101    // display: Hiển thị data trong trang admin (mục chi tiết order), định dạng key và value để dễ đọc.
     102    function is_send_order_admin() {
     103        if (is_admin() and ($_POST['wc_order_action'] ?? '')) {
     104            return true;
     105        }
    87106    }
    88107
     
    90109    function display_woocommerce_order_item_display_meta_key() {
    91110
    92         add_filter('woocommerce_order_item_display_meta_value', function ($value, $meta, $item) {
     111        // ẩn đi những item ko có label
     112        add_filter('woocommerce_order_item_get_formatted_meta_data', function ($formatted_meta, $order_item) {
     113
     114            //
     115            if ($this->is_edit_order_admin() and !$this->is_send_order_admin()) {
     116                return $formatted_meta;
     117            }
     118
     119            foreach ((array)$formatted_meta as $key => $item) {
     120                if ($this->item_key === $item->key and $this->item_label === '') {
     121                    unset($formatted_meta[$key]);
     122                }
     123            }
     124            return $formatted_meta;
     125        }, 10, 2);
     126
     127        // cột trái
     128        add_filter('woocommerce_order_item_display_meta_key', function ($return, $meta, $item) {
    93129            if ($meta->key === $this->item_key) {
    94                 return apply_filters(
    95                     'WoocommerceOrderItem_display',
    96                     $value,
    97                     $this->item_key,
    98                     $item
    99                 );
    100             }
    101             return $value;
     130                $return = $this->item_label;
     131
     132                //
     133                if ($this->is_edit_order_admin()) {
     134                    if (!$return) {
     135                        $return = $this->item_key;
     136                        return $return;
     137                    }
     138                }
     139            }
     140            return $return;
    102141        }, 10, 3);
    103142
    104         add_filter('woocommerce_order_item_display_meta_key', function ($display_key, $meta, $item) {
     143        // cột phải
     144        add_filter('woocommerce_order_item_display_meta_value', function ($return, $meta, $item) {
    105145            if ($meta->key === $this->item_key) {
    106                 $display_key = $this->item_label;
    107             }
    108             return $display_key;
     146                if ($this->item_label) {
     147                    return apply_filters(
     148                        'WoocommerceOrderItem_display',
     149                        $return,
     150                        $this->item_key,
     151                        $item
     152                    );
     153                } else {
     154                    // keep default
     155                }
     156            }
     157            return $return;
    109158        }, 10, 3);
    110159    }
     
    170219}
    171220
    172 
    173 // $a             = new \Adminz\Helper\WoocommerceOrderItem;
    174 // $a->item_label = $label;
    175 // $a->item_key   = $key;
    176 // $a->init();
     221/** ------- Khai báo ------------ */
     222// add_action('init', function () {
     223
     224//     $list = [
     225//         // key => label
     226//         'property' => 'Property',
     227//         'property_1' => 'Property 1',
     228//         'property_2' => 'Property 2',
     229//     ];
     230
     231//     foreach ((array)$list as $key => $value) {
     232//         $a             = new \WCP\Helper\WoocommerceOrderItem;
     233//         $a->item_label = $value;
     234//         $a->item_key   = $key;
     235//         $a->init();
     236//     }
     237
     238//     add_filter('WoocommerceOrderItem_raw', function ($value, $key, $item) use ($list) {
     239//         if (in_array($key, array_keys($list)) and $key == 'property') {
     240//             return $value . ' Custom raw';
     241//         }
     242//         return $value;
     243//     }, 10, 3);
     244
     245//     add_filter('WoocommerceOrderItem_display', function ($value, $key, $item) use ($list) {
     246//         if (in_array($key, array_keys($list)) and $key == 'property') {
     247//             return $value . ' Custom diplay';
     248//         }
     249//         return $value;
     250//     }, 10, 3);
     251// });
     252
     253/** ------- hook để custom item price trong cart ------------ */
     254// add_action('woocommerce_before_calculate_totals', function ($cart) {
     255//     if (is_admin() && !defined('DOING_AJAX')) {
     256//         return;
     257//     }
     258//     foreach ($cart->get_cart() as $cart_item_key => $cart_item) {
     259//         $product = $cart_item['data'];
     260//         $price = 100; // custom item price
     261//         if ($price) {
     262//             $product->set_price($price);
     263//         }
     264//     }
     265// });
     266
     267/** ------- hook để custom item price trong reculcale order ------------ */
     268// add_action('woocommerce_order_before_calculate_totals', function ($and_taxes, $order) {
     269//     foreach ($order->get_items() as $item) {
     270//         // Chỉ xử lý với line item
     271//         if (!$item->is_type('line_item')) {
     272//             continue;
     273//         }
     274
     275//         $original_subtotal = $item->get_subtotal();
     276//         $original_total = $item->get_total();
     277//         $discount = $original_subtotal - $original_total;
     278
     279//         $_check_price = 100;
     280//         $new_subtotal = $_check_price;
     281
     282//         // Tính toán total mới
     283//         $new_total = $new_subtotal - $discount;
     284
     285//         // Đảm bảo total không âm
     286//         if ($new_total < 0) {
     287//             $new_total = 0;
     288//             // Có thể điều chỉnh discount ở đây nếu cần
     289//             $discount = $new_subtotal; // Discount tối đa = subtotal
     290//         }
     291
     292//         // Cập nhật giá trị
     293//         $item->set_subtotal($new_subtotal);
     294//         $item->set_total($new_total);
     295//     }
     296
     297//     // Tính lại thuế nếu cần
     298//     if ($and_taxes) {
     299//         $order->calculate_taxes();
     300//     }
     301// }, 10, 2);
     302
     303/** ------- Script chuẩn để add item vào cart với formData ------------ */
     304// <script type="text/javascript">
     305//     document.addEventListener('DOMContentLoaded', () => {
     306//         const button = e.currentTarget;
     307//         if ('undefined' === typeof wc_add_to_cart_params) {
     308//             return false;
     309//         }
     310//         jQuery(button).addClass('processing');
     311//         const formData = this.getFormData(); // form.serialize()
     312//         jQuery.post(
     313//             wc_add_to_cart_params.wc_ajax_url.toString().replace('%%endpoint%%', 'add_to_cart'), formData,
     314//             function(response) {
     315//                 jQuery(button).removeClass('processing');
     316//                 if (!response) {
     317//                     return;
     318//                 }
     319//                 if (response.error && response.product_url) {
     320//                     window.location = response.product_url;
     321//                     return;
     322//                 }
     323//                 if ('yes' === wc_add_to_cart_params.cart_redirect_after_add) {
     324//                     window.location = wc_add_to_cart_params.cart_url;
     325//                     return;
     326//                 }
     327//                 jQuery(document.body).trigger('added_to_cart', [response.fragments, response.cart_hash]);
     328//             }
     329//         );
     330//     });
     331// </script>
  • administrator-z/trunk/vendor/quyle91/wp-database-helper/src/WpDatabase.php

    r3271332 r3277147  
    195195            // add new
    196196            if (isset($_POST['add_record_' . $this->table_name])) {
    197                 if (wp_verify_nonce($_POST['nonce'], $this->table_name)){
     197                if (wp_verify_nonce($_POST['nonce'], $this->table_name)) {
    198198                    $_post = array_filter($_POST);
    199199                    $this->insert($_post);
     
    204204
    205205            // search
    206             if (isset($_GET['search_' . $this->table_name])) {
    207                 $this->query_args['where_conditions'] = 'like';
    208             }
     206            // if (isset($_GET['search_' . $this->table_name])) {
     207            //     $this->query_args['where_conditions'] = 'like';
     208            // }
    209209
    210210            // delete
     
    231231            'posts_per_page' => (int) ($_GET['posts_per_page'] ?? 100),
    232232            'paged'          => (int) ($_GET['paged'] ?? 1),
     233            'where_conditions' => $_GET['where_conditions'] ?? '='
    233234        ];
    234235
     
    251252        // parse with $args
    252253        $this->query_args = wp_parse_args($args, $defaults);
     254        // echo "<pre>"; print_r($this->query_args); echo "</pre>";
     255        // die;
    253256        return $this->query_args;
    254257    }
     
    315318                            break;
    316319
     320                        case '=':
     321                            $tmp = "$field = '$value'";
     322                            break;
     323
    317324                        default:
    318325                            $tmp = "$field = '$value'";
    319326                            break;
    320327                    }
     328                    // echo "<pre>"; print_r($tmp); echo "</pre>"; die;
    321329                    $where[] = $tmp;
    322330                }
     
    702710            $id = wp_rand();
    703711            $field_name = esc_attr($value['name']);
    704             $field_value = esc_textarea($_GET[$field_name] ?? "");
     712            $field_value = esc_textarea(stripslashes($_GET[$field_name] ?? ""));
    705713            $fields_html .= <<<HTML
    706714            <div class="per_page item">
     
    731739                <input type="hidden" name="page" value="{$menu_slug}">
    732740                <input type="hidden" name="{$search_key}">
     741                <input type="hidden" name="where_conditions" value="like">
    733742                <div class="form_wrap">
    734743                    {$fields_html}
Note: See TracChangeset for help on using the changeset viewer.