Skip to content

Instantly share code, notes, and snippets.

View mklasen's full-sized avatar

Marinus Klasen mklasen

View GitHub Profile
@mklasen
mklasen / main.yml
Created August 27, 2021 13:48
Create a new zipped asset when a new release is published
name: Create release
on:
release:
types:
- created
jobs:
build:
runs-on: ubuntu-latest
@mklasen
mklasen / replace-brackets-by-html.php
Created August 25, 2021 08:47
Replacing brackets by HTML strings in PHP
<?php
public static function process_text($text) {
return preg_replace_callback(
'/{{(.*?)\}}/',
function($matches) {
return sprintf('<span class="text-highlight">%s</span>', $matches[1]);
},
$text
);
}
@mklasen
mklasen / script.js
Created May 26, 2021 15:36
Gravity Forms: Override the submit action so that the form can be submitted even when an unexpected callback was returned
// In this scenario a ZIP was returned upon form submission, because Gravity Forms
// does not expect this, the submit action is not reset.
// This snippet overrides the submit action.
document.addEventListener("DOMContentLoaded", function(){
const form = document.querySelector('form.generate-template');
const submit = form.querySelector('input.gform_button');
submit.addEventListener('click', function() {
form.submit();
});
});
@mklasen
mklasen / Dockerfile
Last active June 27, 2021 13:22
Automatically reloading a python script upon file changes with nodemon
FROM nikolaik/python-nodejs:latest
RUN npm install -g nodemon
@mklasen
mklasen / allow-email-as-username.php
Created April 22, 2021 14:45 — forked from anttiviljami/allow-email-as-username.php
A wordpress mu-plugin that allows you to create users with email-addresses as usernames in multisite
<?php
/**
* Plugin name: Allow email as WordPress Network/Multisite username
* Description: A wordpress mu-plugin that allows you to create users with email-addresses as usernames in multisite
* Version: 1.0
* Author: @anttiviljami
* License: GPLv3
*/
add_filter( 'wpmu_validate_user_signup', '_signup_allow_email_as_username' );
@mklasen
mklasen / (A) class-acf-fields-location.php
Last active July 13, 2022 19:21
Save custom fields to custom plugin folder. All three examples do exactly the same thing in different ways.
<?php
class Plugin {
public function __construct() {
add_filter( 'acf/settings/save_json', array( $this, 'acf_location' ) );
add_filter( 'acf/settings/load_json', array( $this, 'acf_locations' ) );
}
public function acf_location() {
return plugin_dir_path( __FILE__ ) . 'acf-json/';
@mklasen
mklasen / functions.php
Created March 10, 2021 11:42
Customize the slug for the event taxonomy in Sympose
<?php
/* Customize the slug for the event taxonomy in Sympose */
add_filter('sympose_customize_event_taxonomy', 'c7_sympose_alter_event_slug');
function c7_sympose_alter_event_slug($args) {
$args['rewrite'] = array(
'slug' => 'sympose-event',
);
return $args;
}
@mklasen
mklasen / redirect-rules.txt
Created February 18, 2021 09:41
Kinsta Redirect rules for unsplash
^/wp-content/uploads/(.*)-([0-9]+)x([0-9]+).(gif|jpe?g|png|bmp)$
https://source.unsplash.com/random/$2x$3
^/wp-content/uploads/(.*).(gif|jpe?g|png|bmp)$
https://source.unsplash.com/random/600x600
@mklasen
mklasen / wp-cli-command.sh
Last active June 22, 2022 16:49
Add the 'spam' column to the wp_users table
# The script below is updated following a comment by RJT.
# If you use a different prefix, replace wp_users by the actual name of the table.
wp db query "ALTER TABLE wp_users ADD spam TINYINT NOT NULL DEFAULT 0;"
# When the spam column is missing, the ‘deleted’ column might be missing as well.
wp db query "ALTER TABLE wp_users ADD deleted TINYINT NOT NULL DEFAULT 0;"
@mklasen
mklasen / add-image-size.php
Last active January 7, 2021 11:53
WordPress: Add image size to block editor settings (ex: Media & Text block)
<?php
class Main {
public function __construct() {
$this->init();
}
public function init() {
add_action( 'after_setup_theme', array( $this, 'add_image_sizes' ) );
add_filter( 'image_size_names_choose', array( $this, 'show_image_sizes' ) );
}