Skip to content

Instantly share code, notes, and snippets.

View rinatkhaziev's full-sized avatar
🤖
Cache rules everything around me

Rinat K rinatkhaziev

🤖
Cache rules everything around me
View GitHub Profile
@rinatkhaziev
rinatkhaziev / nginx-wp-in-subfolder.rewrite.conf
Last active November 15, 2018 06:25
Nginx rewrite rules when WordPress core files are in a subfolder
# Files are physically in `wp` subfolder but we'd like to serve requests /
# Goes inside server { } block
if (!-e $request_filename) {
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$request_uri/ permanent;
# WordPress in a subdirectory rewrite rules
rewrite ^/([_0-9a-zA-Z-]+/)?(wp-.*|xmlrpc.php) /wp/$2 break;
}
@rinatkhaziev
rinatkhaziev / list-duplicate-terms-in-the-taxonomy.php
Created October 17, 2018 17:32
WP CLI: list terms with the same name in a hierarchical taxonomy for sites in multisite network.
<?php
/**
* List terms (categories) with the same name for each of the blog with a sticker.
*
* This is a one-off, but could be easily abstracted to be more versatile.
*
* @subcommand list-multiple-terms-with-the-same-name
* @synopsis [--taxonomy=<category>]
*/
@rinatkhaziev
rinatkhaziev / make-donald-drumpf-again.php
Last active March 11, 2016 17:01
Make Donald Drumpf Again
<?php
add_filter( 'the_content', 'make_donald_drumpf_again', 666 );
add_filter( 'the_title', 'make_donald_drumpf_again', 666 );
add_filter( 'comment_text', 'make_donald_drumpf_again', 666 );
function make_donald_drumpf_again( $content ) {
return str_replace( 'Trump', 'Drumpf', $content );
}
@rinatkhaziev
rinatkhaziev / post_thumbnail_html-placeholder.php
Created September 21, 2015 17:03
Display placeholder image when there's no thumbnail for the post
<?php
/**
* Filter to put a placeholder in, when there's no thumbnail set for post (which is the case for a lot of legacy posts)
*/
add_filter( 'post_thumbnail_html', function( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
// We have a thumb, return it
if ( $html )
return $html;
$placeholder_url = 'http://full.url.to/placeholder_image';
@rinatkhaziev
rinatkhaziev / dfp-async-mulltisizes.php
Created September 15, 2015 20:32
Multiple sizes per slot
<?php
add_filter( 'acm_ad_tag_ids', 'my_acm_ad_tag_ids' );
function my_acm_ad_tag_ids( $tag_ids ) {
$tag_ids[] = array(
'tag' => 'flex-leaderboard', // tag_id
'url_vars' => array(
'sizes' => array(
array(
'width' => '728',
'height' => '90'
@rinatkhaziev
rinatkhaziev / fu-akismet.php
Created October 22, 2014 01:01
Akismet 3 integration for Frontend Uploader
<?php
/**
* Akismet 3 integration
*/
add_filter( 'fu_should_process_content_upload', 'fu_akismet_check_submission', 10, 2 );
function fu_akismet_check_submission( $should_process, $layout ) {
// Akismet is not enabled or not configured, or too old, just return the filter value
if ( ! class_exists( 'Akismet' ) || !method_exists( 'Akismet', 'get_api_key' ) || ! Akismet::get_api_key() )
return $should_process;
@rinatkhaziev
rinatkhaziev / filter_wpcom_elasticsearch_query_args.php
Created October 6, 2014 14:25
wpcom_elasticsearch_query_args example nested boolean OR filter
<?php
/**
* ES Query args filter
*/
add_filter( 'wpcom_elasticsearch_query_args', function( $args, $query ) {
// Modify sort query
$args['sort'] = array(
array(
'modified' => array( "order" => 'desc' ),
),
{
"suggest": {
"text": keyword,
"title-suggest": {
"term": { "field": "title" },
"size": 3
},
}
@rinatkhaziev
rinatkhaziev / simple-ndn-embed.php
Last active August 29, 2015 14:01
Simple shortcode callback for v2 NDN player
<?php
/*
Plugin Name: Doejo NDN Shortcode
Description: Simple NDN Shortcode
Author: Rinat Khaziev, doejo
Version: 0.7.5
Author URI: http://digitallyconscious.com
GNU General Public License, Free Software Foundation <http://creativecommons.org/licenses/GPL/2.0/>
@rinatkhaziev
rinatkhaziev / dfp-async-sample.php
Created July 23, 2013 15:43
Sample code of DFP Async setTargeting support for ACM
<?php
class Doubleclick_For_Publishers_Async_ACM_Provider extends ACM_Provider {
public $crawler_user_agent = 'Mediapartners-Google';
function filter_output_html( $output_html, $tag_id ) {
// .. omitted
$targeting_params_array = apply_filters( 'acm_targeting_params', array( 'kw' => 'testkeyword' ), $tag_id );
$targeting_string = $this->format_targeting_string( $targeting_params_array );