Skip to content

Instantly share code, notes, and snippets.

View earth3300's full-sized avatar

Earth3300 earth3300

View GitHub Profile
@earth3300
earth3300 / gist:d938a3bde774a65f8dbd2c8db3146e67
Last active November 8, 2018 16:51
Convert an XML string into an array via json_encode and json_decode.
/**
* Convert String to XML to JSON to Array
*
*/
private function xmlStringToArray( $str )
{
/** Load the string into xml. */
$xml = simplexml_load_string( $str, "SimpleXMLElement", LIBXML_NOCDATA );
/** Encode the xml as JSON */
@earth3300
earth3300 / json-encode.php
Created November 22, 2018 20:31
Encodes an array in JSON format with one item per line (JSON_PRETTY_PRINT), but uses only two spaces instead of four, to maintain internal formatting consistency.
/**
* Json Encode
*
* Encode the array as JSON using JSON_PRETTY_PRINT, then use only two spaces
* for indentation instead of four, to maintain consistency with PHP, CSS, JS
* and HTML.
*
* @param array $items
*
* @return string|false
@earth3300
earth3300 / delayed-button.html
Created November 22, 2018 21:30
This disabled button is enabled after three seconds via JavaScript (not jQuery).
<button id="form-submit" type="submit" class="button button-primary" disabled>Send</button>
<script>
setTimeout(function() {
var btnSubmit = document.getElementById('form-submit');
if (typeof btnSubmit !== "undefined") {
btnSubmit.disabled = false;
}
}, 3000);
</script>
@earth3300
earth3300 / password-regex.php
Created November 23, 2018 17:40
Password validation using regex.
/**
* Password Validation
*
* @link https://stackoverflow.com/a/21456918/5449906
*
* @param $string
*
* @return bool
*/
private function validatePassword( $password )
@earth3300
earth3300 / device.php
Last active December 6, 2018 21:42
Device Detection as an Aid to Theme Delivery
<?php
/**
* Device Detection and Theme Delivery
*
* This set of code was developed as an attempt to determine the device the
* viewer was using, so that the content sent could be optimized to that device.
* In addition, then, to knowing what device the viewer is using, a sense of the
* context in which the content is being viewed can be ascertained. For example,
* a person viewing a smartphone may either be on the street or inside in a business
* setting. However a person on a desktop computer (not a tablet, not a smartphone)
@earth3300
earth3300 / style.css
Last active December 7, 2018 21:44
Styling for a Majority of Absolutely Positioned Elements
/*
Theme Name: EC01 Style
Theme URI: http://ec01.earth3300.info/
Author: Clarence Bos
Author URI: http://ec01.earth3300.info/
Description: Part of a sustainable community design.
Version: 1.0.0
License: GPL v3.0
License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
@earth3300
earth3300 / cache_enabler.class.php
Created February 25, 2019 00:57
Cache Enabler Class from Cache Enabler (adjusted)
<?php
// exit
defined('ABSPATH') OR exit;
/**
* Cache_Enabler
*
* @since 1.0.0
*/
@earth3300
earth3300 / site-base-cache.php
Last active February 25, 2019 01:58
Adjusted file path function from the cache-enabler plugin.
/**
* Generate the Cache Path
*
* @param string $path
*
* @return string
*/
function _ce_file_path($path = NULL) {
$url = parse_url( $_SERVER['REQUEST_URI'] );
@earth3300
earth3300 / wp-config.tmpl.php
Last active June 22, 2019 01:38
Modified wp-config.php file. This is the template. Copy to wp-config.php and adjust as needed.
<?php
/**
* The base configuration for WordPress
*
* The wp-config.php creation script uses this file during the
* installation. You don't have to use the web site, you can
* copy this file to "wp-config.php" and fill in the values.
*
* This file contains the following configurations:
*
@earth3300
earth3300 / post.php
Last active March 3, 2019 14:11
Filter the page permalink (including sample permalink).
/**
* Filters the permalink for a page.
*
* @since 1.5.0
*
* @example apply_filters(
* 'page_link',
* string $link,
* int $post_id,
* bool $sample