Plugin Directory

Changeset 3430903


Ignore:
Timestamp:
01/02/2026 08:06:32 AM (7 weeks ago)
Author:
quyle91
Message:

Adminz new release date 02/01/2026 15:09:15,27

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

Legend:

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

    r3428124 r3430903  
    77 * Author: quyle91
    88 * Author URI: http://quyle91.net
    9  * Version: 2025.12.23
     9 * Version: 2025.02.01
    1010 * License: GPL2
    1111 * Text Domain: administrator-z
  • administrator-z/trunk/includes/functions/__admin.php

    r3295523 r3430903  
    11<?php
     2function adminz_admin_login_heading($text) {
     3    //
     4    add_filter('login_headertext', function ($return) use ($text) {
     5        if ($text) {
     6            return $text;
     7        }
     8        return $return;
     9    }, 10, 1);
     10
     11    //
     12    add_action(
     13        'login_enqueue_scripts',
     14        function () {
     15            echo <<<HTML
     16            <style type="text/css">
     17                #login>h1{
     18                    font-size: 1em;
     19                }
     20                #login>h1 a{
     21                    all: unset;
     22                    text-align: left;
     23                    display: block;
     24                    background: unset !important;
     25                    padding: 0 24px;
     26                }
     27
     28                /* supported style */
     29                #login>h1 a h1{
     30                    text-align: left;
     31                    padding: unset;
     32                }
     33                #login>h1 a p{
     34                    font-weight: normal;
     35                }
     36            </style>
     37            HTML;
     38        }
     39    );
     40}
     41
    242function adminz_admin_login_footer_text($text) {
    343    add_action('login_footer', function () use ($text) {
    444        $text = wp_kses_post($text);
    545        echo <<<HTML
    6 <div style="max-width: 320px; margin: auto; text-align: center; padding: 24px 0;">
    7 $text
    8 </div>
    9 HTML;
     46        <div style="max-width: 320px; margin: auto; text-align: center; padding: 24px 0;">
     47        $text
     48        </div>
     49        HTML;
    1050    });
    1151}
    1252
    1353function adminz_admin_login_logo($image_id) {
    14     add_filter('login_enqueue_scripts', function () use ($image_id) {
    15         $image_id = intval($image_id);
     54    add_action('login_enqueue_scripts', function () use ($image_id) {
     55        //
    1656        if (!wp_attachment_is_image($image_id)) {
    1757            return;
    1858        }
    19         $image_url = wp_get_attachment_image_url($image_id, 'full');
    20         if (!$image_url) {
    21             return;
    22         }
    23         $image_url = esc_url($image_url);
    24         echo <<<HTML
    25 <style type="text/css">
    26 h1 a {
    27 background-image: url($image_url) !important;
    28 background-size: contain !important;
    29 width: 100% !important;
    30 max-width: 280px;
    31 }
    32 </style>
    33 HTML;
    34     });
    35 }
    36 
    37 function adminz_admin_background($image_id) {
    38     add_action('login_enqueue_scripts', function () use ($image_id) {
    39         $image_id = intval($image_id);
    40         $attachment = get_post($image_id);
    41         if (!$attachment || $attachment->post_type !== 'attachment' || !wp_attachment_is_image($image_id)) {
    42             return;
    43         }
     59        //
    4460        $image_url = wp_get_attachment_image_url($image_id, 'full');
    4561        if (!$image_url) {
     
    4965        $image_url = esc_url($image_url);
    5066        echo <<<HTML
    51 <style type="text/css">
    52 body.login {
    53 background-image: url($image_url) !important;
    54 background-size: cover !important;
    55 background-position: center center !important;
     67        <style type="text/css">
     68        h1 a {
     69        background-image: url($image_url) !important;
     70        background-size: contain !important;
     71        width: 100% !important;
     72        max-width: 280px;
     73        }
     74        </style>
     75        HTML;
     76    });
    5677}
    57 </style>
    58 HTML;
     78
     79function adminz_admin_background($image_id) {
     80    add_action('login_header', function () {
     81        echo '<div class="adminz_login_wrap">';
     82        echo '<div class="adminz_bgr"></div>'; // bgr div
     83        echo '<div class="adminz_login">';
     84    });
     85
     86    add_action('login_footer', function () {
     87        echo '</div> <!-- end .adminz_login -->';
     88        echo '</div> <!-- end .adminz_login_wrap -->';
     89    });
     90
     91    add_action('login_enqueue_scripts', function () use ($image_id) {
     92        //
     93        $attachment = get_post($image_id);
     94        if (
     95            !$attachment ||
     96            $attachment->post_type !== 'attachment' ||
     97            !wp_attachment_is_image($image_id)
     98        ) {
     99            return;
     100        }
     101        //
     102        $image_url = wp_get_attachment_image_url($image_id, 'full');
     103        if (!$image_url) {
     104            return;
     105        }
     106        //
     107        $image_url = esc_url($image_url);
     108        echo <<<HTML
     109        <style type="text/css">
     110            @media(min-width: 768px){
     111                .adminz_login_wrap{
     112                    display: flex;
     113                    align-items: center;
     114                    width: 100%;
     115                }
     116
     117                .adminz_bgr{
     118                    width: 50%;
     119                    min-height: 100vh;
     120                    background-image: url($image_url) !important;
     121                    background-size: cover !important;
     122                    background-position: center center !important;
     123                }
     124
     125                .adminz_login{
     126                    width: 50%;
     127                }
     128               
     129                #loginform{
     130                    background-color: transparent !important;
     131                    border: none !important;
     132                }
     133            }
     134           
     135        </style>
     136        HTML;
    59137    });
    60138}
     
    86164function adminz_toggle_button($button, $target) {
    87165    return <<<HTML
    88 <button type="button" class="adminz_toggle button" data-toggle="{$target}" style="margin-top: 15px;">
    89 {$button}
    90 </button>
    91 HTML;
     166    <button type="button" class="adminz_toggle button" data-toggle="{$target}" style="margin-top: 15px;">
     167    {$button}
     168    </button>
     169    HTML;
    92170}
  • administrator-z/trunk/src/Controller/Wordpress.php

    r3428124 r3430903  
    112112            $image_url = $this->settings['adminz_admin_logo'];
    113113            adminz_admin_login_logo($image_url);
     114        }
     115
     116        //
     117        if ($this->settings['adminz_admin_login_heading'] ?? "") {
     118            $text = $this->settings['adminz_admin_login_heading'];
     119            adminz_admin_login_heading($text);
    114120        }
    115121
     
    234240
    235241        //
    236         if (!empty($this->settings['remove_post_type_slugs'] ?? [])) {
    237             $post_types = $this->settings['remove_post_type_slugs'];
    238             $a = new \Adminz\Helper\Seo();
    239             $a->remove_post_type_slugs($post_types);
    240         }
    241 
    242         //
     242        $remove_post_type_slugs = array_filter($this->settings['remove_post_type_slugs'] ?? []);
     243        $remove_taxonomy_slugs = array_filter($this->settings['remove_taxonomy_slugs'] ?? []);
     244        if(!empty($remove_post_type_slugs) || !empty($remove_taxonomy_slugs)) {
     245            $a = new \Adminz\Helper\Permalink();
     246            if(!empty($remove_post_type_slugs)) {
     247                $a->post_types($remove_post_type_slugs);
     248            }
     249            if(!empty($remove_taxonomy_slugs)) {
     250                $a->taxonomies($remove_taxonomy_slugs);
     251            }
     252            $a->run();
     253        }
     254
     255       
    243256        if (!empty($this->settings['support_custom_permalinks'] ?? [])) {
    244257            foreach ((array)$this->settings['support_custom_permalinks'] as $post_type) {
     
    461474                    'value' => $this->settings['adminz_admin_login_quiz'] ?? "",
    462475                    'note' => 'Admin login quiz',
     476                ]);
     477
     478                // field
     479                echo adminz_field([
     480                    'field' => 'textarea',
     481                    'attribute' => [
     482                        'name' => $this->option_name . '[adminz_admin_login_heading]',
     483                        'placeholder' => "<h1>Login to your site</h1>\r\n<p>Fill your email and password</p>",
     484                    ],
     485                    'value' => $this->settings['adminz_admin_login_heading'] ?? "",
     486                    'note' => 'Admin login heading',
    463487                ]);
    464488
     
    859883        );
    860884
    861         // field
    862         add_settings_field(
    863             wp_rand(),
    864             'Permalink - remove Post type slug',
     885        // add section
     886        add_settings_section(
     887            'adminz_seo_permalink',
     888            'Permalink',
     889            function () {
     890                //
     891            },
     892            $this->id
     893        );
     894
     895        // field
     896        add_settings_field(
     897            wp_rand(),
     898            'Remove Post type slug',
    865899            function () {
    866900                // field
     
    891925            },
    892926            $this->id,
    893             'adminz_seo'
    894         );
    895 
    896         // field
    897         add_settings_field(
    898             wp_rand(),
    899             'Permalink: Custom url support',
     927            'adminz_seo_permalink'
     928        );
     929
     930        // field
     931        add_settings_field(
     932            wp_rand(),
     933            'Remove Taxonomy term slug',
     934            function () {
     935                // field
     936                $current = $this->settings['remove_taxonomy_slugs'] ?? [''];
     937                $args = [
     938                    'field' => 'select',
     939                    'options' => ["" => __('Select')],
     940                ];
     941                foreach (get_taxonomies() as $value) {
     942                    $args['options'][$value] = $value;
     943                }
     944                $field_configs = [
     945                    ']' => $args,
     946                ];
     947
     948                echo adminz_repeater(
     949                    $current,
     950                    $this->option_name . '[remove_taxonomy_slugs]',
     951                    $field_configs
     952                );
     953
     954                $permalink_option_link = admin_url('options-permalink.php');
     955                echo <<<HTML
     956                <p>
     957                    <small>Please <strong><a target="_blank" href="{$permalink_option_link}">Save permalink</a></strong> again after changes </small>
     958                </p>
     959                HTML;
     960            },
     961            $this->id,
     962            'adminz_seo_permalink'
     963        );
     964
     965        // field
     966        add_settings_field(
     967            wp_rand(),
     968            'Custom url support',
    900969            function () {
    901970                // field
     
    9481017            },
    9491018            $this->id,
    950             'adminz_seo'
     1019            'adminz_seo_permalink'
    9511020        );
    9521021
  • administrator-z/trunk/src/Helper/Seo.php

    r3388167 r3430903  
    201201    }
    202202
    203     function remove_post_type_slugs(array $postTypes) {
    204         $postTypes = array_map('sanitize_key', $postTypes);
    205 
    206         // load rewrite rules on init
    207         add_action('init', function () use ($postTypes) {
    208             foreach ($postTypes as $pt) {
    209                 $posts = get_posts([
    210                     'post_type' => $pt,
    211                     'posts_per_page' => -1,
    212                     'post_status' => 'publish'
    213                 ]);
    214 
    215                 foreach ($posts as $p) {
    216                     // comment: match optional 2 char language prefix then post slug
    217                     add_rewrite_rule(
    218                         '^([a-z]{2}/)?' . $p->post_name . '/?$',
    219                         'index.php?post_type=' . $pt . '&name=' . $p->post_name,
    220                         'top'
    221                     );
    222                 }
    223             }
    224         });
    225 
    226         // modify permalink output
    227         add_filter('post_type_link', function ($postLink, $post) use ($postTypes) {
    228             // comment: only affect defined post types
    229             if (!in_array($post->post_type, $postTypes, true)) {
    230                 return $postLink;
    231             }
    232 
    233             // comment: return permalink without post type slug
    234             return home_url('/' . $post->post_name . '/');
    235         }, 10, 2);
    236 
    237         // redirect
    238         add_action('template_redirect', function () use ($postTypes) {
    239             if (is_singular($postTypes)) {
    240                 global $post;
    241                 $currentUrl = home_url($_SERVER['REQUEST_URI']);
    242                 $shortUrl = home_url('/' . $post->post_name . '/');
    243 
    244                 // comment: detect old url contain post type slug
    245                 foreach ($postTypes as $pt) {
    246                     if (strpos($currentUrl, '/' . $pt . '/') !== false) {
    247                         wp_redirect($shortUrl, 301);
    248                         exit;
    249                     }
    250                 }
    251             }
    252         });
    253 
    254         // when post saved -> update rewrite rules
    255         add_action('save_post', function ($postId, $post) use ($postTypes) {
    256             if (wp_is_post_revision($postId)) {
    257                 return;
    258             }
    259 
    260             // comment: only run for your CPT
    261             if (!in_array($post->post_type, $postTypes, true)) {
    262                 return;
    263             }
    264 
    265             // comment: flush rewrite just that time to make sure new slug works
    266             flush_rewrite_rules(false);
    267         }, 10, 2);
    268     }
    269 
    270203    function custom_permalink($post_type) {
    271204        // Prepare one post type only
     
    305238            // comment: query only this post type, not array
    306239            $results = $wpdb->get_results("
    307             SELECT p.ID AS post_id, pm.meta_value
    308             FROM {$wpdb->posts} p
    309             INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id
    310             WHERE pm.meta_key = 'adminz_custom_permalink'
    311             AND pm.meta_value <> ''
    312             AND p.post_type = '" . esc_sql($post_type) . "'
    313         ");
     240                SELECT p.ID AS post_id, pm.meta_value
     241                FROM {$wpdb->posts} p
     242                INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id
     243                WHERE pm.meta_key = 'adminz_custom_permalink'
     244                AND pm.meta_value <> ''
     245                AND p.post_type = '" . esc_sql($post_type) . "'
     246            ");
    314247
    315248            if (!empty($results)) {
Note: See TracChangeset for help on using the changeset viewer.