Skip to content

Instantly share code, notes, and snippets.

paulund / example-wp-list-table.php
Last active Oct 25, 2021
An example code of using the WP_List_Table class. With Pagination.
View example-wp-list-table.php
* Plugin Name: Paulund WP List Table Example
* Description: An example of how to use the WP_List_Table class to display data in your WordPress Admin area
* Plugin URI:
* Author: Paul Underwood
* Author URI:
* Version: 1.0
* License: GPL2
paulund / resize-image-keep-aspect-ratio.php
Last active Oct 11, 2021
Resize a image to a max width and height and keep aspect ratio.
View resize-image-keep-aspect-ratio.php
public function getImageSizeKeepAspectRatio( $imageUrl, $maxWidth, $maxHeight)
$imageDimensions = getimagesize($imageUrl);
$imageWidth = $imageDimensions[0];
$imageHeight = $imageDimensions[1];
$imageSize['width'] = $imageWidth;
paulund / laravel-recaptcha-validation.php
Created Apr 3, 2018
A Laravel validation rule to verify recaptcha.
View laravel-recaptcha-validation.php
namespace App\Rules;
use GuzzleHttp\Client;
use Illuminate\Contracts\Validation\Rule;
class GoogleRecaptcha implements Rule
paulund / AppServiceProvider.php
Last active Aug 7, 2021
Laravel Cache Auth::user(). Learn how to cache the logged in user at
View AppServiceProvider.php
namespace App\Providers;
use App\Models\User;
use App\Observers\UserObserver;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
paulund / phpcs.xml
Created Aug 20, 2017
PHP PSR-2 CodeSniffer Config for Laravel
View phpcs.xml
<?xml version="1.0"?>
<ruleset name="Laravel Standards">
The name attribute of the ruleset tag is displayed
when running PHP_CodeSniffer with the -v command line
argument. The description tag below is not displayed anywhere
except in this file, so it can contain information for
developers who may change this file in the future.
paulund / wordpress-base-custom-data.php
Created Sep 24, 2013
A PHP class to handle CRUD functionality in WordPress default tables.
View wordpress-base-custom-data.php
* Abstract class which has helper functions to get data from the database
abstract class Base_Custom_Data
* The current table name
* @var boolean
paulund / add-option-to-dropdown.js
Created Jun 25, 2013
Add and Remove Options in Select using jQuery
View add-option-to-dropdown.js
$("#selectBox").append('<option value="option6">option6</option>');
paulund / css-purge-webpack-config.js
Last active Apr 26, 2021
Using CSS Purge With Laravel Mix. Tutorial on how to use the following can be found reduced a production ready CSS file from 179kb to 7.9kb.
View css-purge-webpack-config.js
plugins: [
new purgeCss({
paths: glob.sync([
path.join(__dirname, 'resources/views/**/*.blade.php'),
path.join(__dirname, 'resources/assets/js/**/*.vue')
extractors: [
extractor: class {
paulund / Results--html.vue
Created Dec 26, 2017
Creating a Laravel, VueJS, Algolia real time search results box.
View Results--html.vue
<section class="search-results" v-show="results.length > 0">
<div v-for="result in results" class="search-result">
<a :href="'/' + result.slug">{{ result.title }}</a>
paulund / pre-push
Last active Nov 2, 2020
Run phpunit tests before push and error if the tests fail
View pre-push
git diff --cached --name-only | while read FILE; do
if [[ "$FILE" =~ ^.+(php|inc|module|install|test)$ ]]; then
echo "Running tests..."
cd "${0%/*}/.."
phpunit 1> /dev/null
if [ $? -ne 0 ]; then
echo -e "\e[1;31m\tUnit tests failed ! Aborting commit.\e[0m" >&2
exit 1;