Plugin Directory

Changeset 3211793


Ignore:
Timestamp:
12/22/2024 10:43:57 AM (15 months ago)
Author:
redboxcdn
Message:

v1.9

Location:
purgebox/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • purgebox/trunk/README.md

    r3071443 r3211793  
    44Tags: CDN,Cache Delete,Purge,redbox
    55Requires at least: 4.6
    6 Tested up to: 6.5
    7 Stable tag: 6.0
     6Tested up to: 6.7
     7Stable tag: 6.7
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3535
    3636== Changelog ==
     371.9 Add multisite setting Support WP6.7
    37381.8 Add user role setting Support WP6.5
    38391.7 Support WP6.2.2
  • purgebox/trunk/classes/class-purgebox-admin.php

    r3071443 r3211793  
    4747        $this->_register_setting('group');
    4848        $this->_register_setting('api_key');
     49        $this->_register_setting('purge_path'); // Purge Path を登録
     50        $this->_register_setting('multisite_enabled'); // Multisite 設定を登録
     51        $this->_register_setting('manual_purgepath_enabled'); // 手動PurgePath 設定を登録
    4952        // add purge all role
    5053        register_setting( self::$__setting_group, self::$_option_prefix . 'purge_all_roles' );
     
    163166        $value['api_key'] = esc_attr( self::_get_option( 'api_key' ) );
    164167        $value['group'] = esc_attr( self::_get_option( 'group' ) );
     168        $value['purge_path'] = esc_attr(self::_get_option('purge_path', '/*')); // デフォルト値は '/*'
     169        $value['multisite_enabled'] = esc_attr(self::_get_option('multisite_enabled', '0')); // デフォルト値は '0'
     170        $value['manual_purgepath_enabled'] = esc_attr(self::_get_option('manual_purgepath_enabled', '0')); // デフォルト値は '0'
     171   
     172        // 手動PurgePathが無効の場合に自動設定を行う
     173        if ($value['manual_purgepath_enabled'] !== '1') {
     174            // マルチサイトが有効で、かつチェックが入っている場合
     175            if ($value['multisite_enabled'] === '1' && is_multisite()) {
     176                // 現在ログインしているサブサイトのパスを取得
     177                $details = get_blog_details(get_current_blog_id());
     178                $value['purge_path'] = rtrim($details->path, '/') . '/*';
     179            } elseif (!is_multisite()) {
     180                // マルチサイトでない場合、サブディレクトリのパスを取得
     181                $home_url = parse_url(home_url());
     182                $subdirectory = isset($home_url['path']) && $home_url['path'] !== '/' ? rtrim($home_url['path'], '/') . '/*' : '/*';
     183                $value['purge_path'] = $subdirectory;
     184            }
     185        } else {
     186            // 手動でPurge Pathが設定されていれば、その値を保持
     187            $value['purge_path'] = esc_attr(self::_get_option('purge_path', '/*')); // 手動設定の場合のデフォルト値
     188        }
     189
     190        update_option(self::$_option_prefix . 'purge_path', $value['purge_path']);
     191   
    165192        $view['plugin_name'] = self::PLUGIN_NAME;
    166193        $view['prefix'] = self::$_option_prefix;
    167194        $view['submit_button'] = get_submit_button();
    168195        $view['options'] = '';
    169 
     196   
    170197        $default = '2';
    171198        foreach( array('2') as $version ) {
     
    173200            $view['options'] .= '<option value="'. $version. '" '. $selected. '>'. $version. '</option>';
    174201        }
    175 
     202   
    176203        echo '<form method="post" action="options.php">';
    177204        settings_fields( self::$__setting_group );
    178 
     205   
    179206        // 全ロールを取得して、チェックボックスリストを生成
    180207        $roles_checkboxes = '';
     
    185212            $roles_checkboxes .= "<label><input type='checkbox' name='" . self::$_option_prefix . "purge_all_roles[]' value='$role_value' $checked> $role_name</label><br>";
    186213        }
    187 
    188 
     214   
     215        $multisite_checked = ($value['multisite_enabled'] == '1') ? 'checked' : '';
     216        $manual_purgepath_enabled = ($value['manual_purgepath_enabled'] == '1') ? 'checked' : '';
     217   
    189218        echo <<<HTML
    190 <div id="redbox-wrap">
    191     <h1>{$view['plugin_name']} Setting</h1>
    192     <fieldset>
    193         <p>         
    194             <label>
    195                 API Version : <select name="{$view['prefix']}version" required="required">{$view['options']}</select>
    196             </label>
    197         </p>
    198         <p>
    199             <label>
    200                 API Key : <input type="text" name="{$view['prefix']}api_key" value="{$value['api_key']}" required="required">
    201             </label>
    202         </p>
    203         <p>
    204             <label>
    205                 Group : <input type="text" name="{$view['prefix']}group" value="{$value['group']}" required="required">
    206             </label>
    207         </p>
    208         <h2>Purge Allボタンを許可するロールを選択して下さい。</h2>
    209         $roles_checkboxes
    210     </fieldset>
    211 
    212 
    213     <p>{$view['submit_button']}</p>
    214 </div>
    215 HTML;
    216 echo '</form>';
    217 }
     219        <div id="redbox-wrap">
     220            <h1>{$view['plugin_name']} Setting</h1>
     221            <fieldset>
     222                <p>
     223                    <label>
     224                        API Version : <select name="{$view['prefix']}version" required="required">{$view['options']}</select>
     225                    </label>
     226                </p>
     227                <p>
     228                    <label>
     229                        API Key: <input type="password" name="{$view['prefix']}api_key" value="{$value['api_key']}" required="required">
     230                    </label>
     231                </p>
     232                <p>
     233                    <label>
     234                        Group : <input type="text" name="{$view['prefix']}group" value="{$value['group']}" required="required">
     235                    </label>
     236                </p>
     237                <p>
     238                    <label>
     239                        Purge Path: <input type="text" name="{$view['prefix']}purge_path" value="{$value['purge_path']}" placeholder="e.g., /* or /specific/path">
     240                    </label>
     241                </p>
     242                <p>
     243                    <label>
     244                        Manual Purge Path:
     245                        <input type="checkbox" name="{$view['prefix']}manual_purgepath_enabled" value="1" $manual_purgepath_enabled>
     246                        <br>
     247                        キャッシュ削除パスを手動設定する場合チェックを入れてください。
     248                    </label>
     249                </p>
     250                <p>
     251                    <label>
     252                        Multisite Enabled:
     253                        <input type="checkbox" name="{$view['prefix']}multisite_enabled" value="1" $multisite_checked>
     254                        <br>
     255                        WordPressマルチサイト(ディレクトリ版)を利用している場合はチェックを入れてください。
     256                    </label>
     257                </p>
     258                <h2>Purge Allボタンを許可するロールを選択して下さい。</h2>
     259                $roles_checkboxes
     260            </fieldset>
     261            <p>{$view['submit_button']}</p>
     262        </div>
     263        HTML;
     264   
     265        echo '</form>';
     266    }
     267   
    218268
    219269    /**
  • purgebox/trunk/classes/class-purgebox-api.php

    r2510653 r3211793  
    8080     */
    8181    public function purge_all() {
    82         $url = '/*';
    83         $home = parse_url( home_url() );
    84         if( !empty( $home['path'] ) ) {
    85             $url = rtrim($home['path'], '/'). $url;
     82        $default_path = '/*';
     83
     84        // マルチサイト有効か確認
     85        $is_multisite_enabled = self::_get_option('multisite_enabled', '0') === '1';
     86
     87        if ($is_multisite_enabled && is_multisite()) {
     88            // 現在のサブサイトの情報を取得
     89            $details = get_blog_details(get_current_blog_id());
     90            $purge_path = rtrim($details->path, '/') . '/*';
     91        } else {
     92            // 通常サイトの場合またはマルチサイトが無効の場合
     93            $purge_path = self::_get_option('purge_path', $default_path);
    8694        }
    87         $headers = $this->_get_base_header( $url );
    88         $method = 'POST';
     95
     96        // APIを呼び出す
     97        $headers = $this->_get_base_header($purge_path);
    8998        $headers['X-TYPE'] = 'REGEX';
    90         $this->_request( $this->_base_url, array(
     99
     100        $this->_request($this->_base_url, array(
    91101            'headers' => $headers,
    92             'method' => $method
    93         ) );
     102            'method' => 'POST'
     103        ));
    94104    }
     105
     106   
    95107
    96108    /**
  • purgebox/trunk/classes/class-purgebox-plugin.php

    r1587083 r3211793  
    3737     */
    3838    protected static function _get_option( $name ) {
    39         return get_option( self::$_option_prefix. $name );
     39
     40
     41        // マルチサイトの場合、ネットワーク設定を確認
     42        if (is_multisite()) {
     43            $network_value = get_site_option('purgebox_' . $name);
     44            if ($network_value !== false && $network_value !== '') {
     45                return $network_value; // ネットワーク設定が有効ならそれを返す
     46            }
     47        }
     48
     49        // ネットワーク設定が空の場合、子サイトの設定を返す
     50        return get_option(self::$_option_prefix . $name);
     51
    4052    }
    4153
  • purgebox/trunk/purgebox.php

    r3071443 r3211793  
    55Description: REDBOX CDN Purge Plugin.
    66Author: REDBOX
    7 Version: 1.8
     7Version: 1.9
    88Author URI: https://www.redbox.ne.jp
    99License: GPL3
     
    4242        // アップデート処理の後、新しいバージョンを保存
    4343        update_option('purgebox_plugin_version', $current_version);
     44
     45        // PurgePath と MultisiteEnabled purgebox_manual_purgepath_enabledの初期値を設定
     46        $existing_purge_path = get_option('purgebox_purge_path', null);
     47        $existing_multisite_enabled = get_option('purgebox_multisite_enabled', null);
     48        $existing_manual_purgepath_enabled = get_option('purgebox_manual_purgepath_enabled', null);
     49
     50        if ($existing_purge_path === null) {
     51            update_option('purgebox_purge_path', '/*'); // デフォルト値を設定
     52        }
     53
     54        if ($existing_multisite_enabled === null) {
     55            update_option('purgebox_multisite_enabled', '0'); // デフォルト値を設定
     56        }
     57
     58        if ($existing_manual_purgepath_enabled === null) {
     59            update_option('purgebox_manual_purgepath_enabled', '0'); // デフォルト値を設定
     60        }
    4461    }
    4562}
     
    7390// プラグイン有効化時に実行される関数を登録
    7491register_activation_hook(__FILE__, 'add_purgebox_admin_role');
     92
     93
     94// ネットワーク設定ページを追加
     95add_action('network_admin_menu', function () {
     96    add_menu_page(
     97        'PurgeBox Network Settings',
     98        'PurgeBox',
     99        'manage_network',
     100        'purgebox-network-settings',
     101        'purgebox_render_network_settings_page'
     102    );
     103});
     104
     105function purgebox_render_network_settings_page() {
     106    if ($_POST['submit']) {
     107        check_admin_referer('purgebox_network_settings');
     108
     109        // 入力値を保存
     110        $api_key = isset($_POST['api_key']) ? sanitize_text_field($_POST['api_key']) : '';
     111        $group = isset($_POST['group']) ? sanitize_text_field($_POST['group']) : '';
     112        $multisite_enabled = isset($_POST['multisite_enabled']) ? '1' : '0';
     113
     114        update_site_option('purgebox_api_key', $api_key);
     115        update_site_option('purgebox_group', $group);
     116        update_site_option('purgebox_multisite_enabled', $multisite_enabled);
     117
     118        echo '<div class="updated"><p>Settings Saved!</p></div>';
     119    }
     120
     121    // 現在の設定値を取得
     122    $api_key = get_site_option('purgebox_api_key', '');
     123    $group = get_site_option('purgebox_group', '');
     124    $multisite_enabled = get_site_option('purgebox_multisite_enabled', '0');
     125    ?>
     126    <div class="wrap">
     127        <h1>PurgeBox Network Settings</h1>
     128        <form method="post">
     129            <?php wp_nonce_field('purgebox_network_settings'); ?>
     130            <table class="form-table">
     131                <tr>
     132                    <th scope="row"><label for="api_key">API Key</label></th>
     133                    <td>
     134                        <input type="text" id="api_key" name="api_key" value="<?php echo esc_attr($api_key); ?>" class="regular-text">
     135                    </td>
     136                </tr>
     137                <tr>
     138                    <th scope="row"><label for="group">Group</label></th>
     139                    <td>
     140                        <input type="text" id="group" name="group" value="<?php echo esc_attr($group); ?>" class="regular-text">
     141                    </td>
     142                </tr>
     143                <tr>
     144                    <th scope="row"><label for="multisite_enabled">Enable Multisite</label></th>
     145                    <td>
     146                        <input type="checkbox" id="multisite_enabled" name="multisite_enabled" value="1" <?php checked($multisite_enabled, '1'); ?>>
     147                        Enable multisite functionality for PurgeBox
     148                    </td>
     149                </tr>
     150            </table>
     151            <p class="submit">
     152                <input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes">
     153            </p>
     154        </form>
     155    </div>
     156    <?php
     157}
     158
     159
  • purgebox/trunk/uninstall.php

    r3071443 r3211793  
    99delete_option('purgebox_api_key');
    1010delete_option('purgebox_group');
     11delete_option('purgebox_plugin_version');
     12delete_option('purgebox_purge_path');
     13delete_option('purgebox_multisite_enabled');
     14delete_option('purgebox_manual_purgepath_enabled');
    1115
    1216function purgebox_remove_custom_capability() {
Note: See TracChangeset for help on using the changeset viewer.