Skip to content

Instantly share code, notes, and snippets.

Avatar

Very Good Plugins verygoodplugins

View GitHub Profile
View my-plugin.php
<?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 / wpf-lock-user-for-webhooks.php
Created Dec 8, 2022
Blocks incoming webhooks for a user for one minute after tags were applied to them (to prevent loopbacks)
View wpf-lock-user-for-webhooks.php
<?php
function wpf_lock_user( $user_id ) {
$contact_id = wpf_get_contact_id( $user_id );
set_transient( 'wpf_api_lock_' . $contact_id, 'update', MINUTE_IN_SECONDS );
}
@verygoodplugins
verygoodplugins / copy-memberium-auto-enroll-tags.php
Last active Dec 6, 2022
Copies Memberium's LearnDash auto-enroll tags over to WP Fusion's Link With Tag setting
View copy-memberium-auto-enroll-tags.php
<?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(
@verygoodplugins
verygoodplugins / inherit-memberium-access-rules.php
Last active Dec 7, 2022
Makes WP Fusion inherit post access rules and redirects that were created in Memberium
View inherit-memberium-access-rules.php
<?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 / edd-custom-cancel.php
Created Nov 1, 2022
Modifies the Easy Digital Downloads cancellation link to point to a custom "Confirm cancellation" page
View edd-custom-cancel.php
<?php
/**
* Modify the EDD cancel URL to point custom cancellation page.
*
* @param string $url The cancel URL.
* @param EDD_Subscription $subscription The subscription.
*/
function wpf_edd_subscription_cancel_url( $url, $subscription ) {
@verygoodplugins
verygoodplugins / set-infusionsoft-tracking-cookie.php
Created Sep 9, 2022
Sets the Infusionsoft referral partner tracking cookie based on a URL parameter, so it can be passed to a subdomain.
View set-infusionsoft-tracking-cookie.php
@verygoodplugins
verygoodplugins / wpf-sync-pending-yith-quotes.php
Created Sep 6, 2022
Sync YITH Request A Quote pending orders to ActiveCampaign Deep Data as if they'd already been paid for
View wpf-sync-pending-yith-quotes.php
<?php
// Sync YITH Request A Quote pending orders to AC as if they'd been paid.
function add_custom_paid_status( $statuses ) {
$statuses[] = 'ywraq-new';
$statuses[] = 'ywraq-pending';
return $statuses;
@verygoodplugins
verygoodplugins / tag-based-on-username.php
Created Jul 22, 2022
When a user registers in WordPress, applies a tag in the CRM with their username
View tag-based-on-username.php
<?php
function tag_based_on_username( $user_id ) {
$user = get_user_by( 'id', $user_id );
wp_fusion()->user->apply_tags( array( $user->user_login ), $user_id );
}
@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-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.