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
<div class="row">
<div class="col-lg-6">
<?php
echo $this->Form->create($x->createModel(), $x->options());
echo $this->Form->inputs($fields->inputs(), $nulll, fields->options());
$buttons = $x->buttons();
foreach($buttons as $button) {
echo $this->Form->submit($button->name(), $button->options());
@amdrew
amdrew / gist:a8be1db4d11774418714
Last active August 29, 2015 14:18
OptimizePress + AffiliateWP. Shows how to load a different shortcode for different pages
function affwp_opi_add_tracking_shortcode() {
// this can be the page ID, page slug, or page title. Page title is shown below
if ( is_page( 'Your Success Page' ) ) {
echo do_shortcode( '[affiliate_conversion_script description="Your Description" amount="100"]' );
}
// another "thanks" page using a page ID
if ( is_page( 50 ) ) {
echo do_shortcode( '[affiliate_conversion_script description="A different description" amount="200"]' );
@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 */
@spivurno
spivurno / gp-auto-login-redirect-to-new-site.php
Created February 25, 2015 14:56
Gravity Perks // GP Auto Login // Redirect to New Site on Auto Login
/**
* Gravity Perks // GP Auto Login // Redirect to New Site on Auto Login
*/
add_filter( 'gpal_auto_login_on_redirect_redirect_url', function( $url, $user_id ) {
require_once( GFUser::get_base_path() . '/data.php' );
$entry_id = get_user_meta( $user_id, 'entry_id', true );
$site_id = GFUserData::get_site_by_entry_id( $entry_id );
@gabrielmerovingi
gabrielmerovingi / mycred-hook-wp-courseware
Last active January 30, 2016 15:25
Custom myCRED Hook for WP Courseware. Points can be awarded or deducted for users completing units, modules and courses. Requires myCRED 1.6 or higher.
/**
* WP Courseware Hook
* @version 1.0.2
*/
add_filter( 'mycred_setup_hooks', 'mycred_register_courseware_hook' );
function mycred_register_courseware_hook( $installed ) {
$installed['courseware'] = array(
'title' => 'WP Courseware',
'description' => 'Award or deduct %plural% for users completing WP Courseware courses, modules or units.',
'callback' => array( 'myCRED_Hook_CourseWare' )
@nadeem-khan
nadeem-khan / change-role-based-on-balance.md
Last active February 6, 2016 20:04 — forked from gabrielmerovingi/change-role-based-on-balance
Change WordPress user role based on Mycred Points

Change WordPress user role based on Mycred Points:

add_filter( 'mycred_add', '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;

// Exclude admins
if ( user_can( $request['user_id'], 'manage_options' ) ) 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

/**
* Block Negative Balances
* Stop users from logging into your website if they have a negative
* myCRED balance.
* @version 1.0
*/
add_filter( 'authenticate', 'mycred_block_negative_balances', 990, 3 );
function mycred_block_negative_balances( $user, $username, $password ) {
// Make sure myCRED is installed
@amdrew
amdrew / gist:7f22b058a5defb240c48
Last active March 15, 2016 14:41
OptimizeMember + AffiliateWP. Allow affiliates to login/register and still be redirected to the affiliate area
function affwp_custom_op_login_redirect( $return, $vars ) {
$user_id = $vars['user_id'];
if ( function_exists( 'affwp_is_affiliate' ) && affwp_is_affiliate( $user_id ) ) {
$return = false;
}
return $return;
}
@amdrew
amdrew / dashboard-tab-urls.php
Created January 14, 2015 03:28
AffiliateWP - Show the affiliate's username instead of affiliate ID in the affiliate dashboard
<?php
$affiliate = affwp_get_affiliate( affwp_get_affiliate_id() );
$user_info = get_userdata( $affiliate->user_id );
$affiliate_user_name = $user_info->user_login;
?>
<div id="affwp-affiliate-dashboard-url-generator" class="affwp-tab-content">
<h4><?php _e( 'Referral URL Generator', 'affiliate-wp' ); ?></h4>