Skip to content

Instantly share code, notes, and snippets.

View qutek's full-sized avatar
💻
Working from home

Lafif Astahdziq qutek

💻
Working from home
View GitHub Profile
@qutek
qutek / functions.php
Created March 5, 2015 07:49
[Wordpress] Allow user login with email
<?php
/**
* login_with_email filter to the authenticate filter hook, to fetch a username based on entered email
* @param obj $user
* @param string $username [description]
* @param string $password [description]
* @return boolean
*/
add_filter('authenticate', 'login_with_email', 20, 3);
@qutek
qutek / gist:a700c5b8b231e99c1d07
Last active November 29, 2015 20:25 — forked from saetia/gist:1623487
OSX Preference

OS X Preferences


#Disable window animations
defaults write NSGlobalDomain NSAutomaticWindowAnimationsEnabled -bool false

#Enable repeat on keydown
defaults write -g ApplePressAndHoldEnabled -bool false
@qutek
qutek / Default (OSX).sublime-keymap
Created April 6, 2015 09:32
[Mac] Linux sublime keymap for OSX
/*
Replace default osx keymap, or just add this to Preferences -> Key Bindings -> User
*/
[
{ "keys": ["ctrl+q"], "command": "exit" },
{ "keys": ["ctrl+shift+n"], "command": "new_window" },
{ "keys": ["ctrl+shift+w"], "command": "close_window" },
{ "keys": ["ctrl+o"], "command": "prompt_open_file" },
{ "keys": ["ctrl+shift+t"], "command": "reopen_last_file" },
@qutek
qutek / query
Created May 7, 2015 06:39
[Wordpress][Database] Display meta_value as column
SELECT p.ID, p.post_type, p.post_status, m.* FROM wp_posts p LEFT JOIN
( SELECT
post_id,
GROUP_CONCAT(if(meta_key = 'campaign_description', meta_value, NULL)) AS 'description',
GROUP_CONCAT(if(meta_key = 'campaign_start', meta_value, NULL)) AS 'start',
GROUP_CONCAT(if(meta_key = 'campaign_end', meta_value, NULL)) AS 'end',
GROUP_CONCAT(if(meta_key = 'campaign_priority', meta_value, NULL)) AS 'priority'
FROM wp_postmeta
GROUP BY post_id ) m
ON m.post_id = p.ID
@qutek
qutek / repeatable-fields-metabox.php
Last active August 29, 2015 14:21 — forked from helen/repeatable-fields-metabox.php
Repeatable field for metabox
<?php
/**
* Repeatable Custom Fields in a Metabox
* Author: Helen Hou-Sandi
*
* From a bespoke system, so currently not modular - will fix soon
* Note that this particular metadata is saved as one multidimensional array (serialized)
*/
function hhs_get_sample_options() {
@qutek
qutek / file.php
Created May 15, 2015 04:30
[php][array] get random most priority value
<?php
/**
* getMostPriority()
* Utility function for getting random values with weighting.
* Pass in an associative array, such as array('A'=>5, 'B'=>45, 'C'=>50)
* An array like this means that "A" has a 5% chance of being selected, "B" 45%, and "C" 50%.
* The return value is the array key, A, B, or C in this case. Note that the values assigned
* do not have to be percentages. The values are simply relative to each other. If one value
* weight was 2, and the other weight of 1, the value with the weight of 2 has about a 66%
* chance of being selected. Also note that weights should be integers.
@qutek
qutek / file.php
Created May 20, 2015 04:35
[php] Replace special character using preg replace
<?php
//Remove from a single line string
$output = "Likening ‘not-critical’ with";
$output = preg_replace('/[^(\x20-\x7F)]*/','', $output);
echo $output;
//Remove from a multi-line string
$output = "Likening ‘not-critical’ with \n Likening ‘not-critical’ with \r Likening ‘not-critical’ with. ' ! -.";
$output = preg_replace('/[^(\x20-\x7F)\x0A\x0D]*/','', $output);
echo $output;
@qutek
qutek / functions.php
Created May 22, 2015 02:34
[Wordpress] Custom display setting section do_setting_section()
<?php
function custom_do_settings_sections($page) {
global $wp_settings_sections, $wp_settings_fields;
if ( !isset($wp_settings_sections) || !isset($wp_settings_sections[$page]) )
return;
foreach( (array) $wp_settings_sections[$page] as $section ) {
echo "<h3>{$section['title']}</h3>\n";
call_user_func($section['callback'], $section);
@qutek
qutek / functions.php
Created June 4, 2015 04:58
[Wordpress][Snipets] Get featured image url or first image on content
<?php
/**
* Get the Featured image URL of a post
* @global object $post
* @param string $size
* @return string
*/
function funkmo_get_post_thumbnail_url($post_id='') {
$image_url = '';
@qutek
qutek / whatissoslow.php
Last active August 29, 2015 14:27 — forked from Viper007Bond/whatissoslow.php
WordPress: Times how long it takes each filter and action to run and displays results at the end of the page. Quick and dirty.
<?php
/**
* This little class records how long it takes each WordPress action or filter
* to execute which gives a good indicator of what hooks are being slow.
* You can then debug those hooks to see what hooked functions are causing problems.
*
* This class does NOT time the core WordPress code that is being run between hooks.
* You could use similar code to this that doesn't have an end processor to do that.
*