Skip to content

Instantly share code, notes, and snippets.

View tomstorms's full-sized avatar

Tom Storms tomstorms

View GitHub Profile
@tomstorms
tomstorms / php-cleanurl
Last active December 27, 2021 01:04
Get a clean URL from a user supplied domain name
<?php
// Snippet code demonstrating how you could get a clean URL from a user supplied domain name
// Include the function above with the test.php file to test a bunch of different urls to view the results
function cleanURL($url) {
// Remove http, https and trailing slashes from the url.
$domainURL = str_ireplace('http://', '', $url);
$domainURL = str_ireplace('https://', '', $domainURL);
@tomstorms
tomstorms / php-domain-records
Created December 27, 2021 01:03
Perform domain/DNS verification checks in PHP
<?php
// Snippet code demonstrating how you could potentially do domain/DNS verification checks in PHP.
// Example:
// In this example, we're looking at the domain www.islandmeetscity.com for a TXT record with the value kboZ2tg22FjOPUJQliMJ4QW5g.
// The isDomainVerified function will return true/false if this record exists.
$domainName = 'www.islandmeetscity.com';
$requiredTXTValue = 'kboZ2tg22FjOPUJQliMJ4QW5g';
@tomstorms
tomstorms / php-simple-csrf-token
Last active December 27, 2021 01:12
Simple Cross Site Request Forgery (CSRF) token validation for your PHP projects
<script type="text/javascript">
// If you are using jQuery, you need to initialise the JS variable on your PHP page (ie index.php) so it can be globally accessed.
$(function () {
// Set CSRF token
window.ajax_token = '<?php echo $token; ?>';
});
// Then in your AJAX function, you can use this variable inside your script.js file for example like so:
#-----------------------------------------------------
# Get WordPress Featured Image from Post
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
#-----------------------------------------------------
# Fix WordPress uploads files
#
# See: https://kinsta.com/knowledgebase/sorry-this-file-type-is-not-permitted-for-security-reasons/
#
#-----------------------------------------------------
# Roots Sage WordPress Theme - Build
composer install
npm install
npm run build
# Run the following for production files:
npm run build:production
#-----------------------------------------------------
# WPBakery - Exclude Posts from Post Grid but have a category
<?php
require('wp-load.php');
$data = array(
'post_type' => 'post',
'post_status' => 'publish',
#-----------------------------------------------------
# Send ping results to file:
# On Mac:
ping 172.16.229.39 | tee ~/Desktop/ping-results-172.16.229.39.txt
# On Windows:
ping 172.16.229.39 >> c:\Test.txt -t
#-----------------------------------------------------
# PowerBuilder File Types:
.pbd = compiled code
.pbl = source code
#-----------------------------------------------------
# Placeholder above Input on focus:
<label>
<input placeholder=" ">
<span>Placeholder Text</span>
</label>
label {
#-----------------------------------------------------
# Abort an AJAX request:
var xhr = false;
function fetchEvents() {
// Abort any existing AJAX request
if (xhr) xhr.abort();