Skip to content

Instantly share code, notes, and snippets.

View mklasen's full-sized avatar

Marinus Klasen mklasen

View GitHub Profile
@mklasen
mklasen / compare.dates.php
Created February 28, 2017 13:37
Compare between dates in PHP
$today = new Datetime();
$min = DateTime::createFromFormat('d/m/Y', '25/02/2017');
$max = DateTime::createFromFormat('d/m/Y', '03/03/2017');
if ($min->getTimestamp() <= $today->getTimestamp() && $max->getTimestamp() >= $today->getTimestamp()) {
//
}
@mklasen
mklasen / AWP.snippet.photoheight.html
Last active March 3, 2017 16:41
Keep those photos the same height
<style>
.mk-flex-photo-container {
display: flex;
width: 100%;
justify-content: center;
box-shadow: 0 0 black;
}
.mk-flex-photo-container a {
margin: 0 10px;
}
@mklasen
mklasen / gotoline.atom.keymap.cson
Created March 7, 2017 13:54
Atom custom keybinding for Go to Line
'atom-text-editor':
'cmd-shift-G': 'go-to-line:toggle'
@mklasen
mklasen / check.edit.post.php
Last active March 11, 2017 00:20
Show a message on front-end when someone is editing the post
<?php
function mk_check_edit_in_progress($content) {
if (!is_single())
return $content;
if ( !$lock = get_post_meta( get_the_ID(), '_edit_lock', true ) )
return false;
$lock = explode( ':', $lock );
$time = $lock[0];
$user_id = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true );
@mklasen
mklasen / wc.remove.quantity.php
Created April 4, 2017 15:03
Remove Quantity field from Woocommerce
<?php
// https://github.com/woocommerce/woocommerce/issues/424#issuecomment-8586651
add_filter( 'woocommerce_is_sold_individually', 'wc_remove_all_quantity_fields', 10, 2 );
function wc_remove_all_quantity_fields( $return, $product ) {
return( true );
}
@mklasen
mklasen / remove.thumb.woocommerce.php
Created May 4, 2017 18:33
Remove woocommerce product thumbnail from loop
<?php
add_action('woocommerce_init', function() {
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
});
@mklasen
mklasen / wp-config.php
Created May 16, 2017 12:03
S3 wp-config.php
define( 'S3_UPLOADS_BUCKET', '' );
define( 'S3_UPLOADS_KEY', '' );
define( 'S3_UPLOADS_SECRET', '');
define( 'S3_UPLOADS_REGION', 'eu-central-1' ); // the s3 bucket region, required for Frankfurt and Beijing.
@mklasen
mklasen / xdebug.var_dump.length.php
Last active August 30, 2017 17:29
Set depth/children of xdebug's var_dump
ini_set('xdebug.var_display_max_depth', -1);
ini_set('xdebug.var_display_max_children', -1);
ini_set('xdebug.var_display_max_data', -1);
@mklasen
mklasen / vagrant-hostupdater
Created January 4, 2018 22:37
Working vagrant-hostupdater sudoers.d file for MacOS
# Allow passwordless startup of Vagrant with vagrant-hostsupdater.
Cmnd_Alias VAGRANT_HOSTS_ADD = /bin/sh -c echo "*" >> /etc/hosts
Cmnd_Alias VAGRANT_HOSTS_REMOVE = /usr/bin/sed -i -e /*/ d /etc/hosts
%admin ALL=(root) NOPASSWD: VAGRANT_HOSTS_ADD, VAGRANT_HOSTS_REMOVE
@mklasen
mklasen / customize.rest.api.php
Last active March 16, 2018 05:48
Link image to after uploading to /wp/v2/media (do an action after attachment has been inserted, use $request parameters)
<?php
add_action('rest_insert_attachment', function($attachment, $request, $creating) {
$data = $request->get_params(); // Extra data that was sent to /wp/v2/media
// In this example we can use $data['entry_id']
// Something like: update_post_meta((int) $data['entry_id'], 'attachment_id', $attachment['ID']);
});