Skip to content

Instantly share code, notes, and snippets.

@jchristopher
jchristopher / gist:10730056
Created April 15, 2014 12:53
Throttle the SearchWP indexer
<?php
// pause the indexer for 1s in between passes
function my_searchwp_indexer_throttle() {
return 1;
}
add_filter( 'searchwp_indexer_throttle', 'my_searchwp_indexer_throttle' );
@rogerlos
rogerlos / searchwp_results_substitute_post_for_attachment.php
Created November 11, 2014 23:49
Wordpress SearchWP: Substitute Post for Attachment in Search Results
<?php
/**
* This function will see if a PDF or other "attachment" post-type returned by SearchWP
* is present in a custom field in a regular post, and will return that post instead. Note
* this will only process documents which are referenced via the "attachment" post type.
*
* For example, you may have a product specification PDF and would like it in the search
* results, but would rather people got to it by visiting the product page itself.
*
@thomasgriffin
thomasgriffin / gist:7944588
Created December 13, 2013 13:56
Here is a surefire way to hook into save_post if you need to save stuff. In my case, it is for custom metaboxes.
<?php
/**
* Callback for saving values from metaboxes.
*
* @since 1.0.0
*
* @param int $post_id The current post ID.
* @param object $post The current post object.
*/
function tgm_save_meta_boxes( $post_id, $post ) {
@Rarst
Rarst / append.php
Last active April 27, 2016 12:31
My xhprof/uprofiler setup, tweaked for WordPress and more easily profiling segments.
<?php
use Rarst\Profiler\Handler;
global $wp;
if ( Handler::$profiling && empty( $wp ) ) {
Handler::close();
}
@jchristopher
jchristopher / gist:53d98d2a21ffad14e440
Created June 22, 2015 14:32
Programmatically implement SearchWP synonyms (you do not need the Term Synonyms extension)
<?php
add_filter( 'searchwp_term_in', 'my_find_synonyms', 10, 2 );
add_filter( 'searchwp_and_logic', '__return_false' );
function my_find_synonyms( $term, $engine ) {
global $searchwp;
if( ! class_exists( 'SearchWP' ) || version_compare( $searchwp->version, '2.0.3', '<' ) ) {
return $term;
@danielbachhuber
danielbachhuber / gist:6691084
Last active December 8, 2017 02:56
Auto-paginate after 500 words, but respect paragraphs and don't leave page stubs.
<?php
/**
* Auto-paginate after 500 words
*/
add_action( 'loop_start', function( $query ) {
if ( ! is_single() || 'post' != get_post_type() || ! $query->is_main_query() )
return;
$content = $query->posts[0]->post_content;
@spivurno
spivurno / gw-gravity-forms-exclude-forms-form-list.php
Last active December 14, 2017 02:28
Gravity Wiz // Gravity Forms // Exclude Forms from Form List
<?php
/**
* Gravity Wiz // Gravity Forms // Exclude Forms from Form List
* http://gravitywiz.com
*/
add_filter( 'query', function( $query ) {
if( rgget( 'page' ) != 'gf_edit_forms' ) {
return $query;
}
@nathansmith
nathansmith / check_all.js
Last active March 10, 2019 16:39
Used to check all checkboxes in a page.
// Paste into Firebug or Chrome Dev Tools console
// when viewing a page with multiple checkboxes.
(function(d) {
var input = d.querySelectorAll('input[type="checkbox"]');
var i = input.length;
while (i--) {
input[i].checked = true;
}
@davekiss
davekiss / gist:2639184ac066c53416b23c5a66f42d1e
Created February 2, 2019 17:44
EDD Weekly Domain Report via Email
/**
* Add a weekly email report that summarizes which domains that
* your products are being used on.
*/
add_filter( 'cron_schedules', function( $schedules ) {
$schedules['weekly'] = array(
'interval' => 604800,
'display' => __('Once Weekly')
);
@mattbanks
mattbanks / wp-setup.sh
Created March 14, 2014 18:01
Scaffold a new WordPress development site in Alfred, utilizing WP-CLI. Use this script to run as a Terminal Script. Customize for your theme needs, plugin needs, etc.
# Create directory for new site
cd ~/Sites
mkdir {query}
cd {query}
# Download latest version of WordPress
wp core download
# Setup wp-config file with WP_DEBUG enabled
wp core config --dbname={query} --dbuser=root --dbpass=root --dbprefix={query}wp_ --extra-php <<PHP