Skip to content

Instantly share code, notes, and snippets.

View ioniacob's full-sized avatar
🐌
Exploring the code is like life itself.

Ion Iacob ioniacob

🐌
Exploring the code is like life itself.
View GitHub Profile
@ioniacob
ioniacob / Wordpress functions.php
Last active September 12, 2015 18:47
Personal Wordpress functions.php
// Additional Functions
// =============================================================================
add_action( 'affwp_process_register_form', 'affwp_custom_process_register_form' );
/* Auto enables the "Enable New Referral Notifications" checkbox on the "Settings" tab of the affiliate area when an affiliate is added. */
function affwp_custom_auto_enable_affiliate_referral_notifications( $add ) {
update_user_meta( affwp_get_affiliate_user_id( $add ), 'affwp_referral_notifications', true );
}
add_action( 'affwp_insert_affiliate', 'affwp_custom_auto_enable_affiliate_referral_notifications' );
/** Adds a log out link to the top of the affiliate area */
<!DOCTYPE html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>Testing a PayPal Payments Standard Button</title>
</head>
<body>
<h2>Buy Strings!</h2>
@ioniacob
ioniacob / change-role-based-on-balance
Created February 6, 2016 15:08 — forked from gabrielmerovingi/change-role-based-on-balance
Change a users WordPress role based on their current myCRED balance.
/**
* Promote Based on Balance
* Changes a users role based on their myCRED balance.
* @version 1.0.4
*/
add_filter( 'mycred_add_finished', 'check_for_role_change', 99, 3 );
function check_for_role_change( $reply, $request, $mycred ) {
// Make sure that if any other filter has declined this we also decline
if ( $reply === false ) return $reply;

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

@ioniacob
ioniacob / gist:b0ec76fac319749b3ccb
Created February 7, 2016 22:15 — forked from ultimatemember/gist:643cd90967e5e415378d
Custom profile tab example: showing user pages
/* add a custom tab to show user pages */
add_filter('um_profile_tabs', 'pages_tab', 1000 );
function pages_tab( $tabs ) {
$tabs['pages'] = array(
'name' => 'Pages',
'icon' => 'um-faicon-pencil',
'custom' => true
);
return $tabs;
}
@ioniacob
ioniacob / gist:41e2ecb609b11803b347
Created February 20, 2016 02:25 — forked from ultimatemember/gist:d98861b4c14a1540291b
Conditionally sync UM user role based on WP role (Gravity forms)
/* This code will sync the UM role based on WP role using gravity registration */
add_action("gform_user_registered", "um_gravity_user_role_sync", 200, 4);
function um_gravity_user_role_sync($user_id, $config, $entry, $user_pass) {
$user = new WP_User( $user_id );
$wp_role = $user->roles[0];
// if WP role is subscriber, set UM role to member
if ( $wp_role == 'subscriber' ) {
<!--
Via: http://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript
-->
<textarea class="js-copytextarea">Hello I'm some text</textarea>
<button class="js-textareacopybtn">Copy Text</button>
<script>
@ioniacob
ioniacob / Add user to list after click on link
Created September 29, 2016 19:45 — forked from evrpress/Add user to list after click on link
Assigns a subscriber to a certain list if a certain link has been clicked
@ioniacob
ioniacob / gist:1badc5718549786e7f6de77a3fbb99cf
Created October 18, 2016 01:25 — forked from woogist/gist:5934881
Automatically add product to cart on visit depending on cart total value
/*
* goes in theme functions.php or a custom plugin
**/
// add item to cart on visit depending on cart total value
add_action( 'init', 'add_product_to_cart' );
function add_product_to_cart() {
if ( ! is_admin() ) {
global $woocommerce;
$product_id = 2831;
$found = false;
@ioniacob
ioniacob / gist:e1d558fc8308849dc3defe47cbb653fb
Created October 18, 2016 13:29 — forked from kloon/gist:2376300
WooCommerce Automatically add product to cart on site visit
/*
* goes in theme functions.php or a custom plugin
**/
// add item to cart on visit
add_action( 'template_redirect', 'add_product_to_cart' );
function add_product_to_cart() {
if ( ! is_admin() ) {
$product_id = 64;
$found = false;
//check if product already in cart