Plugin Directory

Changeset 3078475


Ignore:
Timestamp:
04/29/2024 07:42:47 AM (23 months ago)
Author:
mxp
Message:

update 3.1.5

Location:
mxp-dev-tools
Files:
7 edited
18 copied

Legend:

Unmodified
Added
Removed
  • mxp-dev-tools/tags/3.1.5/includes/assets/js/db-optimize/app.js

    r3077135 r3078475  
    231231            }
    232232        });
     233        $('#go_clean_postmeta').click(function() {
     234            var yes = confirm('注意!接下來會進行對資料庫的實際操作,確保有備份好資料再進行!\n此操作針對 _postmeta 資料表中,重複的 meta_key 紀錄進行清除。');
     235            if (yes == false) {
     236                return;
     237            }
     238            $(this).text('作業中!請耐心等待,勿重新整理此頁面!');
     239            var step = $('#go_clean_postmeta').data('step');
     240            $('#go_clean_postmeta').prop('disabled', true);
     241            if (step == 1) {
     242                var data = {
     243                    'action': 'mxp_ajax_db_optimize_postmeta',
     244                    'nonce': MXP.nonce,
     245                    'step': step,
     246                };
     247                $.post(MXP.ajaxurl, data, function(res) {
     248                    if (res.success) {
     249                        console.log(res.data);
     250                        var str = '';
     251                        if (res.data !== undefined && res.data.length > 0) {
     252                            str = '<table><thead><tr><th colspan="4">清除重複的 Post Meta 資料,預設清除較舊的那筆。</th></tr></thead><tbody>';
     253                            str += '<tr><td><input type="checkbox" id="del_all_postmeta" name="del_all_postmeta" checked><label for="del_all_postmeta">全部刪除/Meta ID</label></td><td>Post ID</td><td>Meta Key</td><td>Meta Value</td></tr>';
     254                            for (var i = 0; i < res.data.length; i++) {
     255                                str += '<tr><td><input type="checkbox" class="del_postmeta_id_chk" id="del_meta_id_' + res.data[i].meta_id + '" value="' + res.data[i].meta_id + '" checked>' + res.data[i].meta_id + '</td><td>' + res.data[i].post_id + '</td><td>' + res.data[i].meta_key + '</td><td>' + res.data[i].meta_value + '<span id="res_postmeta_' + res.data[i].meta_id + '"></span></td></tr>';
     256                            }
     257                            str += '</tbody></table>';
     258                        }
     259                        if (str != '') {
     260                            $('#go_clean_postmeta_result').html('</br>' + str);
     261                            $('#del_all_postmeta').click(function() {
     262                                var checkBoxes = $("input.del_postmeta_id_chk");
     263                                checkBoxes.prop("checked", !checkBoxes.prop("checked"));
     264                            });
     265                            $('#go_clean_postmeta').data('step', 2);
     266                            $('#go_clean_postmeta').text('刪除勾選項目');
     267                        } else {
     268                            $('#go_clean_postmeta_result').html('很棒!系統是乾淨的~');
     269                            $('#go_clean_postmeta').text('取得清除清單');
     270                        }
     271                    } else {
     272                        console.log(res.data);
     273                    }
     274                    $('#go_clean_postmeta').prop('disabled', false);
     275                });
     276            }
     277            if (step == 2) {
     278                var meta_ids = [];
     279                $('input.del_postmeta_id_chk:checked').each(function() {
     280                    meta_ids.push($(this).val());
     281                });
     282                console.log(meta_ids);
     283                for (var i = 0; i < meta_ids.length; i++) {
     284                    var del = $('#del_meta_id_' + meta_ids[i]).is(":checked");
     285                    if (del) {
     286                        var tmp = [];
     287                        tmp.push(meta_ids[i]);
     288                        var ajax_options = {
     289                            method: "POST",
     290                            url: MXP.ajaxurl,
     291                            cache: false,
     292                            error: function(res) {
     293                                console.log('Error', res);
     294                            },
     295                            success: function(res) {
     296                                if (res.success) {
     297                                    console.log('success', res.data);
     298                                    if (res.data !== undefined && res.data.length > 0) {
     299                                        for (var i = 0; i < res.data.length; i++) {
     300                                            $('#res_postmeta_' + $.escapeSelector(res.data[i])).html('<del>' + res.data[i] + '</del><font color="red"> 》已清除!</font>');
     301                                        }
     302                                    }
     303                                }
     304                            },
     305                            data: {
     306                                'action': 'mxp_ajax_db_optimize_postmeta',
     307                                'nonce': MXP.nonce,
     308                                'step': step,
     309                                'meta_ids': tmp
     310                            }
     311                        };
     312                        $.ajaxQueue.addRequest(ajax_options);
     313                        $('#res_postmeta_' + $.escapeSelector(meta_ids[i])).html(meta_ids[i] + '<font color="blue"> (<strong>作業中!請耐心等待,勿重新整理此頁面!</strong>)</font>');
     314                    } else {
     315                        $('#res_postmeta_' + $.escapeSelector(meta_ids[i])).html(meta_ids[i] + '<font color="orange"> (<strong>本次作業不處理!</strong>)</font>');
     316                    }
     317                }
     318                $.ajaxQueue.run();
     319                $('#go_clean_postmeta').text('清除中...請勿重新整理頁面。');
     320            }
     321        });
     322        $('#go_clean_usermeta').click(function() {
     323            var yes = confirm('注意!接下來會進行對資料庫的實際操作,確保有備份好資料再進行!\n此操作針對 _usermeta 資料表中,重複的 meta_key 紀錄進行清除。');
     324            if (yes == false) {
     325                return;
     326            }
     327            $(this).text('作業中!請耐心等待,勿重新整理此頁面!');
     328            var step = $('#go_clean_usermeta').data('step');
     329            $('#go_clean_usermeta').prop('disabled', true);
     330            if (step == 1) {
     331                var data = {
     332                    'action': 'mxp_ajax_db_optimize_usermeta',
     333                    'nonce': MXP.nonce,
     334                    'step': step,
     335                };
     336                $.post(MXP.ajaxurl, data, function(res) {
     337                    if (res.success) {
     338                        console.log(res.data);
     339                        var str = '';
     340                        if (res.data !== undefined && res.data.length > 0) {
     341                            str = '<table><thead><tr><th colspan="4">清除重複的 User Meta 資料,預設清除較舊的那筆。</th></tr></thead><tbody>';
     342                            str += '<tr><td><input type="checkbox" id="del_all_usermeta" name="del_all_usermeta" checked><label for="del_all_usermeta">全部刪除/Meta ID</label></td><td>User ID</td><td>Meta Key</td><td>Meta Value</td></tr>';
     343                            for (var i = 0; i < res.data.length; i++) {
     344                                str += '<tr><td><input type="checkbox" class="del_usermeta_id_chk" id="del_meta_id_' + res.data[i].umeta_id + '" value="' + res.data[i].umeta_id + '" checked>' + res.data[i].umeta_id + '</td><td>' + res.data[i].user_id + '</td><td>' + res.data[i].meta_key + '</td><td>' + res.data[i].meta_value + '<span id="res_usermeta_' + res.data[i].umeta_id + '"></span></td></tr>';
     345                            }
     346                            str += '</tbody></table>';
     347                        }
     348                        if (str != '') {
     349                            $('#go_clean_usermeta_result').html('</br>' + str);
     350                            $('#del_all_usermeta').click(function() {
     351                                var checkBoxes = $("input.del_usermeta_id_chk");
     352                                checkBoxes.prop("checked", !checkBoxes.prop("checked"));
     353                            });
     354                            $('#go_clean_usermeta').data('step', 2);
     355                            $('#go_clean_usermeta').text('刪除勾選項目');
     356                        } else {
     357                            $('#go_clean_usermeta_result').html('很棒!系統是乾淨的~');
     358                            $('#go_clean_usermeta').text('取得清除清單');
     359                        }
     360                    } else {
     361                        console.log(res.data);
     362                    }
     363                    $('#go_clean_usermeta').prop('disabled', false);
     364                });
     365            }
     366            if (step == 2) {
     367                var meta_ids = [];
     368                $('input.del_usermeta_id_chk:checked').each(function() {
     369                    meta_ids.push($(this).val());
     370                });
     371                console.log(meta_ids);
     372                for (var i = 0; i < meta_ids.length; i++) {
     373                    var del = $('#del_meta_id_' + meta_ids[i]).is(":checked");
     374                    if (del) {
     375                        var tmp = [];
     376                        tmp.push(meta_ids[i]);
     377                        var ajax_options = {
     378                            method: "POST",
     379                            url: MXP.ajaxurl,
     380                            cache: false,
     381                            error: function(res) {
     382                                console.log('Error', res);
     383                            },
     384                            success: function(res) {
     385                                if (res.success) {
     386                                    console.log('success', res.data);
     387                                    if (res.data !== undefined && res.data.length > 0) {
     388                                        for (var i = 0; i < res.data.length; i++) {
     389                                            $('#res_usermeta_' + $.escapeSelector(res.data[i])).html('<del>' + res.data[i] + '</del><font color="red"> 》已清除!</font>');
     390                                        }
     391                                    }
     392                                }
     393                            },
     394                            data: {
     395                                'action': 'mxp_ajax_db_optimize_usermeta',
     396                                'nonce': MXP.nonce,
     397                                'step': step,
     398                                'meta_ids': tmp
     399                            }
     400                        };
     401                        $.ajaxQueue.addRequest(ajax_options);
     402                        $('#res_usermeta_' + $.escapeSelector(meta_ids[i])).html(meta_ids[i] + '<font color="blue"> (<strong>作業中!請耐心等待,勿重新整理此頁面!</strong>)</font>');
     403                    } else {
     404                        $('#res_usermeta_' + $.escapeSelector(meta_ids[i])).html(meta_ids[i] + '<font color="orange"> (<strong>本次作業不處理!</strong>)</font>');
     405                    }
     406                }
     407                $.ajaxQueue.run();
     408                $('#go_clean_postmeta').text('清除中...請勿重新整理頁面。');
     409            }
     410        });
    233411        $('#go_reset_wp').click(function() {
    234412            var yes = confirm('你確定知道自己正在將網站內容全部清除重新建置嗎?');
  • mxp-dev-tools/tags/3.1.5/includes/db-optimize.php

    r3077135 r3078475  
    13711371        }
    13721372    }
     1373
     1374    public function mxp_ajax_db_optimize_postmeta() {
     1375        set_time_limit(0);
     1376        if (!isset($_REQUEST['step']) || (intval($_REQUEST['step']) != 1 && intval($_REQUEST['step']) != 2)) {
     1377            wp_send_json_error('請求參數有誤!');
     1378        }
     1379        $step     = sanitize_text_field($_REQUEST['step']);
     1380        $meta_ids = isset($_REQUEST['meta_ids']) ? $_REQUEST['meta_ids'] : '';
     1381        if (!empty($meta_ids) && !is_array($meta_ids)) {
     1382            wp_send_json_error('請求參數有誤!');
     1383        }
     1384        if (!isset($_REQUEST['nonce']) || !wp_verify_nonce($_REQUEST['nonce'], 'mxp-ajax-nonce-for-db-optimize')) {
     1385            wp_send_json_error('請求驗證有誤!');
     1386        }
     1387        global $wpdb;
     1388        if ($step == 1) {
     1389            $result = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}postmeta WHERE meta_id NOT IN ( SELECT * FROM ( SELECT MAX(meta_id) FROM {$wpdb->prefix}postmeta GROUP BY post_id, meta_key ) AS x)", ARRAY_A);
     1390            foreach ($result as $index => $item) {
     1391                $result[$index]['meta_value'] = esc_html($item['meta_value']);
     1392            }
     1393            wp_send_json_success($result);
     1394        }
     1395        if ($step == 2) {
     1396            $success = array();
     1397            foreach ($meta_ids as $key => $meta_id) {
     1398                $del = $wpdb->delete(
     1399                    $wpdb->prefix . 'postmeta',
     1400                    array('meta_id' => $meta_id),
     1401                    array('%d')
     1402                );
     1403                if ($del) {
     1404                    $success[] = $meta_id;
     1405                }
     1406            }
     1407            wp_send_json_success($success);
     1408        }
     1409        wp_send_json_error('請求方法有誤!');
     1410    }
     1411
     1412    public function mxp_ajax_db_optimize_usermeta() {
     1413        set_time_limit(0);
     1414        if (!isset($_REQUEST['step']) || (intval($_REQUEST['step']) != 1 && intval($_REQUEST['step']) != 2)) {
     1415            wp_send_json_error('請求參數有誤!');
     1416        }
     1417        $step     = sanitize_text_field($_REQUEST['step']);
     1418        $meta_ids = isset($_REQUEST['meta_ids']) ? $_REQUEST['meta_ids'] : '';
     1419        if (!empty($meta_ids) && !is_array($meta_ids)) {
     1420            wp_send_json_error('請求參數有誤!');
     1421        }
     1422        if (!isset($_REQUEST['nonce']) || !wp_verify_nonce($_REQUEST['nonce'], 'mxp-ajax-nonce-for-db-optimize')) {
     1423            wp_send_json_error('請求驗證有誤!');
     1424        }
     1425        global $wpdb;
     1426        if ($step == 1) {
     1427            $result = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}usermeta WHERE umeta_id NOT IN ( SELECT * FROM ( SELECT MAX(umeta_id) FROM {$wpdb->prefix}usermeta GROUP BY user_id, meta_key ) AS x)", ARRAY_A);
     1428            foreach ($result as $index => $item) {
     1429                $result[$index]['meta_value'] = esc_html($item['meta_value']);
     1430            }
     1431            wp_send_json_success($result);
     1432        }
     1433        if ($step == 2) {
     1434            $success = array();
     1435            foreach ($meta_ids as $key => $umeta_id) {
     1436                $del = $wpdb->delete(
     1437                    $wpdb->prefix . 'usermeta',
     1438                    array('umeta_id' => $umeta_id),
     1439                    array('%d')
     1440                );
     1441                if ($del) {
     1442                    $success[] = $umeta_id;
     1443                }
     1444            }
     1445            wp_send_json_success($success);
     1446        }
     1447        wp_send_json_error('請求方法有誤!');
     1448    }
     1449
    13731450    public function mxp_ajax_clean_orphan() {
    13741451        if (!isset($_REQUEST['type']) || $_REQUEST['type'] == '') {
  • mxp-dev-tools/tags/3.1.5/index.php

    r3077135 r3078475  
    44 * Plugin URI: https://goo.gl/2gLq18
    55 * Description: 一介資男の常用外掛整理與常用開發功能整合外掛。
    6  * Version: 3.1.4
     6 * Version: 3.1.5
    77 * Author: Chun
    88 * Author URI: https://www.mxp.tw/contact/
     
    3535    use SearchReplace;
    3636    use Utility;
    37     static $VERSION                   = '3.1.4';
     37    static $VERSION                   = '3.1.5';
    3838    private $themeforest_api_base_url = 'https://api.envato.com/v3';
    3939    protected static $instance        = null;
     
    6767        add_action('wp_ajax_mxp_background_pack_batch_mode', array($this, 'mxp_ajax_background_pack_action_batch_mode'));
    6868        add_action('wp_ajax_mxp_ajax_db_optimize', array($this, 'mxp_ajax_db_optimize'));
     69        add_action('wp_ajax_mxp_ajax_db_optimize_postmeta', array($this, 'mxp_ajax_db_optimize_postmeta'));
     70        add_action('wp_ajax_mxp_ajax_db_optimize_usermeta', array($this, 'mxp_ajax_db_optimize_usermeta'));
    6971        add_action('wp_ajax_mxp_ajax_clean_orphan', array($this, 'mxp_ajax_clean_orphan'));
    7072        add_action('wp_ajax_mxp_ajax_clean_mxpdev', array($this, 'mxp_ajax_clean_mxpdev'));
     
    261263            echo '<button id="go_clean_options" data-step="1" type="button" class="button button-primary">取得清除清單</button></br>';
    262264            echo '<div id="go_clean_options_result"></div></br>';
     265            echo '<h3>清除重複的 Post Meta</h3>';
     266            echo '<button id="go_clean_postmeta" data-step="1" type="button" class="button button-primary">取得清除清單</button></br>';
     267            echo '<div id="go_clean_postmeta_result"></div></br>';
     268            echo '<h3>清除重複的 User Meta</h3>';
     269            echo '<button id="go_clean_usermeta" data-step="1" type="button" class="button button-primary">取得清除清單</button></br>';
     270            echo '<div id="go_clean_usermeta_result"></div></br>';
    263271            echo '<h3>清除孤立的 Post/Comment Meta 資料</h3>';
    264272            echo '<p>不論是手動刪除或是外掛刪除內容,可能沒連帶刪除的 Meta 關聯資料,堆積在資料庫裡變成垃圾。</p>';
  • mxp-dev-tools/tags/3.1.5/mxp-login-path.php

    r3077135 r3078475  
    44 * Plugin URI: https://tw.wordpress.org/plugins/mxp-dev-tools/
    55 * Description: 隱藏後台登入位置工具。啟用即更改預設登入網址為 /admin-staff/
    6  * Version: 3.1.4
     6 * Version: 3.1.5
    77 * Author: Chun
    88 * Author URI: https://www.mxp.tw/contact/
  • mxp-dev-tools/tags/3.1.5/mxp-site-manager.php

    r3077135 r3078475  
    44 * Plugin URI: https://tw.wordpress.org/plugins/mxp-dev-tools/
    55 * Description: 管理多個 WordPress 站點的工具。
    6  * Version: 3.1.4
     6 * Version: 3.1.5
    77 * Author: Chun
    88 * Author URI: https://www.mxp.tw/contact/
     
    3535class MDTSiteManager {
    3636    public $plugin_slug    = 'mdt-site-manager';
    37     public static $VERSION = '3.1.4';
     37    public static $VERSION = '3.1.5';
    3838
    3939    public function __construct() {
  • mxp-dev-tools/tags/3.1.5/mxp-snippets.php

    r3077135 r3078475  
    44 * Plugin URI: https://tw.wordpress.org/plugins/mxp-dev-tools/
    55 * Description: 整合 GitHub 中常用的程式碼片段。請注意,並非所有網站都適用全部的選項,有進階需求可以透過設定 wp-config.php 中此外掛預設常數,啟用或停用部分功能。
    6  * Version: 3.1.4
     6 * Version: 3.1.5
    77 * Author: Chun
    88 * Author URI: https://www.mxp.tw/contact/
  • mxp-dev-tools/tags/3.1.5/readme.txt

    r3077135 r3078475  
    66Requires PHP: 5.6
    77Tested up to: 6.5
    8 Stable tag: 3.1.4
     8Stable tag: 3.1.5
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    47471. 上傳外掛至外掛目錄 `wp-content/plugins/` 下。 Upload the plugin files to the `/wp-content/plugins/` directory
    48482. 於後台外掛功能處啟動外掛。 Activate the plugin through the 'Plugins' screen in WordPress
    49 3. 啟用後在後台選單可找到「FB工具箱設定」進行參數調整。 Use the 「FB工具箱設定」 screen to configure the plugin
     493. 啟用後在後台選單可找到「開發工具箱設定」進行參數調整。 Use the 「開發工具箱設定」 screen to configure the plugin
    50504. 完成。 Done
    5151
     
    7878
    7979== Changelog ==
     80
     81= 3.1.5 =
     82
     83* 新增清除重複 User/Post Meta 資料的最佳化資料庫的功能,參考:  [Cleanup Duplicate Meta](https://tw.wordpress.org/plugins/cleanup-duplicate-meta/)
    8084
    8185= 3.1.4 =
  • mxp-dev-tools/trunk/includes/assets/js/db-optimize/app.js

    r3077135 r3078475  
    231231            }
    232232        });
     233        $('#go_clean_postmeta').click(function() {
     234            var yes = confirm('注意!接下來會進行對資料庫的實際操作,確保有備份好資料再進行!\n此操作針對 _postmeta 資料表中,重複的 meta_key 紀錄進行清除。');
     235            if (yes == false) {
     236                return;
     237            }
     238            $(this).text('作業中!請耐心等待,勿重新整理此頁面!');
     239            var step = $('#go_clean_postmeta').data('step');
     240            $('#go_clean_postmeta').prop('disabled', true);
     241            if (step == 1) {
     242                var data = {
     243                    'action': 'mxp_ajax_db_optimize_postmeta',
     244                    'nonce': MXP.nonce,
     245                    'step': step,
     246                };
     247                $.post(MXP.ajaxurl, data, function(res) {
     248                    if (res.success) {
     249                        console.log(res.data);
     250                        var str = '';
     251                        if (res.data !== undefined && res.data.length > 0) {
     252                            str = '<table><thead><tr><th colspan="4">清除重複的 Post Meta 資料,預設清除較舊的那筆。</th></tr></thead><tbody>';
     253                            str += '<tr><td><input type="checkbox" id="del_all_postmeta" name="del_all_postmeta" checked><label for="del_all_postmeta">全部刪除/Meta ID</label></td><td>Post ID</td><td>Meta Key</td><td>Meta Value</td></tr>';
     254                            for (var i = 0; i < res.data.length; i++) {
     255                                str += '<tr><td><input type="checkbox" class="del_postmeta_id_chk" id="del_meta_id_' + res.data[i].meta_id + '" value="' + res.data[i].meta_id + '" checked>' + res.data[i].meta_id + '</td><td>' + res.data[i].post_id + '</td><td>' + res.data[i].meta_key + '</td><td>' + res.data[i].meta_value + '<span id="res_postmeta_' + res.data[i].meta_id + '"></span></td></tr>';
     256                            }
     257                            str += '</tbody></table>';
     258                        }
     259                        if (str != '') {
     260                            $('#go_clean_postmeta_result').html('</br>' + str);
     261                            $('#del_all_postmeta').click(function() {
     262                                var checkBoxes = $("input.del_postmeta_id_chk");
     263                                checkBoxes.prop("checked", !checkBoxes.prop("checked"));
     264                            });
     265                            $('#go_clean_postmeta').data('step', 2);
     266                            $('#go_clean_postmeta').text('刪除勾選項目');
     267                        } else {
     268                            $('#go_clean_postmeta_result').html('很棒!系統是乾淨的~');
     269                            $('#go_clean_postmeta').text('取得清除清單');
     270                        }
     271                    } else {
     272                        console.log(res.data);
     273                    }
     274                    $('#go_clean_postmeta').prop('disabled', false);
     275                });
     276            }
     277            if (step == 2) {
     278                var meta_ids = [];
     279                $('input.del_postmeta_id_chk:checked').each(function() {
     280                    meta_ids.push($(this).val());
     281                });
     282                console.log(meta_ids);
     283                for (var i = 0; i < meta_ids.length; i++) {
     284                    var del = $('#del_meta_id_' + meta_ids[i]).is(":checked");
     285                    if (del) {
     286                        var tmp = [];
     287                        tmp.push(meta_ids[i]);
     288                        var ajax_options = {
     289                            method: "POST",
     290                            url: MXP.ajaxurl,
     291                            cache: false,
     292                            error: function(res) {
     293                                console.log('Error', res);
     294                            },
     295                            success: function(res) {
     296                                if (res.success) {
     297                                    console.log('success', res.data);
     298                                    if (res.data !== undefined && res.data.length > 0) {
     299                                        for (var i = 0; i < res.data.length; i++) {
     300                                            $('#res_postmeta_' + $.escapeSelector(res.data[i])).html('<del>' + res.data[i] + '</del><font color="red"> 》已清除!</font>');
     301                                        }
     302                                    }
     303                                }
     304                            },
     305                            data: {
     306                                'action': 'mxp_ajax_db_optimize_postmeta',
     307                                'nonce': MXP.nonce,
     308                                'step': step,
     309                                'meta_ids': tmp
     310                            }
     311                        };
     312                        $.ajaxQueue.addRequest(ajax_options);
     313                        $('#res_postmeta_' + $.escapeSelector(meta_ids[i])).html(meta_ids[i] + '<font color="blue"> (<strong>作業中!請耐心等待,勿重新整理此頁面!</strong>)</font>');
     314                    } else {
     315                        $('#res_postmeta_' + $.escapeSelector(meta_ids[i])).html(meta_ids[i] + '<font color="orange"> (<strong>本次作業不處理!</strong>)</font>');
     316                    }
     317                }
     318                $.ajaxQueue.run();
     319                $('#go_clean_postmeta').text('清除中...請勿重新整理頁面。');
     320            }
     321        });
     322        $('#go_clean_usermeta').click(function() {
     323            var yes = confirm('注意!接下來會進行對資料庫的實際操作,確保有備份好資料再進行!\n此操作針對 _usermeta 資料表中,重複的 meta_key 紀錄進行清除。');
     324            if (yes == false) {
     325                return;
     326            }
     327            $(this).text('作業中!請耐心等待,勿重新整理此頁面!');
     328            var step = $('#go_clean_usermeta').data('step');
     329            $('#go_clean_usermeta').prop('disabled', true);
     330            if (step == 1) {
     331                var data = {
     332                    'action': 'mxp_ajax_db_optimize_usermeta',
     333                    'nonce': MXP.nonce,
     334                    'step': step,
     335                };
     336                $.post(MXP.ajaxurl, data, function(res) {
     337                    if (res.success) {
     338                        console.log(res.data);
     339                        var str = '';
     340                        if (res.data !== undefined && res.data.length > 0) {
     341                            str = '<table><thead><tr><th colspan="4">清除重複的 User Meta 資料,預設清除較舊的那筆。</th></tr></thead><tbody>';
     342                            str += '<tr><td><input type="checkbox" id="del_all_usermeta" name="del_all_usermeta" checked><label for="del_all_usermeta">全部刪除/Meta ID</label></td><td>User ID</td><td>Meta Key</td><td>Meta Value</td></tr>';
     343                            for (var i = 0; i < res.data.length; i++) {
     344                                str += '<tr><td><input type="checkbox" class="del_usermeta_id_chk" id="del_meta_id_' + res.data[i].umeta_id + '" value="' + res.data[i].umeta_id + '" checked>' + res.data[i].umeta_id + '</td><td>' + res.data[i].user_id + '</td><td>' + res.data[i].meta_key + '</td><td>' + res.data[i].meta_value + '<span id="res_usermeta_' + res.data[i].umeta_id + '"></span></td></tr>';
     345                            }
     346                            str += '</tbody></table>';
     347                        }
     348                        if (str != '') {
     349                            $('#go_clean_usermeta_result').html('</br>' + str);
     350                            $('#del_all_usermeta').click(function() {
     351                                var checkBoxes = $("input.del_usermeta_id_chk");
     352                                checkBoxes.prop("checked", !checkBoxes.prop("checked"));
     353                            });
     354                            $('#go_clean_usermeta').data('step', 2);
     355                            $('#go_clean_usermeta').text('刪除勾選項目');
     356                        } else {
     357                            $('#go_clean_usermeta_result').html('很棒!系統是乾淨的~');
     358                            $('#go_clean_usermeta').text('取得清除清單');
     359                        }
     360                    } else {
     361                        console.log(res.data);
     362                    }
     363                    $('#go_clean_usermeta').prop('disabled', false);
     364                });
     365            }
     366            if (step == 2) {
     367                var meta_ids = [];
     368                $('input.del_usermeta_id_chk:checked').each(function() {
     369                    meta_ids.push($(this).val());
     370                });
     371                console.log(meta_ids);
     372                for (var i = 0; i < meta_ids.length; i++) {
     373                    var del = $('#del_meta_id_' + meta_ids[i]).is(":checked");
     374                    if (del) {
     375                        var tmp = [];
     376                        tmp.push(meta_ids[i]);
     377                        var ajax_options = {
     378                            method: "POST",
     379                            url: MXP.ajaxurl,
     380                            cache: false,
     381                            error: function(res) {
     382                                console.log('Error', res);
     383                            },
     384                            success: function(res) {
     385                                if (res.success) {
     386                                    console.log('success', res.data);
     387                                    if (res.data !== undefined && res.data.length > 0) {
     388                                        for (var i = 0; i < res.data.length; i++) {
     389                                            $('#res_usermeta_' + $.escapeSelector(res.data[i])).html('<del>' + res.data[i] + '</del><font color="red"> 》已清除!</font>');
     390                                        }
     391                                    }
     392                                }
     393                            },
     394                            data: {
     395                                'action': 'mxp_ajax_db_optimize_usermeta',
     396                                'nonce': MXP.nonce,
     397                                'step': step,
     398                                'meta_ids': tmp
     399                            }
     400                        };
     401                        $.ajaxQueue.addRequest(ajax_options);
     402                        $('#res_usermeta_' + $.escapeSelector(meta_ids[i])).html(meta_ids[i] + '<font color="blue"> (<strong>作業中!請耐心等待,勿重新整理此頁面!</strong>)</font>');
     403                    } else {
     404                        $('#res_usermeta_' + $.escapeSelector(meta_ids[i])).html(meta_ids[i] + '<font color="orange"> (<strong>本次作業不處理!</strong>)</font>');
     405                    }
     406                }
     407                $.ajaxQueue.run();
     408                $('#go_clean_postmeta').text('清除中...請勿重新整理頁面。');
     409            }
     410        });
    233411        $('#go_reset_wp').click(function() {
    234412            var yes = confirm('你確定知道自己正在將網站內容全部清除重新建置嗎?');
  • mxp-dev-tools/trunk/includes/db-optimize.php

    r3077135 r3078475  
    13711371        }
    13721372    }
     1373
     1374    public function mxp_ajax_db_optimize_postmeta() {
     1375        set_time_limit(0);
     1376        if (!isset($_REQUEST['step']) || (intval($_REQUEST['step']) != 1 && intval($_REQUEST['step']) != 2)) {
     1377            wp_send_json_error('請求參數有誤!');
     1378        }
     1379        $step     = sanitize_text_field($_REQUEST['step']);
     1380        $meta_ids = isset($_REQUEST['meta_ids']) ? $_REQUEST['meta_ids'] : '';
     1381        if (!empty($meta_ids) && !is_array($meta_ids)) {
     1382            wp_send_json_error('請求參數有誤!');
     1383        }
     1384        if (!isset($_REQUEST['nonce']) || !wp_verify_nonce($_REQUEST['nonce'], 'mxp-ajax-nonce-for-db-optimize')) {
     1385            wp_send_json_error('請求驗證有誤!');
     1386        }
     1387        global $wpdb;
     1388        if ($step == 1) {
     1389            $result = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}postmeta WHERE meta_id NOT IN ( SELECT * FROM ( SELECT MAX(meta_id) FROM {$wpdb->prefix}postmeta GROUP BY post_id, meta_key ) AS x)", ARRAY_A);
     1390            foreach ($result as $index => $item) {
     1391                $result[$index]['meta_value'] = esc_html($item['meta_value']);
     1392            }
     1393            wp_send_json_success($result);
     1394        }
     1395        if ($step == 2) {
     1396            $success = array();
     1397            foreach ($meta_ids as $key => $meta_id) {
     1398                $del = $wpdb->delete(
     1399                    $wpdb->prefix . 'postmeta',
     1400                    array('meta_id' => $meta_id),
     1401                    array('%d')
     1402                );
     1403                if ($del) {
     1404                    $success[] = $meta_id;
     1405                }
     1406            }
     1407            wp_send_json_success($success);
     1408        }
     1409        wp_send_json_error('請求方法有誤!');
     1410    }
     1411
     1412    public function mxp_ajax_db_optimize_usermeta() {
     1413        set_time_limit(0);
     1414        if (!isset($_REQUEST['step']) || (intval($_REQUEST['step']) != 1 && intval($_REQUEST['step']) != 2)) {
     1415            wp_send_json_error('請求參數有誤!');
     1416        }
     1417        $step     = sanitize_text_field($_REQUEST['step']);
     1418        $meta_ids = isset($_REQUEST['meta_ids']) ? $_REQUEST['meta_ids'] : '';
     1419        if (!empty($meta_ids) && !is_array($meta_ids)) {
     1420            wp_send_json_error('請求參數有誤!');
     1421        }
     1422        if (!isset($_REQUEST['nonce']) || !wp_verify_nonce($_REQUEST['nonce'], 'mxp-ajax-nonce-for-db-optimize')) {
     1423            wp_send_json_error('請求驗證有誤!');
     1424        }
     1425        global $wpdb;
     1426        if ($step == 1) {
     1427            $result = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}usermeta WHERE umeta_id NOT IN ( SELECT * FROM ( SELECT MAX(umeta_id) FROM {$wpdb->prefix}usermeta GROUP BY user_id, meta_key ) AS x)", ARRAY_A);
     1428            foreach ($result as $index => $item) {
     1429                $result[$index]['meta_value'] = esc_html($item['meta_value']);
     1430            }
     1431            wp_send_json_success($result);
     1432        }
     1433        if ($step == 2) {
     1434            $success = array();
     1435            foreach ($meta_ids as $key => $umeta_id) {
     1436                $del = $wpdb->delete(
     1437                    $wpdb->prefix . 'usermeta',
     1438                    array('umeta_id' => $umeta_id),
     1439                    array('%d')
     1440                );
     1441                if ($del) {
     1442                    $success[] = $umeta_id;
     1443                }
     1444            }
     1445            wp_send_json_success($success);
     1446        }
     1447        wp_send_json_error('請求方法有誤!');
     1448    }
     1449
    13731450    public function mxp_ajax_clean_orphan() {
    13741451        if (!isset($_REQUEST['type']) || $_REQUEST['type'] == '') {
  • mxp-dev-tools/trunk/index.php

    r3077135 r3078475  
    44 * Plugin URI: https://goo.gl/2gLq18
    55 * Description: 一介資男の常用外掛整理與常用開發功能整合外掛。
    6  * Version: 3.1.4
     6 * Version: 3.1.5
    77 * Author: Chun
    88 * Author URI: https://www.mxp.tw/contact/
     
    3535    use SearchReplace;
    3636    use Utility;
    37     static $VERSION                   = '3.1.4';
     37    static $VERSION                   = '3.1.5';
    3838    private $themeforest_api_base_url = 'https://api.envato.com/v3';
    3939    protected static $instance        = null;
     
    6767        add_action('wp_ajax_mxp_background_pack_batch_mode', array($this, 'mxp_ajax_background_pack_action_batch_mode'));
    6868        add_action('wp_ajax_mxp_ajax_db_optimize', array($this, 'mxp_ajax_db_optimize'));
     69        add_action('wp_ajax_mxp_ajax_db_optimize_postmeta', array($this, 'mxp_ajax_db_optimize_postmeta'));
     70        add_action('wp_ajax_mxp_ajax_db_optimize_usermeta', array($this, 'mxp_ajax_db_optimize_usermeta'));
    6971        add_action('wp_ajax_mxp_ajax_clean_orphan', array($this, 'mxp_ajax_clean_orphan'));
    7072        add_action('wp_ajax_mxp_ajax_clean_mxpdev', array($this, 'mxp_ajax_clean_mxpdev'));
     
    261263            echo '<button id="go_clean_options" data-step="1" type="button" class="button button-primary">取得清除清單</button></br>';
    262264            echo '<div id="go_clean_options_result"></div></br>';
     265            echo '<h3>清除重複的 Post Meta</h3>';
     266            echo '<button id="go_clean_postmeta" data-step="1" type="button" class="button button-primary">取得清除清單</button></br>';
     267            echo '<div id="go_clean_postmeta_result"></div></br>';
     268            echo '<h3>清除重複的 User Meta</h3>';
     269            echo '<button id="go_clean_usermeta" data-step="1" type="button" class="button button-primary">取得清除清單</button></br>';
     270            echo '<div id="go_clean_usermeta_result"></div></br>';
    263271            echo '<h3>清除孤立的 Post/Comment Meta 資料</h3>';
    264272            echo '<p>不論是手動刪除或是外掛刪除內容,可能沒連帶刪除的 Meta 關聯資料,堆積在資料庫裡變成垃圾。</p>';
  • mxp-dev-tools/trunk/mxp-login-path.php

    r3077135 r3078475  
    44 * Plugin URI: https://tw.wordpress.org/plugins/mxp-dev-tools/
    55 * Description: 隱藏後台登入位置工具。啟用即更改預設登入網址為 /admin-staff/
    6  * Version: 3.1.4
     6 * Version: 3.1.5
    77 * Author: Chun
    88 * Author URI: https://www.mxp.tw/contact/
  • mxp-dev-tools/trunk/mxp-site-manager.php

    r3077135 r3078475  
    44 * Plugin URI: https://tw.wordpress.org/plugins/mxp-dev-tools/
    55 * Description: 管理多個 WordPress 站點的工具。
    6  * Version: 3.1.4
     6 * Version: 3.1.5
    77 * Author: Chun
    88 * Author URI: https://www.mxp.tw/contact/
     
    3535class MDTSiteManager {
    3636    public $plugin_slug    = 'mdt-site-manager';
    37     public static $VERSION = '3.1.4';
     37    public static $VERSION = '3.1.5';
    3838
    3939    public function __construct() {
  • mxp-dev-tools/trunk/mxp-snippets.php

    r3077135 r3078475  
    44 * Plugin URI: https://tw.wordpress.org/plugins/mxp-dev-tools/
    55 * Description: 整合 GitHub 中常用的程式碼片段。請注意,並非所有網站都適用全部的選項,有進階需求可以透過設定 wp-config.php 中此外掛預設常數,啟用或停用部分功能。
    6  * Version: 3.1.4
     6 * Version: 3.1.5
    77 * Author: Chun
    88 * Author URI: https://www.mxp.tw/contact/
  • mxp-dev-tools/trunk/readme.txt

    r3077135 r3078475  
    66Requires PHP: 5.6
    77Tested up to: 6.5
    8 Stable tag: 3.1.4
     8Stable tag: 3.1.5
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    47471. 上傳外掛至外掛目錄 `wp-content/plugins/` 下。 Upload the plugin files to the `/wp-content/plugins/` directory
    48482. 於後台外掛功能處啟動外掛。 Activate the plugin through the 'Plugins' screen in WordPress
    49 3. 啟用後在後台選單可找到「FB工具箱設定」進行參數調整。 Use the 「FB工具箱設定」 screen to configure the plugin
     493. 啟用後在後台選單可找到「開發工具箱設定」進行參數調整。 Use the 「開發工具箱設定」 screen to configure the plugin
    50504. 完成。 Done
    5151
     
    7878
    7979== Changelog ==
     80
     81= 3.1.5 =
     82
     83* 新增清除重複 User/Post Meta 資料的最佳化資料庫的功能,參考:  [Cleanup Duplicate Meta](https://tw.wordpress.org/plugins/cleanup-duplicate-meta/)
    8084
    8185= 3.1.4 =
Note: See TracChangeset for help on using the changeset viewer.