This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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() ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function example_sync_lifetime_value( $user_meta, $user_id ) { | |
$user_meta['lifetime_value'] = 0; | |
$customer_orders = get_posts( | |
array( | |
'posts_per_page' => -1, | |
'post_type' => 'shop_order', | |
'post_status' => wc_get_is_paid_statuses(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// | |
// Tag Count shortcode, use like [wpf_tag_count tag="Tag Name"] | |
// | |
function wpf_tag_count( $atts ) { | |
$tag = wpf_get_tag_id( $atts['tag'] ); | |
$result = get_transient( 'wpf_tag_count_' . sanitize_key( $tag ) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// | |
// Denies access to any content that was published before the user's registration date | |
// | |
function disallow_before_date_published( $can_access, $user_id, $post_id ) { | |
$published = get_the_date( 'U', $post_id ); | |
$userdata = get_userdata( $user_id ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This runs every day and imports any new users from the connected CRM who have the specified tag ID ("123" in this example) | |
// If contacts with that tag already have user accounts on the site they will be skipped and no data will be loaded | |
// i.e. this just imports *new* users | |
if ( ! wp_next_scheduled( 'wpf_daily_import' ) ) { | |
wp_schedule_event( time(), 'daily', 'wpf_daily_import' ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function wpf_bookable_products_meta_fields( $fields ) { | |
$args = array( | |
'post_type' => 'product', | |
'nopaging' => true, | |
'meta_key' => 'WooCommerceEventsType', | |
'meta_value' => 'bookings', | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 3 is the upgrade ID of a 1 site lifetime license | |
// 4 is the upgrade ID of a 3 sites lifetime license | |
// 1 to 4 are the price IDs of annual licenses | |
// 5 is the price ID of a 1 site lifetime license | |
// 6 is the price ID of a 3 site lifetime license | |
function wpf_edd_sl_upgrade_cost( $cost, $license_id, $upgrade_id ) { |