Skip to content

Instantly share code, notes, and snippets.

View mklasen's full-sized avatar

Marinus Klasen mklasen

View GitHub Profile
@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 / social-media-buttons.php
Last active October 23, 2019 11:11
Snippet for displaying social media buttons without using external libraries
<?php
public function social_media_buttons() {
$output = '';
$enabled_platforms = array(
'googleplus',
'facebook',
'twitter',
@mklasen
mklasen / class-enable-software-updates-for-free-downloads.php
Created October 8, 2019 14:19
EDD: Enable software updates for free downloads
<?php
class Enable_Software_Updates_For_Free_Downloads {
public function __construct() {
$this->hooks();
}
public function hooks() {
add_filter( 'edd_sl_generate_license_key', array( $this, 'generate_free_license_key' ), 10, 5 );
add_filter( 'edd_sl_check_license_status', array( $this, 'skip_free_download_license_check' ), 10, 2 );
@mklasen
mklasen / download-file.php
Created October 15, 2019 09:35
Download PDF from API endpoint
<?php
$auth = base64_encode("_user_:_pass_");
$context = stream_context_create([
"http" => [
"header" => "Authorization: Basic $auth"
]
]);
$result = file_get_contents('_url_', false, $context);
file_put_contents('_file_.pdf', $result);
@mklasen
mklasen / .babelrc
Created December 2, 2019 15:17
Basic webpack setup
{
"presets": [
"@babel/preset-env"
]
}
@mklasen
mklasen / cron.sh
Created December 4, 2019 08:27
Run cronjobs for all sites via WP-CLI
wp site list --field=url | xargs -n1 -I % wp --url=% cron event run --due-now
@mklasen
mklasen / _media-queries.scss
Created January 2, 2020 21:08
Media Queries SASS Mixin
@mixin for-phone-only {
@media (max-width: 599px) { @content; }
}
@mixin for-tablet-portrait-up {
@media (min-width: 600px) { @content; }
}
@mixin for-tablet-landscape-up {
@media (min-width: 900px) { @content; }
}
@mixin for-desktop-up {
<?php
class Sample {
public function register_invoice_endpoint() {
register_rest_route( 'prefix/v1/endoint', '/invoice/(?P<id>\d+)', array(
'methods' => 'GET',
'callback' => array( $this, 'get_invoice' ),
'permission_callback' => array( $this, 'get_items_permissions_check' )
) );
}
@mklasen
mklasen / sympose-overwrite-image-sizes.php
Last active February 25, 2020 05:37
Overwrite Sympose's image sizes
<?php
/**
* Plugin Name: Sympose: Overwrite Image Sizes
*/
add_action('init', function() {
add_image_size( 'person-medium', 150, 150, true );
}, 20);
@mklasen
mklasen / class-sample.php
Last active March 14, 2020 12:26
Add featured image to Latest Posts Block in Block Editor / Gutenberg
<?php
class Sample {
public function __construct() {
$this->hooks();
}
public function hooks() {
// Remove the existing block register function
remove_action( 'init', 'register_block_core_latest_posts', 10 );