assets
5 months ago
src
1 month ago
LICENSE
6 months ago
composer.json
1 month ago
index.php
6 months ago
load.php
1 month ago
start.php
1 month ago
load.php
118 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Loader for the ThemeGrillSDK |
| 4 | * |
| 5 | * Logic for loading always the latest SDK from the installed themes/plugins. |
| 6 | * |
| 7 | * @package ThemeGrillSDK |
| 8 | * @copyright Copyright (c) 2025, ThemeGrill |
| 9 | * @license http://opensource.org/licenses/gpl-3.0.php GNU Public License |
| 10 | * @since 1.0.0 |
| 11 | */ |
| 12 | |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | return; |
| 15 | } |
| 16 | |
| 17 | // Current SDK version and path. |
| 18 | $themegrill_sdk_version = '1.0.4'; |
| 19 | $themegrill_sdk_path = __DIR__; |
| 20 | |
| 21 | global $themegrill_sdk_max_version; |
| 22 | global $themegrill_sdk_max_path; |
| 23 | |
| 24 | if ( |
| 25 | ( is_null( $themegrill_sdk_max_path ) || |
| 26 | version_compare( $themegrill_sdk_version, $themegrill_sdk_max_version ) === 0 ) && |
| 27 | apply_filters( 'themegrill_sdk_should_overwrite_path', false, $themegrill_sdk_path, $themegrill_sdk_max_path ) |
| 28 | ) { |
| 29 | $themegrill_sdk_max_path = $themegrill_sdk_path; |
| 30 | } |
| 31 | |
| 32 | if ( |
| 33 | is_null( $themegrill_sdk_max_version ) || |
| 34 | version_compare( $themegrill_sdk_version, $themegrill_sdk_max_version ) > 0 |
| 35 | ) { |
| 36 | $themegrill_sdk_max_version = $themegrill_sdk_version; |
| 37 | $themegrill_sdk_max_path = $themegrill_sdk_path; |
| 38 | } |
| 39 | |
| 40 | // Load the latest sdk version from the active ThemeGrill products. |
| 41 | if ( ! function_exists( 'themegrill_sdk_load_latest' ) ) : |
| 42 | /** |
| 43 | * Always load the latest sdk version. |
| 44 | */ |
| 45 | function themegrill_sdk_load_latest() { |
| 46 | /** |
| 47 | * Don't load the library if we are on < 7.2.24. |
| 48 | */ |
| 49 | if ( version_compare( PHP_VERSION, '7.2.24', '<' ) ) { |
| 50 | return; |
| 51 | } |
| 52 | global $themegrill_sdk_max_path; |
| 53 | require_once $themegrill_sdk_max_path . '/start.php'; |
| 54 | } |
| 55 | endif; |
| 56 | |
| 57 | add_action( 'init', 'themegrill_sdk_load_latest' ); |
| 58 | |
| 59 | |
| 60 | if ( ! function_exists( 'tgsdk_utmify' ) ) { |
| 61 | /** |
| 62 | * Utmify a link. |
| 63 | * |
| 64 | * @param string $url URL to add utms. |
| 65 | * @param string $area Area in page where this is used ( CTA, image, section name). |
| 66 | * @param string $location Location, such as customizer, about page. |
| 67 | * |
| 68 | * @return string |
| 69 | */ |
| 70 | function tgsdk_utmify( $url, $area, $location = null ) { |
| 71 | static $current_page = null; |
| 72 | if ( $location === null && $current_page === null ) { |
| 73 | global $pagenow; |
| 74 | $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : $pagenow; |
| 75 | $current_page = isset( $screen->id ) ? $screen->id : ( ( $screen === null ) ? 'non-admin' : $screen ); |
| 76 | $current_page = sanitize_key( str_replace( '.php', '', $current_page ) ); |
| 77 | } |
| 78 | $location = $location === null ? $current_page : $location; |
| 79 | $content = sanitize_key( |
| 80 | trim( |
| 81 | str_replace( |
| 82 | apply_filters( |
| 83 | 'tgsdk_utmify_replace', |
| 84 | [ |
| 85 | 'https://', |
| 86 | 'themegrill.com', |
| 87 | '/themes/', |
| 88 | '/plugins/', |
| 89 | '/upgrade', |
| 90 | ] |
| 91 | ), |
| 92 | '', |
| 93 | $url |
| 94 | ), |
| 95 | '/' |
| 96 | ) |
| 97 | ); |
| 98 | $filter_key = sanitize_key( $content ); |
| 99 | $url_args = [ |
| 100 | 'utm_source' => 'wpadmin', |
| 101 | 'utm_medium' => $location, |
| 102 | 'utm_campaign' => $area, |
| 103 | 'utm_content' => $content, |
| 104 | ]; |
| 105 | $query_arguments = apply_filters( 'tgsdk_utmify_' . $filter_key, $url_args, $url ); |
| 106 | $utmify_url = esc_url_raw( |
| 107 | add_query_arg( |
| 108 | $query_arguments, |
| 109 | $url |
| 110 | ) |
| 111 | ); |
| 112 | |
| 113 | return apply_filters( 'tgsdk_utmify_url_' . $filter_key, $utmify_url, $url ); |
| 114 | } |
| 115 | |
| 116 | add_filter( 'tgsdk_utmify', 'tgsdk_utmify', 10, 3 ); |
| 117 | } |
| 118 |