Skip to content

Instantly share code, notes, and snippets.

View mklasen's full-sized avatar

Marinus Klasen mklasen

View GitHub Profile
<?php
add_action( 'cmb2_admin_init', function() {
$prefix = 'mk_add_thickbox_';
$metabox = new_cmb2_box( array(
'id' => $prefix.'box',
'title' => 'Signature',
'object_types' => array( 'post', ),
) );
$metabox->add_field( array(
@mklasen
mklasen / README.MD
Last active April 25, 2023 13:53
Cloudways restart PHP-FPM via terminal
  1. Create a folder on your server.
  2. Copy the composer.json file
  3. Run composer install
  4. Create a file called restart-php-fpm.php
  5. Set the correct email, key, server ID and php-fpm version.
  6. Run php restart-php-fpm.php
@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;
@mklasen
mklasen / extend-rest-api.php
Last active February 11, 2023 20:31
Update Custom Post Type Meta Fields with the WordPress REST API
<?php
register_meta('post', 'custom-field', [
'object_subtype' => 'custom-post-type',
'show_in_rest' => true
]);
@mklasen
mklasen / ajax.upload.js
Created February 11, 2017 12:30
Upload files to WordPress with ajax via REST API
var data = new FormData()
// Add data/files to formdata var
jQuery.ajax({
url: wpApiSettings.root + 'routehere/v1/subroute/save',
type: 'POST',
beforeSend: function(xhr) {
xhr.setRequestHeader( 'X-WP-Nonce', wpApiSettings.nonce );
},
<?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 / Instructions.MD
Last active September 21, 2022 02:17
Install wp-cli on shared hosting (Antagonist)

Download WP-CLI

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

Test to see if it works correctly

php wp-cli.phar --info

Add extra permissions

@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 / (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/';