Skip to content

Instantly share code, notes, and snippets.

@pareshsojitra
pareshsojitra / limit-search-to-post-types.php
Created February 7, 2021 15:14 — forked from devinsays/limit-search-to-post-types.php
Code snippet examples showing how to limit search to post types
<?php
// Change search function globally to search only post, page and portfolio post types
function prefix_limit_post_types_in_search( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', array( 'post','page', 'portfolio' ) );
}
return $query;
}
add_filter( 'pre_get_posts', 'prefix_limit_post_types_in_search' );
?>
@pareshsojitra
pareshsojitra / tracking.js
Created February 7, 2021 15:13 — forked from devinsays/tracking.js
Track JetPack Shares in Google Analytics
/**
* Javacript for loading custom Google Analytics events
*
* @since 1.0.0
*/
(function($) {
// GA Docs for Social Interactions:
// https://developers.google.com/analytics/devguides/collection/analyticsjs/social-interactions
@pareshsojitra
pareshsojitra / iframe-data-decode.js
Last active February 7, 2021 15:13 — forked from devinsays/iframe-data-decode.js
Mixpanel Multiple Domain Tracking
// Parses the url for query strings
function prefix_return_query_strings( url ) {
var urlParams;
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = url.search.substring(1);
urlParams = {};
while (match = search.exec(query) ) {
<?php
/**
* Sets up the Easy Post API Endpoints
*
* @package WP Theming
*/
/**
* Sets up a JSON endpoint at /wp-json/easy-post/v1/rates/
@pareshsojitra
pareshsojitra / estimate-read-time.php
Created February 7, 2021 15:09 — forked from devinsays/estimate-read-time.php
WordPress Estimated Read Time
<?php
/**
* Estimates the reading time for a given piece of $content.
*
* @param string $content Content to calculate read time for.
* @param int $wpm Estimated words per minute of reader.
*
* @returns int $time Esimated reading time.
*/
function prefix_estimated_reading_time( $content = '', $wpm = 300 ) {
@pareshsojitra
pareshsojitra / woocommerce-cart-restrictions.php
Created February 7, 2021 15:09 — forked from devinsays/woocommerce-cart-restrictions.php
Restricts which items can be added to cart based on whether a specific item is already in the cart or being added to the cart.
<?php
/**
* WooCommerce code snippet that restricts which items can be added to cart:
*
* 1) The $trial_product should not be added to cart if existing items are in the cart.
* 2) Other products should not be added to cart if $trial_product is already in cart.
*/
function example_cart_filtering( $passed_validation, $product_id ) {
// ID of the trial product
@pareshsojitra
pareshsojitra / set-cookie-wordpress.php
Created February 7, 2021 15:08 — forked from devinsays/set-cookie-wordpress.php
How to set a cookie using PHP in WordPress
@pareshsojitra
pareshsojitra / class-trial-subscription.php
Created February 7, 2021 15:08 — forked from devinsays/class-trial-subscription.php
Creates a subscription in the background when a trial product is purchased.
<?php
/**
* When a trial product is purchased we create an order for a subscription product.
*
* This subscription order charges after 14 days if customer does not cancel.
*/
class Nano_Trial_Subscription {
/**
@pareshsojitra
pareshsojitra / class-nano-trial-subscription.php
Created February 7, 2021 15:07 — forked from devinsays/class-nano-trial-subscription.php
Add a trial subscription product to the cart during order processing.
<?php
/**
* When a trial product is purchased we add a subscription product the order
* directly before order processing.
*
* This subscription order charges after 14 days if customer does not cancel.
*/
class Nano_Trial_Subscription {
@pareshsojitra
pareshsojitra / .htaccess
Created February 7, 2021 15:07 — forked from devinsays/.htaccess
Restrict access to site to specific IPs
order deny,allow
deny from all
allow from 98.6.000.111
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f