Skip to content

Instantly share code, notes, and snippets.

Yoren Chang yoren

Block or report user

Report or block yoren

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:9a84d039b42c4f6cd9c1bd2c821e32bd
### Keybase proof
I hereby claim:
* I am yoren on github.
* I am yoren (https://keybase.io/yoren) on keybase.
* I have a public key whose fingerprint is 87BF F3DA 7D0C 3BE8 1151 C583 8F39 C153 6FC8 D42C
To claim this, I am signing this object:
@yoren
yoren / functions.php
Created Oct 25, 2016
Get terms by custom post types and taxonomy
View functions.php
<?php
/**
* my_terms_clauses
*
* filter the terms clauses
*
* @param $clauses array
* @param $taxonomy string
* @param $args array
@yoren
yoren / functions.php
Last active Aug 15, 2016
Changing arguments for the built-in taxonomies in WordPress
View functions.php
<?php
function ofix_register_tax_args( $args, $taxonomy, $object_type ) {
if ( 'link_category' === $taxonomy ) {
$args['public'] = true;
$args['query_var'] = true;
}
return $args;
@yoren
yoren / 1fix-switch-theme-on-certain-pages.php
Created Aug 10, 2016
WordPress tiny plugin - Switch theme on certain pages
View 1fix-switch-theme-on-certain-pages.php
<?php
/**
* @package One_Fix_Switch_Theme
* @version 1.0
*/
/*
Plugin Name: One Fix Switch Theme
Plugin URI: https://www.1fix.io
Description: Switch theme on certain pages.
Author: Yoren Chang
@yoren
yoren / functions.php
Last active Feb 29, 2016
Using meta_query With WP API V2
View functions.php
<?php
function my_allow_meta_query( $valid_vars ) {
$valid_vars = array_merge( $valid_vars, array( 'meta_key', 'meta_value', 'meta_query' ) ); // Omit meta_key, meta_value if you don't need them
return $valid_vars;
}
add_filter( 'rest_query_vars', 'my_allow_meta_query' );
@yoren
yoren / nginx.conf
Last active Mar 13, 2016
Proxy WP content images for your local server
View nginx.conf
// Source: https://www.chriswiegman.com/2016/02/getting-media-on-your-local-wordpress-site/
// But if you need an nginx flavor
// Put this in your server block
rewrite ^/wp-content/uploads(.+)$ http://myurl.com/wp-content/uploads$1 last;
@yoren
yoren / functions.php
Last active Apr 17, 2018
Parent Post From Another Post Type And A New URL Structure In WordPress
View functions.php
<?php
// Flush rewrite rules after switch theme
function my_rewrite_flush() {
flush_rewrite_rules();
}
add_action( 'after_switch_theme', 'my_rewrite_flush' );
// A little help so we can get the stylesheet from parent theme
// Remove line 10-19 if this is not a child theme
function my_enqueue_styles() {
@yoren
yoren / extra.php
Last active Aug 3, 2016
Cookie Authentication In A AngularJS WordPress Theme
View extra.php
<?php
// The following function is from: https://github.com/WP-API/WP-API/blob/2.0-beta4/extras.php#L84-L136
/**
* Check for errors when using cookie-based authentication.
*
* WordPress' built-in cookie authentication is always active
* for logged in users. However, the API has to check nonces
* for each request to ensure users are not vulnerable to CSRF.
*
* @global mixed $wp_rest_auth_cookie
@yoren
yoren / functions-1.php
Last active Feb 18, 2016
Upgrading Your AngularJS Theme To Work With WP API V2
View functions-1.php
<?php
function my_rest_prepare_post( $data, $post, $request ) {
$_data = $data->data;
$thumbnail_id = get_post_thumbnail_id( $post->ID );
$thumbnail = wp_get_attachment_image_src( $thumbnail_id );
$_data['featured_image_thumbnail_url'] = $thumbnail[0];
$data->data = $_data;
@yoren
yoren / functions.php
Created Jul 24, 2015
Testing if a post is in a descendant category
View functions.php
<?php
/**
* Tests if any of a post's assigned categories are descendants of target categories
*
* @param int|array $cats The target categories. Integer ID or array of integer IDs
* @param int|object $_post The post. Omit to test the current post in the Loop or main query
* @return bool True if at least 1 of the post's categories is a descendant of any of the target categories
* @see get_term_by() You can get a category by name or slug, then pass ID to this function
* @uses get_term_children() Passes $cats
* @uses in_category() Passes $_post (can be empty)
You can’t perform that action at this time.