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-dont-sync-free-orders.php
Created August 10, 2023 12:55
Prevent the Enhanced Ecommerce addon from syncing free orders to the CRM
<?php
function wpf_dont_sync_free_orders( $order_args ) {
if ( empty( $order_args['total'] ) ) {
return false;
}
return $order_args;
}
@verygoodplugins
verygoodplugins / wpf-add-field-keys-to-names.php
Created July 19, 2023 13:03
Appends each CRM field's internal ID to the field label in the dropdowns.
<?php
function add_field_keys_to_names( $fields ) {
foreach ( $fields as $i => $category ) {
foreach ( $category as $key => $label ) {
$fields[ $i ][ $key ] = $label .= ' (' . $key . ')';
}
}
@verygoodplugins
verygoodplugins / wpf-inherit-from-am360.php
Created July 13, 2023 11:40
Inherit access rules from ActiveMember360
<?php
/**
* Inherits access rules and redirects from ActiveMember360 for posts and pages.
*
* @param array $settings The WP Fusion settings on the post.
* @param WP_Post|int $post_id The post or post ID.
* @return array The settings.
*/
function inherit_am360_access_rules( $settings, $post_id ) {
@verygoodplugins
verygoodplugins / wpf-delete-user-on-field-change.php
Last active June 29, 2023 11:15
Deletes WordPress user when the "role" field is loaded from the CRM with a value of "deleted"
<?php
// Deletes WordPress user when the "role" field is loaded from the CRM with a value of "deleted"
// Works when a webhook is received or a batch Pull User Meta operation is run.
function my_wpf_delete_user_by_field( $user_id, $user_meta ) {
if ( isset( $user_meta['role'] ) && $user_meta['role'] == 'deleted' && ! user_can( $user_id, 'manage_options' ) ) {
require_once( ABSPATH . 'wp-admin/includes/user.php' );
@verygoodplugins
verygoodplugins / wpf-true-auto-login.php
Last active April 25, 2023 12:18
Allow a true auto-login via a link with a contact ID in it.
<?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 / wpf-lock-user-for-webhooks.php
Last active March 8, 2023 11:45
Blocks incoming webhooks for a user for one minute after tags were applied to them (to prevent loopbacks)
<?php
/**
* Sets a transient to lock a user from receiving webhooks from the CRM for one minute
* after tags have been applied by WP Fusion.
*
* @param int $user_id The user ID.
*/
function wpf_lock_user( $user_id ) {
@verygoodplugins
verygoodplugins / edd-auto-activate-sites.php
Created February 9, 2023 13:25
Allow active licenses to get updates if they're not at the limit, no matter what.
<?php
/**
* Allow active licenses to get updates if they're not at the limit, no matter what.
*
* @param bool $is_active Whether the site is active or not.
* @param int $license_id The license ID.
* @param string $passed_site_url The site URL.
*
* @return bool Whether the site is active or not.
*/
@verygoodplugins
verygoodplugins / my-plugin.php
Created December 8, 2022 11:38
WordPress plugin created by ChatGPT (https://i.wpfusion.com/8p22pV)
<?php
// Define a class for our plugin
class MyPlugin {
// Define a static property to hold the single instance of the class
private static $instance;
// Define a private constructor to prevent the class from being instantiated directly
private function __construct() {
// Add the admin settings page to the WordPress admin menu
@verygoodplugins
verygoodplugins / inherit-memberium-access-rules.php
Last active December 7, 2022 10:48
Makes WP Fusion inherit post access rules and redirects that were created in Memberium
<?php
function inherit_memberium_access_rules( $settings, $post_id ) {
if ( is_object( $post_id ) ) {
$post_id = $post_id->ID; // wpf_settings_for_meta_box passes a WP_Post.
}
if ( empty( $settings['allow_tags'] ) ) {
@verygoodplugins
verygoodplugins / copy-memberium-auto-enroll-tags.php
Last active December 6, 2022 10:55
Copies Memberium's LearnDash auto-enroll tags over to WP Fusion's Link With Tag setting
<?php
function maybe_migrate_auto_enroll_tags() {
// visit /wp-admin/index.php?migrate=true to start.
if ( isset( $_GET['migrate'] ) ) {
$linked_courses = get_posts(
array(