Skip to content

Instantly share code, notes, and snippets.

@goranefbl
goranefbl / GitHub curl.sh
Created November 2, 2016 23:57
Download a single file from a private GitHub repo. You'll need an access token as described in this GitHub Help article: https://help.github.com/articles/creating-an-access-token-for-command-line-use
curl --header 'Authorization: token INSERTACCESSTOKENHERE' \
--header 'Accept: application/vnd.github.v3.raw' \
--remote-name \
--location https://api.github.com/repos/owner/repo/contents/path
# Example...
TOKEN="INSERTACCESSTOKENHERE"
OWNER="BBC-News"
REPO="responsive-news"
@goranefbl
goranefbl / disable-users-REST.php
Created December 24, 2016 08:16
Disable Users REST API endpoint
<?php
// Disable REST API user endpoints
add_filter( 'rest_endpoints', function( $endpoints ){
if ( isset( $endpoints['/wp/v2/users'] ) ) {
unset( $endpoints['/wp/v2/users'] );
}
if ( isset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] ) ) {
unset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] );
}
return $endpoints;
@goranefbl
goranefbl / auto-coupon-woo.php
Created January 29, 2017 19:42 — forked from jwebcat/auto-coupon-woo.php
Automatically apply coupon to cart WooCommerce
add_action( 'woocommerce_before_cart', 'apply_matched_coupons' );
function apply_matched_coupons() {
global $woocommerce;
$get1 = 'getonech'; // your coupon code here
$get2 = 'gettwoch'; // your coupon code here
$get3 = 'getthreech'; // your coupon code here
$get4 = 'getfourch'; // your coupon code here
$get5 = 'getfivech'; // your coupon code here
@goranefbl
goranefbl / raf-tab.php
Created February 24, 2017 16:18
Raf Tab
/**
* Register new endpoint to use inside My Account page.
*
* @see https://developer.wordpress.org/reference/functions/add_rewrite_endpoint/
*/
function my_custom_endpoints() {
add_rewrite_endpoint( 'refer-a-friend', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'my_custom_endpoints' );
@goranefbl
goranefbl / wp-pagination.php
Created March 13, 2017 10:50
WordPress table pagination class example
<?php
/**
* The dashboard-specific functionality of the plugin.
*
* Defines the plugin name, version, and two examples hooks for how to
* enqueue the dashboard-specific stylesheet and JavaScript.
*
* @package Gens_RAF
* @subpackage Gens_RAF/admin
@goranefbl
goranefbl / functions.php
Last active March 16, 2017 10:32
shortcode for coupons
add_shortcode('my-referals','raf_show_coupons');
function raf_show_coupons($atts, $content = null) {
$user_info = get_userdata(get_current_user_id());
$user_email = $user_info->user_email;
$date_format = get_option( 'date_format' );
$args = array(
'posts_per_page' => -1,
'post_type' => 'shop_coupon',
'post_status' => 'publish',
'meta_query' => array (
@goranefbl
goranefbl / wpgens.php
Created March 26, 2017 13:44
add from email
public function gens_send_buyer_email($order_email,$coupon_code) {
if ( !$order_email || !$coupon_code) {
return false;
}
global $woocommerce;
$mailer = $woocommerce->mailer();
$user_message = get_option( 'gens_raf_buyer_email_message' );
@goranefbl
goranefbl / formtocookie.js
Created April 3, 2017 11:08 — forked from themactep/formtocookie.js
How to save form to cookies, restore form from cookies. Requires jQuery and jQuery Cookie plugin.
/*
* Save Form To Cookie
* (cc) Paul Philippov, [email protected]
*
* This is rather a proof of concept than a production-ready solution.
* It does not handle radio buttons and such.
* You might want to extend it to suit your needs.
*
* Usage:
*
@goranefbl
goranefbl / raf-limit.php
Created May 2, 2017 05:59
filter referral saving
<?php
// Stop referrals if product isnt in category
function only_specific_cat($not_active,$num_friends_refered,$order) {
$items = $order->get_items();
$not_active = "yes"; // if this function returns "yes", order wont be saved as referral.
foreach ( $items as $item ) {
$product_id = $item['product_id'];
$term_list = wp_get_post_terms($product_id, 'product_cat', array('fields' => 'ids'));
if (is_array($term_list) && in_array("add_your_cat_id_here", $term_list)) {
$not_active = "no"; // this means there is product cat here, and coupon will be generated
<?php
// Povuci sve lokacije najblize lat i lon koji su prosledjeni
function get_posts_by_geo_distance($post_type,$lat_key,$lng_key,$source_lat,$source_lng) {
global $wpdb;
$sql =<<<SQL
SELECT
rl.ID,
rl.post_title AS location,
ROUND(6371*2*ASIN(SQRT(POWER(SIN(({$source_lat}-abs(lat.lat))*pi()/180/2),2)+
COS({$source_lat}*pi()/180)*COS(abs(lat.lat)*pi()/180)*