Skip to content

Instantly share code, notes, and snippets.

@ChrisFlannagan
ChrisFlannagan / geodistance.php
Created October 13, 2017 16:52
Calculate distance between to coordinates of latitude and longitude using the WP REST API and return posts ordered by distance from user's coordinates
<?php
/**
* Heavily borrowed from: http://xplus3.net/2010/08/08/filtering-on-a-non-standard-database-field-with-wordpress/
**/
class CoordinatesTable extends DB {
protected $db_option = "coordinates_db";
@bekarice
bekarice / registration-order-link-for-woocommerce.php
Last active September 13, 2024 07:59
Automatically link previous orders to new WooCommerce customer accounts upon registration
@glueckpress
glueckpress / wp-rocket-affiliatewp-cookies-cache.php
Last active March 26, 2019 21:24
[WordPress][WP Rocket] Creates cached files based on dynamic cookies for AffiliateWP. (WP Rocket 2.7+ required.)
<?php
/**
* Plugin Name: WP Rocket | AffiliateWP Cookie Cache
* Description: Creates a specific cache for each affiliate ref ID.
* Author: WP Rocket Support Team
* Author URI: http://wp-rocket.me/
* Plugin URI: https://gist.github.com/glueckpress/d379c5534708f440942523fe205ec840
* License: GNU General Public License v3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
@mathetos
mathetos / plugin.php
Last active April 13, 2023 16:48
Dependent Plugin Activation/Deactivation and Alert
<?php
/*
* Dependent Plugin Activation/Deactivation
*
* Sources:
* 1. https://pippinsplugins.com/checking-dependent-plugin-active/
* 2. http://10up.com/blog/2012/wordpress-plug-in-self-deactivation/
*
*/
@scottopolis
scottopolis / thumbnail-featured-url-wp-api.php
Last active September 5, 2024 01:54
Add post thumbnail (featured image) url to WP-API response
@scottopolis
scottopolis / wp-api-user-meta.php
Last active April 18, 2020 19:13
Add user meta to the WP-API
<?php
/* Adds all user meta to the /wp-json/wp/v2/user/[id] endpoint */
function sb_user_meta( $data, $field_name, $request ) {
if( $data['id'] ){
$user_meta = get_user_meta( $data['id'] );
}
if ( !$user_meta ) {
return new WP_Error( 'No user meta found', 'No user meta found', array( 'status' => 404 ) );
}
@scottopolis
scottopolis / wp-api-custom-taxonomies.php
Created October 27, 2015 22:27
Add custom taxonomies to the WP-API
<?php
function ms_add_tax_to_api() {
$taxonomies = get_taxonomies( '', 'objects' );
foreach( $taxonomies as $taxonomy ) {
$taxonomy->show_in_rest = true;
}
}
add_action( 'init', 'ms_add_tax_to_api', 30 );
@ultimatemember
ultimatemember / gist:08c7f3369f49021cb749
Last active April 4, 2018 14:20
How to stop registration using Ultimate Member action hooks
/*
You need to hook into um_submit_form_errors_hook with a
priority over 10.
You can stop registration here if the customer_code field does not
match the value you want "ALLOWED_VALUE" in this example
*/