Skip to content

Instantly share code, notes, and snippets.

View webzunft's full-sized avatar

Thomas Maier webzunft

View GitHub Profile
@webzunft
webzunft / geo-targeting.php
Last active February 21, 2024 09:17
Geo-targeting debug ad for Advanced Ads as seen on https://wpadvancedads.com/manual/geo-targeting-tests-and-issues/
<div style="min-width: 300px; height: auto; padding: 10px; background: #fff; color: #333; text-align: center; border: solid 1px #ddd;">
<p>Your location:</p>
<?php
if( class_exists( 'Advanced_Ads_Geo_Api' ) ) :
$api = Advanced_Ads_Geo_Api::get_instance();
$ip = $api->get_real_IP_address();
$error = false;
$my_country = '';
$my_country_isoCode = '';
$my_city = '';
@webzunft
webzunft / isc-options-printer.php
Last active February 5, 2024 15:16
ISC Options Printer
<?php
/**
* Plugin Name: ISC Options Printer
* Plugin URI: https://yourwebsite.com/
* Description: A helper plugin to print the Image Source Control plugin options in raw, serialized format at the top of the ISC plugin options page.
* Version: 1.0
* Author: Your Name
* Author URI: https://yourwebsite.com/
* License: GPL2
*/
@webzunft
webzunft / edd-order-columns.php
Created November 7, 2022 15:59
Add Product and Country column to Easy Digital Downloads
<?php
/**
* Add more columns to the order table
*
* - Products
* - Country
*/
/**
* Add table columns
*
@webzunft
webzunft / canceled-subscriptions.sql
Last active October 4, 2022 13:15
SQL queries to analyse canceled subscriptions managed with EDD Recurring Payments
# Basic queries to analyse canceled subscriptions using EDD Recurring Payments pre EDD 3.0
# Use EXPLAIN if you have large stores since the "notes" column is not indexed and queries can take some time
# Some of these reports might be worth storing as Views and look at the graphs PHPMyAdmin can also create from them
# List subscription cancelation with creation and cancelation date, as well as the user who canceled
# good as a basis for further queries
SELECT ID,
created,
REGEXP_SUBSTR( REGEXP_SUBSTR( notes, '.* Status changed from active to cancelled .*' ), '^[a-z]+ [0-9]+, [0-9]+' ) AS 'date',
@webzunft
webzunft / edd-pricing-discount-shortcodes.php
Created September 1, 2022 13:43
Shortcodes to deliver discount-based information, show prices, and actual discounts. Helpful for dynamic pricing pages.
<?php
/**
* Shortcodes that help with displaying pricing information
*/
/**
* Show the original price of a given download and price ID
*
* @param array $atts shortcode attributes.
* @param array $content shortcode attributes.
@webzunft
webzunft / fix-unclosed-query.php
Created September 25, 2020 11:53
Fixes an unclosed WP_Query() or query_posts() before Advanced Ads loads an ad
/**
* Fix the "Current post is not identical to main post."
* and "Current query is not identical to main query." warnings in Advanced Ads
* caused by custom queries not using wp_reset_postdata() or wp_reset_query()
*
* @source https://wpadvancedads.com/manual/ad-debug-mode/
* @source https://developer.wordpress.org/reference/classes/wp_query/
* @source https://developer.wordpress.org/reference/functions/query_posts/
*
* Developers should not use this and rather add wp_reset_postdata() or wp_reset_query() to their code
@webzunft
webzunft / check cURL version
Last active January 22, 2022 08:35
Check cURL version in EDD Software Licensing > activate_license
if ( is_wp_error( $response ) ) {
$body = wp_remote_retrieve_body( $response );
if ( $body ) {
return $body;
} else {
$curl = curl_version();
return __( 'License couldn’t be activated. Please try again later.', 'advanced-ads' ) . " (cURL {$curl['version']})";
}
}
@webzunft
webzunft / shortcodes.php
Last active December 10, 2019 10:06
Extend edd_aa_all_access() function in EDD All Access to work for multiple All Access passes
<?php
/**
* Shortcode which can be used to easily give a user the option to log in or purchase an All Access Pass.
* If the user is already logged in but does not have a valid All Access Pass, they will see a buy button.
* If the user is both logged in and has a valid All Access Pass, they will be redirected to the page defined by the shortcode args.
* Can also be used to restrict content.
*
* @since 1.0.0
* @param array $atts Shortcode attributes
* @param string $content
@webzunft
webzunft / helper-functions.php
Last active December 10, 2019 09:09
Suggestion for improved edd_all_access_user_has_pass() in EDD All Access
<?php
/**
* Check if a specific customer has a valid, specific All Access Pass.
*
* @since 1.0.0
* @param int - The ID of the user
* @param mixed - The ID of the All Access product, separate multiple IDs using comma
* @param mixed - The price_id (price variation) of the All Access product, separate multiple IDs using comma, leave empty for all price IDs
* @param string - The status of the pass we want to check if the user has.
* @return object/int - The All Access Pass if it exists or false if not.
@webzunft
webzunft / advanced-ads-company-category.php
Last active March 5, 2019 10:30
Add a company taxonomy to ads managed by the Advanced Ads plugin.
<?php
/**
* Advanced Ads – Company Category
*
* @wordpress-plugin
* Plugin Name: Advanced Ads – Company Category
* Plugin URI: https://wpadvancedads.com
* Description: Add a Company category to ads so that you can group them.
* Version: 0.1
* Author: Thomas Maier