Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View mklasen's full-sized avatar

Marinus Klasen mklasen

View GitHub Profile
@mklasen
mklasen / sympose-generate-person-image.php
Last active February 14, 2023 13:34
Generate images for Sympose person pages
<?php
/**
* Plugin Name: Generate person images
*/
use Treinetic\ImageArtist\lib\Text\Color;
use Treinetic\ImageArtist\lib\Overlays\Overlay;
use Treinetic\ImageArtist\lib\Text\TextBox;
use Treinetic\ImageArtist\lib\Text\Font;
use Treinetic\ImageArtist\lib\Image;
<?php
/**
* Plugin Name: CMB2 text_datetime_timestamp_timezone Test
* Test file for CMB2 Bug Report: https://github.com/CMB2/CMB2/issues/1465
*/
add_action(
'cmb2_admin_init',
function() {
@mklasen
mklasen / mk-manage-plugins.php
Last active October 5, 2022 08:05
Activate and deactivate plugins in WordPress - use as must-use plugin
<?php
/**
* MK Manage Plugins
* Activates and deactivates plugins for a site or network-wide.
* - Make sure to define a WORDPRESS_ENV variable in your wp-config.php
* Usage Example:
* --
* new MK_Manage_Plugins(
* array(
* 'post-smtp' => array(
@mklasen
mklasen / class-woocommerce.php
Created August 16, 2022 10:13
Manage menu items and custom pages in Woocommerce my account dashboard
<?php
class MK_Woocommerce {
public function __construct() {
$this->init();
}
public function init() {
add_filter( 'woocommerce_account_menu_items', array( $this, 'manage_menu_items' ), 80 );
@mklasen
mklasen / index.html
Created February 11, 2022 11:32
Video upload sample with duration and video sample after selecting a file.
<!-- This sample uses TailwindCSS, it works without but will not have any styling. -->
<div class="container mx-auto py-12 font-sans">
<input type="file" class="bg-gray-100 p-5 block border mb-2" />
<div class="duration py-2">Duration:<span class="font-bold px-2"></span></div>
<div class="progress py-2"></div>
<div class="video-sample w-4/12 bg-gray-200 shadow-md rounded border"> </div>
</div>
@mklasen
mklasen / main.php
Created February 3, 2022 15:39
Uncanny Import Users: Automatically give the user the default role when the user exists in the network, but not on the site.
<?php
class Sample {
public function __construct() {
$this->hooks();
}
public function hooks() {
add_action( 'uo_after_user_row_imported', array( $this, 'add_user_to_multisite' ), 99, 4 );
}
@mklasen
mklasen / reorder-options.js
Created February 3, 2022 10:18
Re-order options in a select element alphabatically by it's text value
main.querySelectorAll("select").forEach(select => {
let options = select.querySelectorAll("option");
Array.from(options)
.sort((a, b) => {
if (a.text.toUpperCase() > b.text.toUpperCase()) return 1;
else if (a.text.toUpperCase() < b.text.toUpperCase()) return -1;
else return 0;
})
.forEach(el => {
select.appendChild(el);
@mklasen
mklasen / remove-fuzzy-hook.php
Last active November 5, 2021 12:38
Remove fuzzy actions and filters in WordPress
<?php
class Main {
public function remove_fuzzy_hook( $hook_name, $callback, $priority ) {
global $wp_filter;
// Confirm the hook name exists.
if ( isset( $wp_filter[ $hook_name ] ) && is_a( $wp_filter[ $hook_name ], 'WP_Hook' ) ) {
@mklasen
mklasen / show-gif-after-content.php
Created October 20, 2021 13:46
Show a GIF after the content of a blog post in WordPress
<?php
add_filter('the_content', 'show_a_gif');
function show_a_gif($content) {
$content .= '<iframe src="https://giphy.com/embed/jTqfCm1C0BV5fFAYvT" width="480" height="480" frameBorder="0" class="giphy-embed" allowFullScreen></iframe><p><a href="https://giphy.com/gifs/wordpressdotcom-diversity-wordpress-radiate-jTqfCm1C0BV5fFAYvT">via GIPHY</a></p>';
return $content;
}
@mklasen
mklasen / plugin.php
Last active October 15, 2021 16:02
Include ACF (Pro) in a premium WordPress plugin
<?php
/**
* An example for including Advanced Custom Fields in your plugin
* Made for Premia (getpremia.com)
* WordPress premium plugins made easy!
*/
class Your_Plugin {
public function __construct() {