Skip to content

Instantly share code, notes, and snippets.

View hatsumatsu's full-sized avatar
🛸

Martin Wecke hatsumatsu

🛸
View GitHub Profile
@hatsumatsu
hatsumatsu / lukas.php
Last active March 12, 2019 11:56
Custom query vars, rewrite rules and admin columns
/**
* Make a custom permalink structure on top of a custom post type for yearly archives
* mapping the year to a meta field
*/
/**
* Register a custom query variable in our example 'event_year'
* This can later be used in WP_Query like `get_query_var( 'event_year' )`
<?php
/**
* Modify ACF's WYSIWYG field toolbar
* @param array $toolbars toolbars
* @return array toolbars
*/
function modify_acf_editor_toolbars( $toolbars ) {
$toolbars['Minimal' ] = array();
$toolbars['Minimal' ][1] = array(
<?php
/**
* Flush W3TC page cache when custom post types are updated.
*/
function flushCustomPostTypesPageCache( $post_id ) {
$custom_post_types = array(
'post_type' => true
);
@hatsumatsu
hatsumatsu / lukas.php
Created July 18, 2018 14:08
Hi Lukas!
<?php
/**
* Temporary function:
* @return [type] [description]
*/
function convert_to_legacy_posts() {
if( !is_admin() ) {
return;
}
@hatsumatsu
hatsumatsu / array.shuffle.js
Created November 22, 2016 11:31
Array.Shuffle
http://stackoverflow.com/a/10142256/2799523
Array.prototype.shuffle = function() {
var i = this.length, j, temp;
if ( i == 0 ) return this;
while ( --i ) {
j = Math.floor( Math.random() * ( i + 1 ) );
temp = this[i];
this[i] = this[j];
this[j] = temp;
$tags = um_user( 'Musicstyles' );
if( $tags ) {
foreach( $tags as $tag ) {
$tag_object = get_term_by( 'id', $tag, 'um_user_tag' );
$url = 'https://resonate.is/musicians/?Musicstyles=' . $tag_object->slug;
$label = $tag_object->name;
if( $label ) {
echo '<a href="' . esc_url( $url ) . '">' . wptexturize( $label ) . '</a>';
/**
* Get the total number of users by user role
*
* Usage:
*
* if( function_exists( 'get_resonate_user_count' ) ) {
* if( $count = get_resonate_user_count( 'my-custom-user-role' ) ) {
* echo sprintf( __( 'My user rule has %s users.' ), $count );
* }
* }
/**
* Extract the twitter user name from a twitter URL
* @param [type] $user_name [description]
* @return [type] [description]
*/
public static function extract_username_from_url( $user_name ) {
// remove https://twitter.com/
$user_name = str_replace( 'https://twitter.com/', '', $user_name );
$user_name = str_replace( 'https://www.twitter.com/', '', $user_name );
@hatsumatsu
hatsumatsu / sampler.js
Created April 21, 2016 09:54
Tone.js Safari debug
var Sampler = ( function() {
var settings = {
samples: {
'808': {
0: 'bass.mp3'
}
},
bpm: 110,
isPlaying: false,
isLoaded: false,
@hatsumatsu
hatsumatsu / page-transitions.js
Last active April 11, 2016 10:13
page transition module
// module pageTransitions
var pageTransitions = ( function() {
var settings = {
duration: 500,
selector: 'a[href^="' + globals.blogurl + '"]:not([data-page-transition="ignore"])'
};
var init = function() {
$( 'html' )