Skip to content

Instantly share code, notes, and snippets.

@paulund
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
<?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: http://www.paulund.co.uk
* Author: Paul Underwood
* Author URI: http://www.paulund.co.uk
* Version: 1.0
* License: GPL2
*/
@paulund
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
<?php
public function getImageSizeKeepAspectRatio( $imageUrl, $maxWidth, $maxHeight)
{
$imageDimensions = getimagesize($imageUrl);
$imageWidth = $imageDimensions[0];
$imageHeight = $imageDimensions[1];
$imageSize['width'] = $imageWidth;
@paulund
paulund / laravel-recaptcha-validation.php
Created Apr 3, 2018
A Laravel validation rule to verify recaptcha.
View laravel-recaptcha-validation.php
<?php
namespace App\Rules;
use GuzzleHttp\Client;
use Illuminate\Contracts\Validation\Rule;
class GoogleRecaptcha implements Rule
{
/**
@paulund
paulund / AppServiceProvider.php
Last active Aug 7, 2021
Laravel Cache Auth::user(). Learn how to cache the logged in user at https://paulund.co.uk/laravel-cache-authuser
View AppServiceProvider.php
<?php
namespace App\Providers;
use App\Models\User;
use App\Observers\UserObserver;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
@paulund
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
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
<?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
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
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 https://paulund.co.uk/reduce-css-file-size-with-css-purge reduced a production ready CSS file from 179kb to 7.9kb.
View css-purge-webpack-config.js
mix.webpackConfig({
plugins: [
new purgeCss({
paths: glob.sync([
path.join(__dirname, 'resources/views/**/*.blade.php'),
path.join(__dirname, 'resources/assets/js/**/*.vue')
]),
extractors: [
{
extractor: class {
@paulund
paulund / Results--html.vue
Created Dec 26, 2017
Creating a Laravel, VueJS, Algolia real time search results box.
View Results--html.vue
<template>
<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>
</div>
</section>
</template>
@paulund
paulund / pre-push
Last active Nov 2, 2020
Run phpunit tests before push and error if the tests fail
View pre-push
#!/bin/bash
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;