Skip to content

Instantly share code, notes, and snippets.

View jeffreyvr's full-sized avatar
🎸
Freelancing and building my own stuff.

Jeffrey van Rossum jeffreyvr

🎸
Freelancing and building my own stuff.
View GitHub Profile
@jeffreyvr
jeffreyvr / validate-dutch-phone-number-function.php
Created March 19, 2015 13:47
Validate Dutch Phone Number
<?php
/**
* Validate Dutch Phone number
*
* Can be a local or mobile phone number.
*/
function validate_dutch_phone_number( $phone_number ){
if ( preg_match( "/^(\+|00|0)(31\s?)?(6[\s-]?[1-9][0-9]{7}|[1-9][0-9][\s-]?[1-9][0-9]{6}|[1-9][0-9]{2}[\s-]?[1-9][0-9]{5})$/", $phone_number ) ) {
return true;
} else {
@jeffreyvr
jeffreyvr / class-single-post-meta-manager-loader.php
Last active March 1, 2017 10:23
Defining priority and arguments to Single Post Meta Manager Loader class.
<?php
/**
* This class is based on the loader class from this tutorial;
* https://code.tutsplus.com/tutorials/object-oriented-programming-in-wordpress-document-the-plugin-ii--cms-21167
*
* In this example I have added the ability to define the priority and arguments for actiond and filters.
*/
class Single_Post_Meta_Manager_Loader {
protected $actions;
@jeffreyvr
jeffreyvr / simple-html-dom.php
Last active March 21, 2017 19:06
Simple WordPress plugin to replace images with the .Sirv css class (for Boagworld)
<?php
/**
* Website: http://sourceforge.net/projects/simplehtmldom/
* Additional projects that may be used: http://sourceforge.net/projects/debugobject/
* Acknowledge: Jose Solorzano (https://sourceforge.net/projects/php-html/)
* Contributions by:
* Yousuke Kumakura (Attribute filters)
* Vadim Voituk (Negative indexes supports of "find" method)
* Antcs (Constructor with automatically load contents either text or file/url)
*
@jeffreyvr
jeffreyvr / LogFailedAuthenticationAttempt.php
Last active July 24, 2017 06:25
Add WordPress password validation to Laravel
<?php
namespace App\Listeners;
use Illuminate\Auth\Events\Failed;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\User as User;
use MikeMcLin\WpPassword\Facades\WpPassword;
use Auth;
@jeffreyvr
jeffreyvr / access_vba_login.vba
Created January 23, 2018 21:54
Access VBA Login
Option Compare Database
Private Sub LoginBtn_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("select * from dbo_Medewerker where medewerkerloginnaam='" & GebruikersnaamTxt.Value & "'")
If rst.RecordCount <= 0 Then
@jeffreyvr
jeffreyvr / wordpress_api_option_groups_categories.js
Last active February 8, 2018 12:22
Make option groups from WordPress API Categories list
var categories = getCategories(); // this function gets the categories with ajax (you'll have to do that yourself ;-))
var html = "";
var tpl_categories = []; // top level categories
var top_cat_count = 0;
for (i = 0; i < categories.length; i++) {
if ( categories[i].parent == 0 ) {
@jeffreyvr
jeffreyvr / color-brightness.php
Last active February 15, 2018 14:00
Color brightness rgb
<?php
function color_brightness($hex) {
$hex = str_replace('#', '', $hex);
$strl = strlen($hex)/3;
$c_r = hexdec(substr($hex, 0, $strl));
$c_g = hexdec(substr($hex, $strl, $strl));
$c_b = hexdec(substr($hex, $strl*2, $strl));
$brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
@jeffreyvr
jeffreyvr / MjmlHelper.php
Created March 6, 2018 14:49
Simple helper class for Mjml.
<?php
namespace App\Helpers;
use Config;
class MjmlHelper
{
public static function auth() {
if ( empty( env('MJML_APPID') ) || empty( env('MJML_APPSECRET') ) ) return;
return base64_encode(env('MJML_APPID').':'.env('MJML_APPSECRET'));
@jeffreyvr
jeffreyvr / functions.php
Created October 23, 2018 10:25
Adding oEmbed filter in custom WordPress function
<?php
function prefix_get_custom_sidebar() {
global $post, $wp_embed;
$custom_sidebar = get_post_meta( $post->ID, 'custom_sidebar', true );
$custom_sidebar = $wp_embed->autoembed( $custom_sidebar ); // Apply oEmbed filter
return $custom_sidebar;
@jeffreyvr
jeffreyvr / whitelist.php
Created December 3, 2018 15:50
Generate commands to whitelist Cloudflare IP's (iptables)
<?php
$ips = file_get_contents( 'https://www.cloudflare.com/ips-v4' );
$ips = explode( PHP_EOL, $ips );
$result = '';
foreach ( $ips as $ip ){