This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Class: Sample_Block_Parser | |
* | |
* @package Sample | |
* @subpackage sample-project | |
* @since 1.0.0 | |
*/ | |
add_filter( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'http_request_args', function( $args ) { | |
if ( ! defined( 'WP_IMPORTING' ) || ( defined( 'WP_IMPORTING' ) && ! WP_IMPORTING ) ) { | |
return $args; | |
} | |
if ( ! isset( $args['headers']['Authorization'] ) ) { | |
$args['headers']['Authorization'] = 'Basic ' . base64_encode( 'user:pass' ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function wpsc_get_terms_variation_sort_filter( $terms ) { | |
$new_terms = array(); | |
$unsorted = array(); | |
var_dump( $terms ); // in 4.5.2, returns an array of terms. In trunk (only in some contexts), returns a numeric string. | |
foreach ( $terms as $term ) { | |
if ( ! is_object( $term ) ) { | |
return $terms; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Plugin Name: Example Modify Price | |
*/ | |
class Example_Modify_Price { | |
private static $instance; | |
public static function register() { | |
if (self::$instance == null) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Use case: Want to order by meta key = value, while including all posts, not just those matching said meta value. | |
* | |
* WP_Query's capacity for ordering has improved so much - but as of right now, it's not possible | |
* to get _all_ posts, not just ones where a value may or may not exist, and may or may not equal something, and | |
* have all of those be at the top of results. | |
* | |
* My very specific use case: a use can set their city and it's saved as a cookie. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$form_id = 12; // Or whatever form ID has the notificaiton you're after | |
$form = GFAPI::get_form( $form_id ); | |
$notification = end( $form['notifications'] ); // Just an easy way to get the notification I wanted. YMMV. | |
$lead = array( | |
'id' => wp_generate_password( 64, true, true ), // Normally, this would be the Lead ID. Not necessary for us. | |
'form_id' => $form_id, | |
'source_url' => 'https://site.com/', | |
'status' => 'active', | |
'1.3' => $args['first_name'], // YMMV on these args - set them to whatever your form sets them to be. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'woocommerce_new_customer_data', function( $data ) { | |
$data['user_login'] = $data['user_email']; | |
return $data; | |
} ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'pre_get_posts', function( $query ) { | |
if ( ( is_post_type_archive( 'special-cpt' ) || ( is_search() && 'special-cpt' == $query->get( 'post_type' ) ) ) && $query->is_main_query() ) { | |
$query->set( 'orderby' , 'title' ); | |
$query->set( 'order' , 'ASC' ); | |
$query->set( 'tax_query', array( | |
array( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'posts_search', function( $sql, $wp_query ) { | |
global $wpdb; | |
$sql .= "OR $wpdb->posts.post_excerpt LIKE '%s' AND $wpdb->posts.post_type NOT IN ('some-post-type', 'another-post-type')"; | |
return $sql; | |
}, 10, 2 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function wpsc_hide_shipping_fields_if_no_shipping( $fields ) { | |
if ( wpsc_uses_shipping() || is_admin() ) { | |
return $fields; | |
} | |
foreach ( $fields as $index => $field ) { | |
if ( false !== strpos( $field->unique_name, 'shipping' ) || 'delivertoafriend' == $field->unique_name ) { | |
unset( $fields[ $index ] ); |
NewerOlder