This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Pull apart OEmbed video link to get thumbnails out*/ | |
function get_video_thumbnail_uri( $video_uri ) { | |
$thumbnail_uri = ''; | |
// determine the type of video and the video id | |
$video = parse_video_uri( $video_uri ); | |
// get youtube thumbnail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getTaxTermsByOtherTaxTerm($taxonomy_args, $out_taxonomy, $post_type = NULL) { | |
global $wpdb; | |
$tax_q = $taxonomy_ids = array(); | |
$post_type_q = !empty($post_type_q) ? "AND p.post_type = '$post_type'" : ""; | |
foreach ($taxonomy_args as $tax => $term_id) { | |
$sql = "SELECT tt.term_taxonomy_id FROM $wpdb->term_taxonomy AS tt | |
INNER JOIN $wpdb->term_taxonomy t ON (t.term_id = tt.term_id AND tt.taxonomy = '$tax' AND t.term_id = $term_id)"; | |
$taxonomy_ids = array_merge( $taxonomy_ids, $wpdb->get_col($sql) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* filter to get "services" in product categories, child categories, and singe product pages correctly */ | |
// /services/%product_cat%/ - Product base permalink settings | |
// services - Product Category base permalink settings | |
add_filter('rewrite_rules_array', function( $rules ) { | |
$new_rules = array( | |
'services/([^/]*?)/page/([0-9]{1,})/?$' => 'index.php?product_cat=$matches[1]&paged=$matches[2]', | |
'services/([^/]*?)/([^/]*?)/page/([0-9]{1,})/?$' => 'index.php?product_cat=$matches[2]&paged=$matches[3]', | |
'services/([^/]*?)/?$' => 'index.php?product_cat=$matches[1]', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$files = array('file1.txt', 'file2.csv', 'file3.png'); | |
$zip = new ZipArchive(); | |
$zip_name = "out/" . time() . ".zip"; // Zip name | |
$zip->open($zip_name, ZipArchive::CREATE); | |
foreach ($files as $path) { | |
if (file_exists($path)) { | |
$zip->addFromString(basename($path), file_get_contents($path)); | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'post_type_archive_link', 'fix_post_type_archive_link', 10, 2 ); | |
function fix_post_type_archive_link( $link, $post_type ) { | |
if($post_type == 'scripts'){ | |
$link = str_replace('/%some-slug%', '', $link); | |
} | |
return $link; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
'rewrite' => array('slug' => 'scripts/%custom-taxonomy%'), // register post type arg 'rewrite' | |
*/ | |
add_filter('post_type_link', 'change_cpt_post_permalink', 99, 3); | |
function change_cpt_post_permalink($permalink, $post_id) { | |
if (strpos($permalink, '%custom-taxonomy%') === FALSE) | |
return $permalink; | |
$post = get_post($post_id); | |
if (!$post) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('manage_users_columns','kjl_modify_user_columns'); | |
function kjl_modify_user_columns($column_headers) { | |
//unset($column_headers['posts']); | |
$column_headers['status'] = 'Status'; | |
return $column_headers; | |
} | |
function kjl_user_posts_count_column_content($value, $column_name, $user_id) { | |
//$user = get_userdata($user_id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add ACF Columns | |
function add_new_product_cat_column($column) { | |
$column['english_name'] = 'English Name'; | |
return $column; | |
} | |
add_filter('manage_edit-product_category_columns', 'add_new_product_cat_column'); | |
function add_new_product_cat_admin_column_show_value( $content, $column_name, $term_id ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get Youtube URL | |
$yturl = 'https://www.youtube.com/watch?v=HhAKNSsb4t4'; | |
preg_match("/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'>]+)/", $yturl, $matches); | |
$video_id = $matches[1]; | |
// Get Thumbnail | |
$file_headers = get_headers( 'http://img.youtube.com/vi/' . $video_id . '/maxresdefault.jpg' ); | |
$is_404 = $file_headers[0] == 'HTTP/1.0 404 Not Found' || false !== strpos( $file_headers[0], '404 Not Found' ); | |
$video_thumbnail_url = $is_404 ? 'http://img.youtube.com/vi/' . $youtube_id . '/maxresdefault.jpg' : 'http://img.youtube.com/vi/' . $video_id . '/hqdefault.jpg'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* For debug | |
* show template file name | |
* ---------------------------------------------------------*/ | |
function show_template() { | |
global $template; | |
echo basename( $template ); | |
} |