Skip to content

Instantly share code, notes, and snippets.

Avatar

johnlewisdesign

View GitHub Profile
@johnlewisdesign
johnlewisdesign / post-versioning-via-comments.php
Created Jun 18, 2020
Log post history in comments - WordPress
View post-versioning-via-comments.php
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 Jun 18, 2020
Find and remove an array key from a PHP array
View remove-array-key.php
<?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 Jun 18, 2020
Ready web folder permissions without digits - CHMOD 755 folders, 644 files
View chmod-web.sh
chmod -R a=r,u+w,a+X ./web
@johnlewisdesign
johnlewisdesign / yetVisited.js
Last active Jun 18, 2020
Set whether page has been visited or not yet via jQuery (COVID-19 banner show once)
View yetVisited.js
$(document).ready(function() {
var yetVisited = localStorage['visited'];
if (!yetVisited) {
// open popup
localStorage['visited'] = "yes";
}
});
@johnlewisdesign
johnlewisdesign / wp-api-stack-requests.php
Created Jun 18, 2020
Stack WP/WooCommerce API calls to override 100 limit
View wp-api-stack-requests.php
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);