Skip to content

Instantly share code, notes, and snippets.

View johnlewisdesign's full-sized avatar

johnlewisdesign

View GitHub Profile
@johnlewisdesign
johnlewisdesign / post-versioning-via-comments.php
Created June 18, 2020 19:29
Log post history in comments - WordPress
function add_comment_on_post_update( $post_id, $post_after, $post_before ) {
// If this is just a revision, don't send the email.
if ( wp_is_post_revision( $post_id ) )
return;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return;
if (isset($post_before->post_status) && 'auto-draft' == $post_before->post_status) {
return;
}
@johnlewisdesign
johnlewisdesign / remove-array-key.php
Last active June 18, 2020 19:26
Find and remove an array key from a PHP array
<?php
function removeRecursive($inputArray,$delKey){
if(is_array($inputArray)){
$moreKey = explode(",",$delKey);
foreach($moreKey as $nKey){
unset($inputArray[$nKey]);
foreach($inputArray as $k=>$value) {
$inputArray[$k] = removeRecursive($value,$nKey);
}
}
@johnlewisdesign
johnlewisdesign / chmod-web.sh
Created June 18, 2020 19:25
Ready web folder permissions without digits - CHMOD 755 folders, 644 files
chmod -R a=r,u+w,a+X ./web
@johnlewisdesign
johnlewisdesign / yetVisited.js
Last active June 18, 2020 19:23
Set whether page has been visited or not yet via jQuery (COVID-19 banner show once)
$(document).ready(function() {
var yetVisited = localStorage['visited'];
if (!yetVisited) {
// open popup
localStorage['visited'] = "yes";
}
});
@johnlewisdesign
johnlewisdesign / wp-api-stack-requests.php
Created June 18, 2020 19:22
Stack WP/WooCommerce API calls to override 100 limit
header('Access-Control-Allow-Origin: *', 'Content-Type: application/json'); // Avoid cross origin block
$url1 = 'https://www.example.com/wp/v2/posts?per_page=100&page=1'; // path to your JSON file
$url2 = ''https://www.example.com/wp/v2/posts?per_page=100&page=2'; // path to your JSON file
$json1 = file_get_contents($url1);
$json2 = file_get_contents($url2);
$my_array1 = json_decode($json1, true);
$my_array2 = json_decode($json2, true);
$res = array_merge($my_array1, $my_array2);