Skip to content

Instantly share code, notes, and snippets.

Phil Banks emirpprime

Block or report user

Report or block emirpprime

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
@emirpprime
emirpprime / time_machine.php
Last active May 20, 2018
Filter the *displayed* time of posts in WordPress to move them into the past/future.
View time_machine.php
/**
* Filter the_time function to show posts as being from another date/time.
*
* @param string $formatted The formatted time.
* @param string $format The time format used.
* @return string Modified formatted time.
*/
function cc_time_machine( $formatted, $format ) {
$offset = get_option( 'cc_time_offset' ); // Offset in days, can be negative.
if ( $offset ) {
@emirpprime
emirpprime / remove_post_type_breadcrumb.php
Created May 17, 2018
Remove post type from Breadcrumb NavXT breadcrumbs when viewing Tag archives.
View remove_post_type_breadcrumb.php
<?php
/**
* Filter breadcrumbs to remove post archive when viewing Tag archives.
*/
add_action( 'bcn_after_fill', function( $bcn_breadcrumb_trail ){
// Bail early if not a tag archive.
if ( ! is_tag() ) {
return $bcn_breadcrumb_trail;
}
View RegEx to link Twitter Usernames and Hashtags (e.g. in WordPress)
@emirpprime
emirpprime / exclude_posts_with_term.php
Last active Jan 31, 2018
Exclude posts with a term in a taxonomy from search
View exclude_posts_with_term.php
<?php
/**
* Exclude posts with term 'bananas' from Search.
*/
function cc_search_filter( $query ) {
if ( ! is_admin() && $query->is_main_query() ) {
if ( $query->is_search ) {
$query->set(
'tax_query',
array(
@emirpprime
emirpprime / exclude_posts_with_meta.php
Created Jan 31, 2018
Exclude posts with a custom meta value from search
View exclude_posts_with_meta.php
<?php
/**
* Exclude posts with 'fruit' custom meta field value of 'bananas' from site Search
*/
function cc_search_filter( $query ) {
if ( ! is_admin() && $query->is_main_query() ) {
if ( $query->is_search ) {
$query->set( 'meta_query',
array(
'relation' => 'OR',
@emirpprime
emirpprime / update_htaccess.php
Last active Jul 26, 2017
Example snippet showing how to update the WordPress .htaccess file programatically
View update_htaccess.php
<?php
/**
* Update .htaccess to whitelist logo when modified in platform settings.
*/
function cc_logo_htaccess() {
// Fire only on Platform Settings options page.
$screen = get_current_screen();
if ( 'cc-configurator_page_cc-settings' === $screen->id && ( $_POST['acf']['field_576c2a5137029'] || $_POST['acf']['field_576c2a9e3702a'] ) ) {
// Store files in an array.
@emirpprime
emirpprime / update_htpasswd.sh
Created Jul 26, 2017
Bash script to help manage .htpasswd files
View update_htpasswd.sh
#!/bin/bash
#
# Manage .htpasswd files
# Store script name for use in output.
me=$( basename $0 )
# Utility function for exiting.
@emirpprime
emirpprime / functions.php
Last active Feb 1, 2017
Show WordPress "authors" only the comments on their posts
View functions.php
<?php
/**
* Clone of wp_count_comments from WP4.2.
*/
function myblogs_count_comments( $post_id = 0 ) {
global $wpdb;
$post_id = (int) $post_id;
/**
* Filter the comments count for a given post.
@emirpprime
emirpprime / cpt_term_list.php
Created Dec 21, 2016
Get a list of terms from a shared taxonomy that are used on a particular post type only
View cpt_term_list.php
<?php ?>
<label for="filter-country">Country</label>
<select id="filter-country" class="form-control" name="country">
<option selected="" value="">All countries</option>
<?php
if ( false === ( $cptcountries = get_transient( 'cpt_countries' ) ) ) {
global $wpdb;
$cpt_countries = $wpdb->get_col( "select distinct term_taxonomy_id from $wpdb->term_relationships where object_id in ( select ID from $wpdb->posts where post_type='cpt' )" );
$cptcountries = get_terms( array( 'taxonomy' => 'country', 'include' => $cpt_countries ) );
if ( ! empty( $cptcountries ) && ! is_wp_error( $cptcountries ) ) {
@emirpprime
emirpprime / tinymce_garlicjs_compat.php
Created Dec 7, 2016
Make TinyMCE compatible with Garlic.js in Wordpress
View tinymce_garlicjs_compat.php
/**
* Add Garlic.js compatability to TinyMCE on front-end
*
* @param array $settings TinyMCE settings array.
* @return array Modified TinyMCE settings array.
*/
function mytheme_tinymce_garlicjs_compat( $settings ) {
if ( ! is_admin() ) {
$settings['setup'] = "function(editor) {
editor.on('change keyup', function(e){
You can’t perform that action at this time.