Plugin Directory

Changeset 3368769


Ignore:
Timestamp:
09/27/2025 04:34:41 AM (6 months ago)
Author:
quyle91
Message:

Adminz new release date 27/09/2025 11:34:36,76

Location:
administrator-z/trunk
Files:
4 edited

Legend:

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

    r3368149 r3368769  
    77 * Author: quyle91
    88 * Author URI: http://quyle91.net
    9  * Version: 2025.09.26
     9 * Version: 2025.09.27
    1010 * License: GPL2
    1111 * Text Domain: administrator-z
  • administrator-z/trunk/src/Controller/AdministratorZ.php

    r3367317 r3368769  
    5454        add_settings_field(
    5555            wp_rand(),
     56            __('Version'),
     57            function () {
     58                echo '<code>' . ADMINZ_VERSION . '</code>';
     59            },
     60            $this->id,
     61            'adminz'
     62        );
     63
     64        // field
     65        add_settings_field(
     66            wp_rand(),
    5667            __('What&#8217;s New'),
    5768            function () {
    5869                $list = [
     70                    'New: Wordpress seo - Custom permalink, enable this function is required',
    5971                    'Restore option Flatsome: enable zalo skype whatsapp support checkbox',
    6072                    'Flatsome - fix element openstreet map for wrong lat/long data',
     
    113125        add_settings_field(
    114126            wp_rand(),
    115             __('Version'),
    116             function () {
    117                 echo '<small>' . ADMINZ_VERSION . '</small>';
    118             },
    119             $this->id,
    120             'adminz'
    121         );
    122 
    123         // field
    124         add_settings_field(
    125             wp_rand(),
    126127            'Data version',
    127128            function () {
  • administrator-z/trunk/src/Controller/Wordpress.php

    r3359270 r3368769  
    231231            $a = new \Adminz\Helper\Seo();
    232232            $a->general_og_twitter();
     233        }
     234
     235        //
     236        if (!empty($this->settings['support_custom_permalink'] ?? '') == 'on') {
     237            $a = new \Adminz\Helper\Seo();
     238            $a->custom_permalink();
    233239        }
    234240
     
    842848        );
    843849
     850        // field
     851        add_settings_field(
     852            wp_rand(),
     853            'Custom permalink support',
     854            function () {
     855                // field
     856                echo adminz_field([
     857                    'field' => 'input',
     858                    'attribute' => [
     859                        'type' => 'checkbox',
     860                        'name' => $this->option_name . '[support_custom_permalink]',
     861                    ],
     862                    'value' => $this->settings['support_custom_permalink'] ?? "",
     863                    'note' => 'Create field in post edit to custom permalink.',
     864                ]);
     865
     866                echo adminz_toggle_button(_x('Suggested', 'custom headers'), ".guild_process");
     867                $test_meta_values = [
     868                    'abc-xycx-just-a-cool-blog-post-with-images' => 'Work',
     869                    'abc/100/sdfalhsdal;fsadh' => 'Work',
     870                    'folder/subfolder/file.name' => 'Work',
     871                    '@weird!$+chars/slug' => 'Work',
     872                    '中文/slug' => 'Work (if the server supports Unicode)',
     873                    '%E6%97%A5%E6%9C%AC%E8%AA%9E/slug' => 'Work (but percent-encoded)',
     874                    'foo#bar' => 'Not Work (# = fragment, browser dont accept it)',
     875                    'foo?bar' => 'Not Work (? = query string)',
     876                    'path with spaces' => 'Not Work (browser send %20)',
     877                    'foo%bar' => 'Not Work (% must be %HH)',
     878                    'folder\\name' => 'Not Work (Invalid backslash)',
     879                ];
     880                echo <<<HTML
     881                <table class="guild_process hidden" style="margin-top: 15px;">
     882                    <tr>
     883                        <td>Meta_value</td>
     884                        <td>Work or Not</td>
     885                    </tr>
     886                HTML;
     887                foreach ($test_meta_values as $meta => $result) {
     888                    echo "<tr>";
     889                    echo "<td>" . esc_html($meta) . "</td>";
     890                    echo "<td>" . esc_html($result) . "</td>";
     891                    echo "</tr>";
     892                }
     893                echo "</table>";
     894
     895            },
     896            $this->id,
     897            'adminz_seo'
     898        );
     899
    844900
    845901        // add section
  • administrator-z/trunk/src/Helper/Seo.php

    r3359270 r3368769  
    142142        foreach (get_post_types() as $post_type => $post_type) {
    143143            $args = [
    144                 'post_type'          => $post_type,
    145                 'metabox_label'      => 'Adminz preload images',
    146                 'meta_fields'        => [
     144                'post_type' => $post_type,
     145                'metabox_label' => 'Adminz preload images',
     146                'meta_fields' => [
    147147                    [
    148148                        'meta_key' => 'adminz_preload_images',
     
    172172            $meta->init_meta();
    173173        }
    174        
     174
    175175
    176176        // show preload image
    177         add_action('wp_head', function (){
     177        add_action('wp_head', function () {
    178178
    179179            // skip on non-singular pages
    180             if(!is_singular()) {
     180            if (!is_singular()) {
    181181                return;
    182182            }
     
    186186
    187187            // skip if empty
    188             if(empty($preload_images)){
     188            if (empty($preload_images)) {
    189189                return;
    190190            }
     
    200200        });
    201201    }
     202
     203    function custom_permalink() {
     204
     205        // create page metabox
     206        foreach (get_post_types() as $post_type => $post_type) {
     207            $args = [
     208                'post_type' => $post_type,
     209                'metabox_label' => 'Adminz custom permalink',
     210                'meta_fields' => [
     211                    [
     212                        'meta_key' => 'adminz_custom_permalink',
     213                        'label' => 'Custom permalink',
     214                        'field' => 'input',
     215                        'attribute' => [
     216                            'type' => 'text',
     217                            'placeholder' => 'custom-slug',
     218                        ],
     219                        'suggest' => '1/2/3/4/5/6abc-xyz/just-a-cool-blog-post',
     220                        'note' => 'Don\'t forget save permalink after new changes'
     221                    ],
     222                ],
     223                'register_post_meta' => true,
     224                'admin_post_columns' => false,
     225            ];
     226
     227            $meta = \WpDatabaseHelper\Init::WpMeta();
     228            $meta->init($args);
     229            $meta->init_meta();
     230        }
     231
     232        // add rewrite rule
     233        add_action('init', function () {
     234            global $wpdb;
     235
     236            // lấy tất cả permalink tùy chỉnh
     237            $results = $wpdb->get_results("
     238            SELECT post_id, meta_value
     239            FROM {$wpdb->postmeta}
     240            WHERE meta_key = 'adminz_custom_permalink'
     241            AND meta_value <> ''
     242            ");
     243
     244            if (!empty($results)) {
     245                foreach ($results as $row) {
     246                    $post_id = intval($row->post_id);
     247                    $meta_value = $row->meta_value;
     248
     249                    $post_type = get_post_type($post_id);
     250                    if (!$post_type) {
     251                        continue;
     252                    }
     253
     254                    // build regex rule chính xác theo meta_value
     255                    $regex = preg_quote($meta_value, '/'); // escape ký tự regex đặc biệt
     256                    add_rewrite_rule(
     257                        '^' . $regex . '/?$',
     258                        'index.php?post_type=' . $post_type . '&p=' . $post_id,
     259                        'top'
     260                    );
     261                }
     262            }
     263        });
     264
     265
     266        // change post link
     267        $filter_hook = function ($post_link, $post) {
     268            $post_id = is_object($post) ? $post->ID : (int) $post;
     269
     270            $custom = get_post_meta($post_id, 'adminz_custom_permalink', true);
     271            if (!empty($custom)) {
     272                $custom_path = trim($custom, "/ \t\n\r\0\x0B");
     273                return home_url('/' . $custom_path . '/');
     274            }
     275
     276            return $post_link;
     277        };
     278
     279        add_filter('post_type_link', $filter_hook, 10, 2);
     280        add_filter('post_link', $filter_hook, 10, 2);
     281        add_filter('page_link', $filter_hook, 10, 2);
     282        add_filter('attachment_link', $filter_hook, 10, 2);
     283    }
    202284}
Note: See TracChangeset for help on using the changeset viewer.