Skip to content

Instantly share code, notes, and snippets.

View verygoodplugins's full-sized avatar

Very Good Plugins verygoodplugins

View GitHub Profile
@verygoodplugins
verygoodplugins / wpf-api-error-email-notification.php
Created September 13, 2018 16:22
Send an email notification when an API error is encountered
<?php
function wpf_email_notify( $timestamp, $level, $user, $message, $source, $context ) {
if( $level == 'error' ) {
wp_mail( 'youremail@example.com', 'WP Fusion API Error', 'Error message: ' . $message . ' for user ID ' . $user );
}
@verygoodplugins
verygoodplugins / wpf-unlock-for-fb-referral.php
Created September 20, 2018 14:10
Unlock any locked content when visited from a Facebook link
<?php
function unlock_for_fb_referral( $can_access, $user_id, $post_id ) {
if( isset( $_SERVER['HTTP_REFERER'] ) && strpos( $_SERVER['HTTP_REFERER'], 'facebook') !== false ) {
return true;
}
return $can_access;
@verygoodplugins
verygoodplugins / wpf-show-infusionsoft-invoices.php
Last active October 31, 2018 13:28
Outputs a table that shows a logged in user's invoices in Infusionsoft
<?php
function wpf_infusionsoft_invoices() {
$contact_id = wp_fusion()->user->get_contact_id();
if( ! is_user_logged_in() || $contact_id == false ) {
return 'No contact record found.';
}
@verygoodplugins
verygoodplugins / wpf-set-batch-sleep-time.php
Created November 29, 2018 18:10
Slow down WP Fusion's batch processing tools to prevent API throttling
<?php
// Tells WP Fusion's batch process to wait one second between each operation.
function set_wpf_sleep_time( $seconds ) {
return 1;
}
add_filter( 'wpf_batch_sleep_time', 'set_wpf_sleep_time' );
@verygoodplugins
verygoodplugins / wpf-sync-woo-autogen-password.php
Last active December 12, 2018 16:02
Syncs passwords to your CRM only when they have been automatically generated by WooCommerce
<?php
// Add WooCommerce Generated Password field to Contact Fields list
function add_woo_password_meta_field( $meta_fields ) {
$meta_fields['woo_password'] = array( 'label' => 'Generated Password', 'type' => 'text', 'group' => 'woocommerce' );
return $meta_fields;
@verygoodplugins
verygoodplugins / wpf-flip-access-rules.php
Last active December 13, 2018 17:20
Flips the access rules for a post or posts so that users *without* any of the specified tags are granted access
<?php
add_filter('wpf_user_can_access', 'my_wpf_flip_access_rules', 10, 3);
function my_wpf_flip_access_rules( $can_access, $user_id, $post_id ) {
// Optional: limit the rule flipping just to certain post IDs (1234 and 4567)
if( $post_id != 1234 ) {
return $can_access;
}
@verygoodplugins
verygoodplugins / wpf-create-contacts-on-login.php
Created January 4, 2019 16:31
Create a new CRM contact record when a user logs in if they don't have one already
<?php
function login_add_contact( $user_login, $user ) {
$cid = wp_fusion()->user->get_contact_id( $user->ID );
if( empty( $cid ) ) {
wp_fusion()->user->user_register( $user->ID );
}
@verygoodplugins
verygoodplugins / wpf-salesforce-object-type.php
Created January 16, 2019 17:05
Change CRM object type to Leads for Salesforce
<?php
function set_object_type( $object_type ) {
return 'Lead';
}
add_filter( 'wpf_crm_object_type', 'set_object_type' );
@verygoodplugins
verygoodplugins / wpf-apply-tags-post-terms.php
Created February 19, 2019 19:42
Applies tags when a post is viewed based on the names of the categories and post tags assigned to the post
<?php
function wpf_apply_tags_on_view( $post ) {
if( ! function_exists( 'wp_fusion' ) ) {
return;
}
if ( is_admin() || ! is_singular() || ! is_user_logged_in() || $post->post_type != 'post' ) {
return;
@verygoodplugins
verygoodplugins / wpf-date-math.php
Last active March 28, 2019 19:58
Add one year to a custom field value and send it back to your CRM
<?php
// Adds the two custom fields to the Contact Fields tab
function custom_wpf_meta_fields( $fields ) {
$fields['last_bill_date'] = array('label' => 'Last Bill Date', 'type' => 'date', 'group' => 'wordpress');
$fields['next_bill_date'] = array('label' => 'Next Bill Date', 'type' => 'date', 'group' => 'wordpress');
return $fields;