Skip to content

Instantly share code, notes, and snippets.

Avatar

Very Good Plugins verygoodplugins

View GitHub Profile
@verygoodplugins
verygoodplugins / wpf-ac-resubscribe-to-list.php
Created Jun 2, 2022
Re-susbscribes an unsubscribed contact to the selected list when their profile is updated
View wpf-ac-resubscribe-to-list.php
<?php
// This runs whenever WP Fusion updates an existing contact record. It re-subscribes them to the list ID specified.
function re_subscribe_to_list( $args ) {
$list_id = 1; // Update this with your list ID.
$args[1][ 'p[' . $list_id . ']' ] = $list_id;
$args[1][ 'status[' . $list_id . ']' ] = 1;
@verygoodplugins
verygoodplugins / wpf-learndash-require-enrolled.php
Created Apr 21, 2020
Modifies WP Fusion's course access permissions for LearnDash so users must be enrolled in the course to see the course page
View wpf-learndash-require-enrolled.php
<?php
// Check course access
function check_ld_access( $can_access, $user_id, $post_id ) {
if ( ! function_exists( 'sfwd_lms_has_access' ) ) {
return $can_access;
}
@verygoodplugins
verygoodplugins / wpf-update-custom-object.php
Last active Dec 29, 2021
Create / update a custom Event object in Zoho. Salesforce, or HubSpot when an "event" post type is created or updated
View wpf-update-custom-object.php
<?php
// Runs on any post with post type "event" and updates the "Event" custom object with values Title and EventDate
function create_update_event_object( $post_id, $post, $update ) {
// Don't run if WP Fusion isn't active, otherwise you'll get an error
if ( ! function_exists( 'wp_fusion' ) ) {
return;
@verygoodplugins
verygoodplugins / wpf-multisite-meta-keys.php
Last active Nov 15, 2021
Prefix the WPF contact ID and tags meta keys with the current blog prefix
View wpf-multisite-meta-keys.php
<?php
/**
* When the user's contact ID or tags are saved, prefix the usermeta key with
* the blog prefix of the current blog.
*
* @param bool $check Whether or not to bypass the original database
* check.
* @param int $user_id The user ID.
* @param string $meta_key The meta key.
@verygoodplugins
verygoodplugins / wpf-sync-multiple-subscription-renewal-dates.php
Last active Nov 4, 2021
Allows syncing the renewal dates from multiple WooCommerce subscriptions into multiple custom fields
View wpf-sync-multiple-subscription-renewal-dates.php
<?php
function wpf_subscription_products_meta_fields( $fields ) {
if ( ! class_exists( 'WC_Subscriptions_Product' ) ) {
return;
}
$args = array(
'post_type' => 'product',
@verygoodplugins
verygoodplugins / wpf-track-login-streak.php
Last active Sep 21, 2021
Updates a wpf_logins_streak field each time a user logs in on two consecutive days
View wpf-track-login-streak.php
<?php
function wpf_track_login_streak( $meta_id, $user_id, $meta_key, $meta_value ) {
if ( 'wpf_last_login' === $meta_key ) { // this runs every time the wpf_last_login field is about to be updated.
$prev_value = get_user_meta( $user_id, 'wpf_last_login', true ); // get the previous last login timestamp.
$prev_value = floor( absint( $prev_value ) / DAY_IN_SECONDS ); // Convert to days since Jan 1st 1970.
@verygoodplugins
verygoodplugins / wpf-true-auto-login.php
Last active Sep 4, 2021
Allow a true auto-login via a link with a contact ID in it.
View wpf-true-auto-login.php
<?php
// Disbale "Allow URL Login" in WP Fusion's settings for this to work properly.
/**
* True auto login. Format your URLs like: https://mysite.com/?cid=%CONTACTID%&email=%EMAILADDRESS%&key=%ACCESSKEY%
*
* Where %CONTACTID% is the ID of the contact
* %EMAIL% is the email address of the contact
* and %ACCESSKEY% is your access key from the bottom of the WP Fusion General settings tab
@verygoodplugins
verygoodplugins / edd-improved-grandfathered-renewal-discount.php
Last active Aug 28, 2021
Easy Digital Downloads grandfathered renewal discounts, with support for upgrades and reactivations
View edd-improved-grandfathered-renewal-discount.php
<?php
/**
* Sets renewal discount to 30% for any customer that purchased before January
* 1, 2021.
*
* @param int $renewal_discount The renewal discount.
* @param int $license_id The license ID.
* @return int The renewal discount amount.
*/
function wpf_edd_grandfather_renewal_discount( $renewal_discount, $license_id ) {
@verygoodplugins
verygoodplugins / wpf-lookup-hubspot-company.php
Created Aug 4, 2021
Uses a saved company_id to lookup the company for a HubSpot contact over the Companies API
View wpf-lookup-hubspot-company.php
<?php
function example_hubspot_company_lookup( $user_id ) {
$company_id = get_user_meta( $user_id, 'company_id', true );
$request = 'https://api.hubapi.com/crm/v3/objects/companies/' . $company_id; // see https://developers.hubspot.com/docs/api/crm/companies
$response = wp_remote_get( $request, wp_fusion()->crm->get_params() );
if ( is_wp_error( $response ) ) {
wpf_log( 'error', 0, $response->get_error_message() );
View wpf-delete-user-on-tag-update.php
<?php
// Deletes WordPress user when the tag "REMOVE USER" is applied.
// Works when a webhook is received or during a batch Resync Tags operation is run.
// USE WITH CAUTION.
function my_wpf_delete_user( $user_id, $user_tags ) {
if ( wp_fusion()->user->has_tag( 'REMOVE USER', $user_id ) && ! user_can( $user_id, 'manage_options' ) ) {