Plugin Directory

Changeset 3318141


Ignore:
Timestamp:
06/26/2025 09:53:23 AM (9 months ago)
Author:
quyle91
Message:

Adminz new release date 26/06/2025 16:53:13,69

Location:
administrator-z/trunk
Files:
4 edited

Legend:

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

    r3311656 r3318141  
    77 * Author: quyle91
    88 * Author URI: http://quyle91.net
    9  * Version: 2025.06.14
     9 * Version: 2025.06.26
    1010 * License: GPL2
    1111 * Text Domain: administrator-z
  • administrator-z/trunk/assets/js/adminz.js

    r3277147 r3318141  
    8080            });
    8181
     82            // wpcf7: adminz_wpcf7_toggle
     83            document.querySelectorAll('.adminz_enable_adminz_wpcf7_toggle .adminz_wpcf7_toggle').forEach(element => {
     84                this.adminz_wpcf7_toggle(element);
     85            });
     86
    8287
    8388        };
     
    8994            });
    9095        }
     96
     97        adminz_wpcf7_toggle = (element) => {
     98            console.log('adminz_wpcf7_toggle');
     99            const hiddenFields = element.querySelectorAll('.wpcf7-form-control.hidden');
     100            const primaryField = element.querySelector('.wpcf7-form-control:not(.hidden)');
     101
     102            const handleHiddenFields = () => {
     103                const values = Array.from(hiddenFields)
     104                    .map(field => field.value.trim())
     105                    .filter(value => value !== '');
     106
     107                const mergedValue = values.join(' - ');
     108
     109                // Nếu là input type text (hoặc tương tự), bạn có thể set value
     110                if (primaryField.tagName === 'INPUT' || primaryField.tagName === 'TEXTAREA') {
     111                    primaryField.value = mergedValue;
     112                }
     113            };
     114
     115            hiddenFields.forEach(field => {
     116                field.addEventListener('input', handleHiddenFields);
     117            });
     118
     119            primaryField.addEventListener('click', () => {
     120
     121                hiddenFields.forEach(field => {
     122                    field.classList.remove('hidden');
     123                });
     124
     125                if(hiddenFields[0]){
     126                    hiddenFields[0].focus();
     127                }
     128
     129                primaryField.classList.add('hidden');
     130            });
     131        };
    91132
    92133        adminz_auto_freescroll = (element) => {
  • administrator-z/trunk/src/Controller/AdministratorZ.php

    r3311656 r3318141  
    6161            function () {
    6262                $list = [
     63                    'Wpcf7 - Date time placeholder',
    6364                    'Wordpress - Move plugins to must use',
    6465                    'Flatsome custom slider - New option: equal height',
  • administrator-z/trunk/src/Controller/Wpcf7.php

    r3295523 r3318141  
    44
    55final class Wpcf7 {
    6     private static $instance = null;
    7     public $id = 'adminz_contactform7';
    8     public $name = 'Contact form 7';
    9     public $option_name = 'adminz_cf7';
    10 
    11     public $settings = [];
    12 
    13     public static function get_instance() {
    14         if (is_null(self::$instance)) {
    15             self::$instance = new self();
    16         }
    17         return self::$instance;
    18     }
    19 
    20     function __construct() {
    21         add_filter('adminz_option_page_nav', [$this, 'add_admin_nav'], 10, 1);
    22         add_action('admin_init', [$this, 'register_settings']);
    23         $this->load_settings();
    24         $this->plugin_loaded();
    25     }
    26 
    27     function plugin_loaded() {
    28 
    29         // ------------------
    30         if ($this->settings['anti_spam'] ?? "") {
    31             /*
     6    private static $instance = null;
     7    public $id = 'adminz_contactform7';
     8    public $name = 'Contact form 7';
     9    public $option_name = 'adminz_cf7';
     10
     11    public $settings = [];
     12
     13    public static function get_instance() {
     14        if (is_null(self::$instance)) {
     15            self::$instance = new self();
     16        }
     17        return self::$instance;
     18    }
     19
     20    function __construct() {
     21        add_filter('adminz_option_page_nav', [$this, 'add_admin_nav'], 10, 1);
     22        add_action('admin_init', [$this, 'register_settings']);
     23        $this->load_settings();
     24        $this->plugin_loaded();
     25    }
     26
     27    function plugin_loaded() {
     28
     29        // ------------------
     30        if ($this->settings['anti_spam'] ?? "") {
     31            /*
    3232             * Chống spam cho contact form 7
    3333             * Author: levantoan.com
    3434             * */
    35             /*Thêm 1 field ẩn vào form cf7*/
    36             add_filter('wpcf7_form_elements', function ($html) {
    37                 $html = '<div style="display: none"><p><span class="wpcf7-form-control-wrap" data-name="devvn"><input size="40" class="wpcf7-form-control wpcf7-text" aria-invalid="false" value="" type="text" name="devvn"></span></p></div>' . $html;
    38                 return $html;
    39             });
    40 
    41             /*Kiểm tra form đó mà được nhập giá trị thì là spam*/
    42             add_action('wpcf7_posted_data', function ($posted_data) {
    43                 $submission = \WPCF7_Submission::get_instance();
    44                 if (!empty($posted_data['devvn'])) {
    45                     $submission->set_status('spam');
    46                     $submission->set_response('You are Spamer');
    47                 }
    48                 unset($posted_data['devvn']);
    49                 return $posted_data;
    50             });
    51         }
    52 
    53         // ------------------
    54         if ($this->settings['allow_shortcode'] ?? "") {
    55             add_filter('wpcf7_form_elements', function ($form) {
    56                 return do_shortcode($form);
    57             });
    58         }
    59 
    60         // ------------------
    61         if ($this->settings['allow_shortcode_email'] ?? "") {
    62             add_filter('wpcf7_mail_components', function ($components) {
    63                 if (isset($components['body'])) {
    64                     $components['body'] = do_shortcode($components['body']);
    65                 }
    66                 return $components;
    67             }, 100, 1);
    68         }
    69 
    70         // ------------------
    71         if ($this->settings['remove_auto_p'] ?? "") {
    72             //
    73             add_filter('wpcf7_autop_or_not', '__return_false');
    74             // enable auto p on email
    75             add_action('wpcf7_before_send_mail', function () {
    76                 add_filter('wpcf7_autop_or_not', '__return_true');
    77             });
    78         }
    79 
    80         // ------------------
    81         if ($this->settings['custom_email_layout'] ?? "") {
    82             if ($custom_email_content = ($this->settings['custom_email_content'] ?? "")) {
    83                 add_filter('wpcf7_mail_components', function ($components) use ($custom_email_content) {
    84                     $components['body'] = str_replace(
    85                         '{wpcf7_email_body}',
    86                         $components['body'],
    87                         $custom_email_content
    88                     );
    89 
    90                     return $components;
    91                 }, 10, 1);
    92             }
    93         }
    94 
    95         // ------------------
    96         if ($this->settings['form_newletters'] ?? "") {
    97             $a = new \Adminz\Helper\Wpcf7();
    98             $a->make_form_newletters(
    99                 $this->settings['form_newletters'],
    100                 'adminz_newletters_email'
    101             );
    102         }
    103 
    104         // ------------------
    105         if ($this->settings['thankyou'] ?? "") {
    106             $a = new \Adminz\Helper\Wpcf7();
    107             $a->make_thankyou();
    108         }
    109 
    110         // ------------------
    111         if ($this->settings['save_submissions'] ?? "") {
    112             $a = new \Adminz\Helper\Wpcf7();
    113             $a->save_submissions();
    114         }
    115     }
    116 
    117     function load_settings() {
    118         $this->settings = get_option($this->option_name, []);
    119     }
    120 
    121     function add_admin_nav($nav) {
    122         $nav[$this->id] = $this->name;
    123         return $nav;
    124     }
    125 
    126     function register_settings() {
    127         register_setting($this->id, $this->option_name);
    128 
    129         // add section
    130         add_settings_section(
    131             'adminz_cf7_section',
    132             'Contact Form 7',
    133             function () {
    134             },
    135             $this->id
    136         );
    137 
    138         // field
    139         add_settings_field(
    140             wp_rand(),
    141             'Anti spam by DevVN',
    142             function () {
    143                 // field
    144                 echo adminz_field([
    145                     'field' => 'input',
    146                     'attribute' => [
    147                         'type' => 'checkbox',
    148                         'name' => $this->option_name . '[anti_spam]',
    149                     ],
    150                     'value' => $this->settings['anti_spam'] ?? "",
    151                 ]);
    152             },
    153             $this->id,
    154             'adminz_cf7_section'
    155         );
    156 
    157         // field
    158         add_settings_field(
    159             wp_rand(),
    160             'Allow shortcode',
    161             function () {
    162                 // field
    163                 echo adminz_field([
    164                     'field' => 'input',
    165                     'attribute' => [
    166                         'type' => 'checkbox',
    167                         'name' => $this->option_name . '[allow_shortcode]',
    168                     ],
    169                     'value' => $this->settings['allow_shortcode'] ?? "",
    170                 ]);
    171             },
    172             $this->id,
    173             'adminz_cf7_section'
    174         );
    175 
    176         // field
    177         add_settings_field(
    178             wp_rand(),
    179             'Allow shortcode in email',
    180             function () {
    181                 // field
    182                 echo adminz_field([
    183                     'field' => 'input',
    184                     'attribute' => [
    185                         'type' => 'checkbox',
    186                         'name' => $this->option_name . '[allow_shortcode_email]',
    187                     ],
    188                     'value' => $this->settings['allow_shortcode_email'] ?? "",
    189                     'note' => '<strong>Use HTML content type</strong> is required!',
    190                 ]);
    191             },
    192             $this->id,
    193             'adminz_cf7_section'
    194         );
    195 
    196         // field
    197         add_settings_field(
    198             wp_rand(),
    199             'Remove auto p tag',
    200             function () {
    201                 // field
    202                 echo adminz_field([
    203                     'field' => 'input',
    204                     'attribute' => [
    205                         'type' => 'checkbox',
    206                         'name' => $this->option_name . '[remove_auto_p]',
    207                     ],
    208                     'value' => $this->settings['remove_auto_p'] ?? "",
    209                 ]);
    210             },
    211             $this->id,
    212             'adminz_cf7_section'
    213         );
    214 
    215         // field
    216         add_settings_field(
    217             wp_rand(),
    218             'Custom email layout',
    219             function () {
    220                 // field
    221                 echo adminz_field([
    222                     'field' => 'input',
    223                     'attribute' => [
    224                         'type' => 'checkbox',
    225                         'name' => $this->option_name . '[custom_email_layout]',
    226                     ],
    227                     'value' => $this->settings['custom_email_layout'] ?? "",
    228                     'note' => '<strong>Use HTML content type</strong> is required!',
    229                 ]);
    230 
    231                 // field
    232                 echo adminz_toggle_button(__('Content'), ".xxxxxxxxxxxx");
    233                 $default = <<<HTML
     35            /*Thêm 1 field ẩn vào form cf7*/
     36            add_filter('wpcf7_form_elements', function ($html) {
     37                $html = '<div style="display: none"><p><span class="wpcf7-form-control-wrap" data-name="devvn"><input size="40" class="wpcf7-form-control wpcf7-text" aria-invalid="false" value="" type="text" name="devvn"></span></p></div>' . $html;
     38                return $html;
     39            });
     40
     41            /*Kiểm tra form đó mà được nhập giá trị thì là spam*/
     42            add_action('wpcf7_posted_data', function ($posted_data) {
     43                $submission = \WPCF7_Submission::get_instance();
     44                if (!empty($posted_data['devvn'])) {
     45                    $submission->set_status('spam');
     46                    $submission->set_response('You are Spamer');
     47                }
     48                unset($posted_data['devvn']);
     49                return $posted_data;
     50            });
     51        }
     52
     53        // ------------------
     54        if ($this->settings['allow_shortcode'] ?? "") {
     55            add_filter('wpcf7_form_elements', function ($form) {
     56                return do_shortcode($form);
     57            });
     58        }
     59
     60        // ------------------
     61        if ($this->settings['allow_shortcode_email'] ?? "") {
     62            add_filter('wpcf7_mail_components', function ($components) {
     63                if (isset($components['body'])) {
     64                    $components['body'] = do_shortcode($components['body']);
     65                }
     66                return $components;
     67            }, 100, 1);
     68        }
     69
     70        // ------------------
     71        if ($this->settings['remove_auto_p'] ?? "") {
     72            //
     73            add_filter('wpcf7_autop_or_not', '__return_false');
     74            // enable auto p on email
     75            add_action('wpcf7_before_send_mail', function () {
     76                add_filter('wpcf7_autop_or_not', '__return_true');
     77            });
     78        }
     79
     80        // ------------------
     81        if ($this->settings['custom_email_layout'] ?? "") {
     82            if ($custom_email_content = ($this->settings['custom_email_content'] ?? "")) {
     83                add_filter('wpcf7_mail_components', function ($components) use ($custom_email_content) {
     84                    $components['body'] = str_replace(
     85                        '{wpcf7_email_body}',
     86                        $components['body'],
     87                        $custom_email_content
     88                    );
     89
     90                    return $components;
     91                }, 10, 1);
     92            }
     93        }
     94
     95        // ------------------
     96        if ($this->settings['form_newletters'] ?? "") {
     97            $a = new \Adminz\Helper\Wpcf7();
     98            $a->make_form_newletters(
     99                $this->settings['form_newletters'],
     100                'adminz_newletters_email'
     101            );
     102        }
     103
     104        // ------------------
     105        if ($this->settings['thankyou'] ?? "") {
     106            $a = new \Adminz\Helper\Wpcf7();
     107            $a->make_thankyou();
     108        }
     109
     110        // ------------------
     111        if ($this->settings['save_submissions'] ?? "") {
     112            $a = new \Adminz\Helper\Wpcf7();
     113            $a->save_submissions();
     114        }
     115
     116        // ------------------
     117        if ($this->settings['date_time_placeholder'] ?? "" == 'on') {
     118            adminz_add_body_class('adminz_enable_adminz_wpcf7_toggle');
     119        }
     120    }
     121
     122    function load_settings() {
     123        $this->settings = get_option($this->option_name, []);
     124    }
     125
     126    function add_admin_nav($nav) {
     127        $nav[$this->id] = $this->name;
     128        return $nav;
     129    }
     130
     131    function register_settings() {
     132        register_setting($this->id, $this->option_name);
     133
     134        // add section
     135        add_settings_section(
     136            'adminz_cf7_section',
     137            'Contact Form 7',
     138            function () {
     139            },
     140            $this->id
     141        );
     142
     143        // field
     144        add_settings_field(
     145            wp_rand(),
     146            'Anti spam by DevVN',
     147            function () {
     148                // field
     149                echo adminz_field([
     150                    'field' => 'input',
     151                    'attribute' => [
     152                        'type' => 'checkbox',
     153                        'name' => $this->option_name . '[anti_spam]',
     154                    ],
     155                    'value' => $this->settings['anti_spam'] ?? "",
     156                ]);
     157            },
     158            $this->id,
     159            'adminz_cf7_section'
     160        );
     161
     162        // field
     163        add_settings_field(
     164            wp_rand(),
     165            'Allow shortcode',
     166            function () {
     167                // field
     168                echo adminz_field([
     169                    'field' => 'input',
     170                    'attribute' => [
     171                        'type' => 'checkbox',
     172                        'name' => $this->option_name . '[allow_shortcode]',
     173                    ],
     174                    'value' => $this->settings['allow_shortcode'] ?? "",
     175                ]);
     176            },
     177            $this->id,
     178            'adminz_cf7_section'
     179        );
     180
     181        // field
     182        add_settings_field(
     183            wp_rand(),
     184            'Allow shortcode in email',
     185            function () {
     186                // field
     187                echo adminz_field([
     188                    'field' => 'input',
     189                    'attribute' => [
     190                        'type' => 'checkbox',
     191                        'name' => $this->option_name . '[allow_shortcode_email]',
     192                    ],
     193                    'value' => $this->settings['allow_shortcode_email'] ?? "",
     194                    'note' => '<strong>Use HTML content type</strong> is required!',
     195                ]);
     196            },
     197            $this->id,
     198            'adminz_cf7_section'
     199        );
     200
     201        // field
     202        add_settings_field(
     203            wp_rand(),
     204            'Remove auto p tag',
     205            function () {
     206                // field
     207                echo adminz_field([
     208                    'field' => 'input',
     209                    'attribute' => [
     210                        'type' => 'checkbox',
     211                        'name' => $this->option_name . '[remove_auto_p]',
     212                    ],
     213                    'value' => $this->settings['remove_auto_p'] ?? "",
     214                ]);
     215            },
     216            $this->id,
     217            'adminz_cf7_section'
     218        );
     219
     220        // field
     221        add_settings_field(
     222            wp_rand(),
     223            'Custom email layout',
     224            function () {
     225                // field
     226                echo adminz_field([
     227                    'field' => 'input',
     228                    'attribute' => [
     229                        'type' => 'checkbox',
     230                        'name' => $this->option_name . '[custom_email_layout]',
     231                    ],
     232                    'value' => $this->settings['custom_email_layout'] ?? "",
     233                    'note' => '<strong>Use HTML content type</strong> is required!',
     234                ]);
     235
     236                // field
     237                echo adminz_toggle_button(__('Content'), ".xxxxxxxxxxxx");
     238                $default = <<<HTML
    234239                <body style="background:#f6f6f6; padding: 70px 0;">
    235240                    <div style="max-width: 560px; padding: 20px; margin: auto; background-color: white;">
     
    238243                </body>
    239244                HTML;
    240                 $value = $this->settings['custom_email_content'] ?? "";
    241                 $value = $value ? $value : $default;
    242                 echo adminz_field([
    243                     'field' => 'textarea',
    244                     'attribute' => [
    245                         'name' => $this->option_name . '[custom_email_content]',
    246                     ],
    247                     'value' => $value,
    248                     'suggest' => '{wpcf7_email_body}',
    249                     'before' => '<div class="xxxxxxxxxxxx hidden" style="margin-top: 15px;"><div class="___default_wrap">',
    250                     'after' => '</div></div>',
    251                 ]);
    252             },
    253             $this->id,
    254             'adminz_cf7_section'
    255         );
    256 
    257         // field
    258         add_settings_field(
    259             wp_rand(),
    260             'Form as newsletters',
    261             function () {
    262                 // field
    263                 echo adminz_field([
    264                     'field' => 'select',
    265                     'attribute' => [
    266                         'type' => 'checkbox',
    267                         'name' => $this->option_name . '[form_newletters]',
    268                     ],
    269                     'post_select' => [
    270                         'post_type' => 'wpcf7_contact_form',
    271                     ],
    272                     'value' => $this->settings['form_newletters'] ?? "",
    273                     'note' => 'Use Field email name: ' . adminz_copy('adminz_newletters_email', false) . "as default, and only for Post type <strong>Post</strong>",
    274                 ]);
    275             },
    276             $this->id,
    277             'adminz_cf7_section'
    278         );
    279 
    280         // field
    281         add_settings_field(
    282             wp_rand(),
    283             'Thankyou',
    284             function () {
    285                 // field
    286                 echo adminz_field([
    287                     'field' => 'input',
    288                     'attribute' => [
    289                         'type' => 'checkbox',
    290                         'name' => $this->option_name . '[thankyou]',
    291                     ],
    292                     'value' => $this->settings['thankyou'] ?? "",
    293                 ]);
    294             },
    295             $this->id,
    296             'adminz_cf7_section'
    297         );
    298 
    299         // field
    300         add_settings_field(
    301             wp_rand(),
    302             'Save submissions',
    303             function () {
    304                 // field
    305                 echo adminz_field([
    306                     'field' => 'input',
    307                     'attribute' => [
    308                         'type' => 'checkbox',
    309                         'name' => $this->option_name . '[save_submissions]',
    310                     ],
    311                     'value' => $this->settings['save_submissions'] ?? "",
    312                 ]);
    313             },
    314             $this->id,
    315             'adminz_cf7_section'
    316         );
    317     }
     245                $value = $this->settings['custom_email_content'] ?? "";
     246                $value = $value ? $value : $default;
     247                echo adminz_field([
     248                    'field' => 'textarea',
     249                    'attribute' => [
     250                        'name' => $this->option_name . '[custom_email_content]',
     251                    ],
     252                    'value' => $value,
     253                    'suggest' => '{wpcf7_email_body}',
     254                    'before' => '<div class="xxxxxxxxxxxx hidden" style="margin-top: 15px;"><div class="___default_wrap">',
     255                    'after' => '</div></div>',
     256                ]);
     257            },
     258            $this->id,
     259            'adminz_cf7_section'
     260        );
     261
     262        // field
     263        add_settings_field(
     264            wp_rand(),
     265            'Form as newsletters',
     266            function () {
     267                // field
     268                echo adminz_field([
     269                    'field' => 'select',
     270                    'attribute' => [
     271                        'type' => 'checkbox',
     272                        'name' => $this->option_name . '[form_newletters]',
     273                    ],
     274                    'post_select' => [
     275                        'post_type' => 'wpcf7_contact_form',
     276                    ],
     277                    'value' => $this->settings['form_newletters'] ?? "",
     278                    'note' => 'Use Field email name: ' . adminz_copy('adminz_newletters_email', false) . "as default, and only for Post type <strong>Post</strong>",
     279                ]);
     280            },
     281            $this->id,
     282            'adminz_cf7_section'
     283        );
     284
     285        // field
     286        add_settings_field(
     287            wp_rand(),
     288            'Thankyou',
     289            function () {
     290                // field
     291                echo adminz_field([
     292                    'field' => 'input',
     293                    'attribute' => [
     294                        'type' => 'checkbox',
     295                        'name' => $this->option_name . '[thankyou]',
     296                    ],
     297                    'value' => $this->settings['thankyou'] ?? "",
     298                ]);
     299            },
     300            $this->id,
     301            'adminz_cf7_section'
     302        );
     303
     304        // field
     305        add_settings_field(
     306            wp_rand(),
     307            'Save submissions',
     308            function () {
     309                // field
     310                echo adminz_field([
     311                    'field' => 'input',
     312                    'attribute' => [
     313                        'type' => 'checkbox',
     314                        'name' => $this->option_name . '[save_submissions]',
     315                    ],
     316                    'value' => $this->settings['save_submissions'] ?? "",
     317                ]);
     318            },
     319            $this->id,
     320            'adminz_cf7_section'
     321        );
     322
     323        // field
     324        add_settings_field(
     325            wp_rand(),
     326            'Date time placeholder',
     327            function () {
     328                // field
     329                echo adminz_field([
     330                    'field' => 'input',
     331                    'attribute' => [
     332                        'type' => 'checkbox',
     333                        'name' => $this->option_name . '[date_time_placeholder]',
     334                    ],
     335                    'value' => $this->settings['date_time_placeholder'] ?? "",
     336                    'note' => 'All hidden fields value will be merge into primary field',
     337                ]);
     338
     339                // field
     340                echo adminz_toggle_button(__('Guid'), ".xxxxxxxxxxxx1");
     341                $value = '<div class="adminz_wpcf7_toggle">
     342                    [date date-244 class:hidden]
     343                    [date date-245 class:hidden]
     344                    [text text-266 placeholder "Select dates"]
     345                </div>';
     346                echo '<br>';
     347                echo '<textarea disabled cols="65" rows="8" class="xxxxxxxxxxxx1 hidden">' . $value . '</textarea>';
     348            },
     349            $this->id,
     350            'adminz_cf7_section'
     351        );
     352    }
    318353}
Note: See TracChangeset for help on using the changeset viewer.