Plugin Directory

Changeset 2628264


Ignore:
Timestamp:
11/11/2021 07:47:43 PM (4 years ago)
Author:
paulswarthout
Message:

Bug fixes, code clean-up, testing with the latest version of WordPress 5.8.2.

Location:
child-themes-helper/trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • child-themes-helper/trunk/child-themes-helper.php

    r2544671 r2628264  
    22/*
    33    Plugin Name: Child Themes Helper
    4     Plugin URI: http://www.paulswarthout.com/Child-Themes-Helper/
     4    Plugin URI: https://www.paulswarthout.com/Child-Themes-Helper/
    55    Description: Tool to aid the child theme developer. Copies files from the parent theme to the child theme, duplicating the folder structure in the child theme. Directly edit the child theme's files. Create a new child theme from any template theme.
    6     Version: 2.2.2
     6    Version: 2.2.4
    77    Author: Paul A. Swarthout
    8     Author URI: http://www.PaulSwarthout.com
     8    Author URI: https://www.PaulSwarthout.com
    99    License: GPL2
    1010    License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    158158if (defined("DEMO_CAPABILITY")) { add_action( 'init',   'pas_cth_no_profile_access' ); }
    159159
    160 add_action( 'wp_footer','pas_cth_flushBuffer' );        // Response Buffering
     160add_action( 'wp_footer', __NAMESPACE__ . '\pas_cth_flushBuffer' );      // Response Buffering
    161161
    162162/* AJAX PHP functions may be found in the 'classes/class_ajax_functions.php' file
     
    229229}
    230230
    231 register_deactivation_hook( __FILE__, 'pas_cth_deactivate' );//Plugin Deactivation
     231register_deactivation_hook( __FILE__, __NAMESPACE__ . '\pas_cth_deactivate' );//Plugin Deactivation
    232232
    233233
  • child-themes-helper/trunk/classes/class_childThemesHelper.php

    r2544661 r2628264  
    288288The Child Theme Helper plugin was created because I, the developer of {$abbr} would invariably screw it up and my child theme would not work and I would spend hours trying to figure out why.
    289289<br><br>
    290 <h3>The Child Themes Helper plugin has 4 areas of primary functionality.</h3> For more information on each of these, review the information at the top of each tab.
     290<h3>The Child Themes Helper plugin has 4 areas of primary functionality.</h3> For more information on each of these, review the information at the top of eachBookWriter.tab.
    291291<ol>
    292292    <li>Create a new child theme from any of the template themes installed on your website. {$abbr} requires the child theme to exist before you can copy files to it.</li>
     
    304304This selection <u>does not</u> change which theme is activated. It only specifies to {$abbr} which child/parent theme that it should manipulate.
    305305<br><br>
    306 Once selected, the page will reload and you will be on the Copy/Edit Theme Files tab.
     306Once selected, the page will reload and you will be on the Copy/Edit Theme FilesBookWriter.tab.
    307307
    308308
  • child-themes-helper/trunk/css/style.css

    r2074973 r2628264  
    4949  padding: 20px;
    5050  text-align: left;
     51  margin-bottom:50px;
    5152}
    5253.pas-grid-item-child {
  • child-themes-helper/trunk/js/class-my-spinner.js

    r2544671 r2628264  
    55    }
    66    wait_cursor() {
    7         debugger
    87        var spinner;
    98        var self = this;
    109        if (this.wait_cursor_count == 0) {
    1110            spinner = this.showSpinner();
    12             spinner.onclick = function () { toc_common.default_cursor(); self.wait_cursor_count = 0; }
     11            spinner.onclick = function () { self.self.default_cursor(); self.wait_cursor_count = 0; }
    1312        }
    1413        this.wait_cursor_count++;
  • child-themes-helper/trunk/js/edit_file.js

    r2544661 r2628264  
    7272}
    7373function pas_cth_js_editFile(event) {
     74    pas_cth_spinner.wait_cursor();
     75
    7476    var element = document.getElementById(event.srcElement.dataset.elementid);
    7577    var dataBlock = {};
     
    8688            "</div>";
    8789        pas_cth_js_createBox("invalidFileTypeMessage", "", document.getElementsByTagName("body")[0], true).innerHTML += msg;
     90        pas_cth_spinner.default_cursor();
    8891        return;
    8992    }
     
    253256    var fileContents = "";
    254257    var dataBlock = {};
     258   
     259    pas_cth_spinner.wait_cursor();
     260
    255261    fileContents = ee.editBox.innerText; // .replace(/&lt;/g, "<").replace(/&gt;/g, ">");
    256262
     
    263269    pas_cth_js_closeEditFile(); // Closing only clears the div and hides it. Not destroyed.
    264270    var successCallback = function (response) {
     271
    265272        if (response.length) {
    266273            pas_cth_js_processResponse(response);
    267274            pas_cth_js_hideWait();
    268275        }
     276        pas_cth_spinner.default_cursor();
    269277    }
    270278    pas_cth_js_AJAXCall('saveFile', dataBlock, successCallback, pas_cth_js_failureCallback);
  • child-themes-helper/trunk/js/js_common_fn.js

    r2544661 r2628264  
    1515    String.prototype.left = function(n) { return this.substring(0, n); }
    1616}
    17 
    1817function pas_cth_DOMFunctions() {
    1918    var self = this;
     
    2625            e = element;
    2726        }
    28 
    2927        if (e.parentNode != null) {
    3028            e.parentNode.removeChild(e);
     
    4644        box = document.createElement("DIV");
    4745        box.id = id;
    48 
    4946        parent.appendChild(box);
    5047        return box;
     
    6158        if (element == null) { return null; }
    6259        var rect = element.getBoundingClientRect();
    63 
    6460        return {left : rect.left, top: rect.top, width : Math.abs(rect.right - rect.left), height : Math.abs(rect.bottom - rect.top), 'element' : element };
    6561    }
     
    7369    this.searchTree = function (rootElement, tree, pointElement) {
    7470        var found = false;
    75 
    7671        if (rootElement == pointElement) {
    7772            return true;
     
    8681
    8782var mousePosition = {x:0, y:0, element:null};
    88 
    8983var pas_cth_library = new pas_cth_DOMFunctions();
    9084
    91 
    9285window.addEventListener("mousemove", function (e) {
    93 
    9486    mousePosition.x = e.clientX;
    95 
    9687    mousePosition.y = e.clientY;
    97 
    9888});
    9989
    10090function pas_cth_js_AJAXCall(action, dataBlock = [], callback = null, error_callback = null) {
    101 
    10291    var xmlhttp = new XMLHttpRequest();
    103 
    10492    var data    = new FormData();
    105 
    106 
    107 
    10893    data.append("action", action);
    109 
    110 
    111 
    11294    if (dataBlock != null) {
    113 
    11495        Object.keys(dataBlock).forEach(function(key) {
    115 
    11696            if (key != "action") {
    117  data.append(key, dataBlock[key]);
    118  }
     97                data.append(key, dataBlock[key]);
     98            }
    11999        });
    120 
    121     }
    122 
     100    }
    123101    xmlhttp.open("POST", ajaxurl, true);
    124 
    125102    xmlhttp.onreadystatechange = function () {
    126 
    127103        if (4 == xmlhttp.readyState) {
    128 
    129104            // The next line strips the admin_ajax.php 1 byte response from the beginning of the response.
    130 
    131105            // Usually, admin_ajax.php returns a zero. This strips that.
    132 
    133106            var response = (xmlhttp.responseText.length >= 1 ? xmlhttp.responseText.left(xmlhttp.responseText.length - 1) : "");
    134 
    135107            if (xmlhttp.status == 200) {
    136 
    137108                if (callback != null) {
    138 
    139109                    callback(response);
    140 
    141110                }
    142 
    143111            } else {
    144 
    145112                if (error_callback != null) {
    146 
    147113                    error_callback(xmlhttp.statusText, response);
    148 
    149114                } else {
    150 
    151115                    alert("AJAX Error:\n\n" + xmlhttp.statusText + "\n\n" + response);
    152 
    153116                }
    154 
    155117            }
    156 
    157         }
    158 
    159     }
    160 
     118        }
     119    }
    161120    xmlhttp.send(data);
    162 
    163 }
    164 
     121}
    165122if (document.getElementById("childGrid") != null && document.getElementById("parentGrid") != null) {
    166 
    167123    window.addEventListener("resize", function (e) {
    168124        var childGrid = document.getElementById("childGrid")
    169 
    170125        var parentGrid = document.getElementById("parentGrid")
    171 
    172 
    173 
    174126        // Clears inline styles
    175 
    176127        if (childGrid != null) {
    177 
    178128            childGrid.style = "";
    179 
    180         }
    181 
     129        }
    182130        if (parentGrid != null) {
    183 
    184131            parentGrid.style = "";
    185 
    186         }
    187 
    188     }
    189 );
     132        }
     133    });
    190134}
    191135
    192136var windowFlag = false;
    193 
    194 
    195137
    196138if (window.location.href.indexOf("manage_child_themes") >= 0) {
    197139    window.addEventListener("click", function (e) {
    198 
    199140        if (windowFlag) {
    200 
    201141            windowFlag = false;
    202 
    203142            return;
    204 
    205         }
    206 
     143        }
    207144        if (e.clientX == undefined || e.clientY == undefined) {
    208 
    209145            return;
    210 
    211         }
    212 
    213 
    214 
     146        }
    215147        var pointElement    = null;
    216 
    217148        var actionBox       = document.getElementById("pas_cth_actionBox");
    218 
    219149        var errorMessageBox = document.getElementsByName("errorMessageBox")[0];
    220 
    221 
    222 
    223150        pointElement = document.elementFromPoint(e.clientX, e.clientY);
    224 
    225 
    226 
    227151        var tree = pas_cth_library.getElementTree(actionBox);
    228 
    229152        var found = false;
    230 
    231153        found = pas_cth_library.searchTree(actionBox, tree, pointElement);
    232 
    233 
    234 
    235154        if (! found) {
    236 
    237155            tree = pas_cth_library.getElementTree(errorMessageBox);
    238 
    239156            found = pas_cth_library.searchTree(errorMessageBox, tree, pointElement);
    240 
    241         }
    242 
    243 
    244 
     157        }
    245158        if (! found) {
    246 
    247159            pas_cth_library.kill(actionBox);
    248 
    249160            pas_cth_library.kill(errorMessageBox);
    250 
    251         }
    252 
     161        }
    253162    });
    254 
    255 }
    256 
    257 
     163}
    258164
    259165// KillMe kills the error message boxes.
    260 
    261166// After the last box has been destroyed, kill the actionBox div too.
    262 
    263167function pas_cth_js_killMe(element) {
    264 
    265168    var elements;
    266 
    267169    if (element.parentNode != null) {
    268 
    269170        element.parentNode.removeChild(element);
    270 
    271     }
    272 
     171    }
    273172    element.remove();
    274 
    275 
    276 
    277173    elements = document.getElementsByName("errorMessageBox");
    278 
    279174    if (0 == elements.length) {
    280 
    281175        var actionBox = document.getElementById("pas_cth_actionBox");
    282 
    283176        if (actionBox.parentNode != null) {
    284 
    285177            actionBox.parentNode.removeChild(actionBox);
    286 
    287         }
    288 
     178        }
    289179        actionBox.remove();
    290 
    291     }
    292 
     180    }
    293181}
    294182
    295183function pas_cth_js_popupMessage(abbr, msg) {
    296 
    297184    var box = document.getElementById("popupMessageBox")
    298 
    299185    box.innerHTML = msg;
    300 
    301186    box.style.position = "fixed";
    302 
    303187    box.style.left = mousePosition.x + 100 + "px";
    304 
    305188    box.style.top  = mousePosition.y - 40 + "px";
    306 
    307189    box.style.display = "inline";
    308 
    309190    setTimeout(function () {
    310 
    311191                var p = document.getElementById("popupMessageBox")
    312 
    313192                p.innerHTML = "";
    314 
    315193                p.style.display = "none";
    316 
    317194               }, 2000);
    318 
    319195}
    320196
    321197// Process the xmlhttp.responseText that was echo'd during the AJAX call
    322 
    323198function pas_cth_js_processResponse(response) {
    324 
    325199    if ("ABBREVIATION:{" == response.left("ABBREVIATION:{".length).toUpperCase()) {
    326 
    327200        abbr = response.right(response.length - "ABBREVIATION:{".length);
    328 
    329201        abbr = abbr.left(abbr.length - 1);
    330 
    331202        pas_cth_js_popupMessage(abbr, "color saved");
    332 
    333203        document.getElementById("popupMessageBox").style.display = "inline";
    334 
    335204    } else if ("EDITFILEOUTPUT:{" == response.left("EDITFILEOUTPUT:{".length).toUpperCase()) {
    336 
    337205        response = response.right(response.length - "EDITFILEOUTPUT:{".length);
    338 
    339206        response = response.left(response.length - 1);
    340 
    341207        processEditFile(response);
    342 
    343208    } else if ("DEBUG:{" == response.left("DEBUG:{".length).toUpperCase()) {
    344 
    345209        pas_cth_library.kill("pas_cth_actionBox");
    346 
    347210        debugResponse = response.right(response.length - "debug:{".length);
    348 
    349211        debugResponse = debugResponse.left(debugResponse.length - 1);
    350 
    351212       
    352213        box = pas_cth_js_createBox('debugBox', 'debug');
    353 
    354214        box.innerHTML = debugResponse;
    355 
    356215    // Nothing special. We've got output from the PHP function, dump it to the screen.
    357 
    358216    } else {
    359 
    360217        if (response.length > 0) {
    361 
    362218            pas_cth_js_createBox("pas_cth_actionBox", "").innerHTML = response;
    363 
    364219            windowFlag = true;
    365 
    366         }
    367 
    368     }
    369 
     220        }
     221    }
    370222}
    371223
    372224function pas_cth_js_showBox() {
    373 
    374225    return pas_cth_library.createBox("pas_cth_actionBox");
    375226}
    376227
    377228function pas_cth_js_createBox(id, className = "", parent = document.getElementsByTagName("body")[0], clickClose = false) {
    378 
    379229    var box = pas_cth_library.createBox(id, parent);
    380 
    381230    if (className.trim.length > 0) {
    382 
    383231        box.className = className;
    384 
    385     }
    386 
    387 
    388 
     232    }
    389233    if (clickClose) {
    390 
    391234        box.onclick= function () {
    392  pas_cth_library.kill(this); }
     235            pas_cth_library.kill(this);
     236        }
    393237    } else {
    394 
    395238        var dismissBTN = document.createElement("p")
    396 
    397239        dismissBTN.setAttribute("id", "dismissBox");
    398 
    399240        box.appendChild(dismissBTN);
    400 
    401241        dismissBTN.innerHTML = "DISMISS";
    402 
    403242        dismissBTN.onclick = function () {
    404 
    405243            pas_cth_library.kill("pas_cth_actionBox");
    406244        }
    407 
    408     }
    409 
     245    }
    410246    return box;
    411 
    412247}
    413248
    414249function pas_cth_js_addCloseButton(id, parent, text) {
    415 
    416250    var element = document.createElement("p");
    417 
    418251    element.setAttribute("id", id);
    419 
    420 
    421252    parent.appendChild(element);
    422 
    423253    element.innerHTML = text;
    424 
    425254    element.onclick = function () {
    426 
    427255        var myParent = this.parentNode;
    428 
    429256        var myGrandParent = myParent.parentNode;
    430 
    431 
    432 
    433257        if (myGrandParent != null) {
    434 
    435258            myGrandParent.removeChild(myParent);
    436 
    437259            myParent.remove();
    438 
    439         }
    440 
    441     }
    442 
     260        }
     261    }
    443262}
    444263
    445264function getTopLeftPosition(obj = null) {
    446 
    447265    if (obj != null) {
    448 
    449266        return pas_cth_library.getPosition(obj);
    450 
    451267    } else {
    452 
    453268        return null;
    454 
    455     }
    456 
    457 }
     269    }
     270}
  • child-themes-helper/trunk/js/menu.js

    r2544661 r2628264  
    7777    var position = { 'x'    :   event.clientX, 'y'  :   event.clientY };
    7878    var jsdata = JSON.parse(element.getAttribute("data-jsdata"));
    79     var elementID = Date.now(); // clock ticks since midnight at the epoch. Guarantees a unique ID number.
     79    /*
     80     * Originally used Date.now() for unique IDs. But too many operations are performed per clock tick to make these unique IDs.
     81     * Instead, I'm using Math.floor(Math.random() * 1000000.0 ).
     82     * Does not guarantee uniqueness, but picking 2 random numbers between 0 and 999,999 makes it highly unlikely
     83     * that they would be identical. For this purpose, it's good enough.
     84     */
     85    var elementID = Math.floor(Math.random() * 1000000.0);
    8086    var childGrid = document.getElementById("childGrid");
    8187    var parentGrid = document.getElementById("parentGrid");
    8288    var themeType = "";
    8389
     90    /*
     91     * Are we over a child file, a parent file, or no file?
     92     */
    8493    var obj = new elementInfo(childGrid);
    8594    if (obj.isMouseOver(position)) {
     
    94103        return;
    95104    }
     105
     106    /*
     107     * Grab menu items with the appropriate themeType
     108     */
    96109    var menuElements = [];
    97110    pas_cth_menu.forEach(function (cell) {
     
    102115    element.setAttribute("id", "file_" + elementID);
    103116
     117    /*
     118     * Look for an existing popup menu. If found, close it.
     119     */
    104120    var box = document.getElementById("popupMenu");
    105121    if (box != null) {
     
    107123        box.remove();
    108124    }
     125
     126    /*
     127     * Create new popup menu.
     128     */
    109129    box = document.createElement("DIV");
    110130    var p = document.createElement("P");
     
    114134
    115135   
    116    
    117     var rect = p.getBoundingClientRect();
    118     var pHeight = rect.height;
    119     rect = p.getBoundingClientRect();
     136    /*
     137     * Position info the new popup menu.
     138     */
     139//  var rect = p.getBoundingClientRect();
     140//  var pHeight = rect.height;
     141//  rect = p.getBoundingClientRect();
    120142
    121143    box.appendChild(p);
    122144
     145    /*
     146     * Display selected menu items (Edit/Remove for child theme, Copy/View for parent theme)
     147     */
    123148    var anchor = [];
    124 
    125149    for (var ndx = 0; ndx < menuElements.length; ndx++) {
    126150        p = document.createElement("P");
     
    138162    box.id = "popupMenu";
    139163
     164    /*
     165     * Position new popup menu
     166     */
    140167    var lft = position.x + 25;
    141168    var tp = position.y;
     
    144171    document.getElementsByTagName("body")[0].appendChild(box);
    145172
     173    /*
     174     * Expand or contract the menu width depending upon its contents
     175     */
    146176    box.style.width = box.scrollWidth;
    147177
    148     var pRect = p.getBoundingClientRect();
    149     var boxRect = box.getBoundingClientRect();
     178//  var pRect = p.getBoundingClientRect();
     179//  var boxRect = box.getBoundingClientRect();
    150180
    151181    event.preventDefault();
    152182}
     183/*
    153184function findCorners(objPos) {
    154185    this.adjustCorners = function (adjSize) {
     
    166197    }
    167198}
     199*/
  • child-themes-helper/trunk/js/pasChildThemes.js

    r2544661 r2628264  
    1717    var jsInput;
    1818    var box;
     19
     20    pas_cth_spinner.wait_cursor();
    1921
    2022
     
    4042        document.getElementById("pas_cth_actionBox").style.display = "inline";
    4143        windowFlag = true; // Prevents the window.onclick event from closing this prompt.
     44
     45        pas_cth_spinner.default_cursor();
     46
    4247        return;
    4348    }
     
    5964            break;
    6065    }
     66    pas_cth_spinner.default_cursor();
     67
    6168}
    6269function pas_cth_js_showWait() {
     
    134141        pas_cth_js_processResponse(response);
    135142        pas_cth_js_hideWait();
     143        pas_cth_spinner.default_cursor();
    136144    } else {
    137145        location.reload();
     
    142150    pas_cth_js_showBox().innerHTML = msg;
    143151    pas_cth_js_hideWait();
     152    pas_cth_spinner.default_cursor();
    144153}
    145154/*
  • child-themes-helper/trunk/js/tabs.js

    r2544661 r2628264  
    5353
    5454    body.style.overflow = "hidden";
    55     html.style.overflow = "hidden";
    5655}
    5756function pas_cth_js_expertMode(element) {
  • child-themes-helper/trunk/readme.txt

    r2544671 r2628264  
    44Donate link: https://paypal.me/PaulSwarthout
    55Tags: child themes helper, child themes, child theme, child, theme, template theme, parent theme, developers, IIS, Linux, copy files to child theme, create a child theme
    6 Requires at least: 4.7.0
    7 Tested up to: 5.7.2
    8 Stable tag: 2.2.2
     6Requires at least: 5.0
     7Tested up to: 5.8.2
     8Stable tag: 2.2.4
    99Requires PHP: 5.6.31
    1010License: GPLv2 or later
     
    6060
    6161    - *Development versions*
    62         Versions 2\.1, 1\.2 are available for download and install.
     62        Versions 2\.2\.1, 2\.1, 1\.2 are available for download and install.
    6363
    6464    - *Screenshot*
     
    9393
    9494== Frequently Asked Questions ==
     95
     96= Sometimes the wait spinner gets stuck and doesn't end. What can I do?
     97
     98Yep. I've noticed that. I don't know why that happens. When I stumble on that, and I walk the code, it never happens. In the meantime, there's a really simple solution. Just click on the spinner with your primary mouse button (usually the left) and the wait spinner will disappear.
    9599
    96100= Do I have to keep the Child Themes Helper installed and/or activated? =
     
    124128== Changelog ==
    125129
     130= 2.2.4 =
     131 - Tested the plugin with PHP 8.0.0 and WordPress 5.8.2.
     132
     133 - Cleaned up code.
     134
     135 - Fixed a problem with the spinning wait cursors. The code was originally copied from another plugin that I'm developing, but I inadvertantly got some code that doesn't work with this plugin.
     136
     137 - Introduced namespaces to my code. Slowly removing prefixes from all 'global' functions as they are now localized in the child-themes-helper namespace.
     138
     139= 2.2.3 =
     140 - Bug fix: Format at the very bottom of the list of files didn't leave room for the popup menu. Extended the page with a bottom margin of 50px.
     141
    126142= 2.2.2 =
    127143 - Oops. Forgot to include the new files before I committed the changes. Everything is included with this one.
     
    219235== Upgrade Notice ==
    220236
     237= 2.2.4 =
     238 - Fixed several bugs that were preventing the plugin from loading correctly.
     239 - Please submit a trouble ticket when you encounter problems. I was embarrassed that this plugin was broken in the latest version on the WordPress Plugins repository.
     240
    221241= 1.1.3 =
    222242- Fixed a bug: The path to the child theme's stylesheet in the functions.php was incorrect.
Note: See TracChangeset for help on using the changeset viewer.