| @@ -9,27 +9,167 @@ | ||
| 9 | 9 | * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 10 | 10 | * @since 1.1.0 |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 14 | + return; | |
| 15 | +} | |
| 13 | 16 | // Current SDK version and path. |
| 14 | -$themeisle_sdk_version = '2.2.8'; | |
| 17 | +$themeisle_sdk_version = '3.2.30'; | |
| 15 | 18 | $themeisle_sdk_path = dirname( __FILE__ ); |
| 16 | 19 | |
| 17 | 20 | global $themeisle_sdk_max_version; |
| 18 | 21 | global $themeisle_sdk_max_path; |
| 19 | 22 | |
| 20 | -if ( version_compare( $themeisle_sdk_version, $themeisle_sdk_max_version ) >= 0 ) { | |
| 23 | +// If this is the latest SDK and it comes from a theme, we should load licenser separately. | |
| 24 | +$themeisle_sdk_relative_licenser_path = '/src/Modules/Licenser.php'; | |
| 25 | + | |
| 26 | +global $themeisle_sdk_abs_licenser_path; | |
| 27 | +if ( ! is_file( $themeisle_sdk_path . $themeisle_sdk_relative_licenser_path ) && ! empty( $themeisle_sdk_max_path ) && is_file( $themeisle_sdk_max_path . $themeisle_sdk_relative_licenser_path ) ) { | |
| 28 | + $themeisle_sdk_abs_licenser_path = $themeisle_sdk_max_path . $themeisle_sdk_relative_licenser_path; | |
| 29 | + add_filter( 'themeisle_sdk_required_files', 'themeisle_sdk_load_licenser_if_present' ); | |
| 30 | +} | |
| 31 | + | |
| 32 | +if ( ( is_null( $themeisle_sdk_max_path ) || version_compare( $themeisle_sdk_version, $themeisle_sdk_max_path ) == 0 ) && | |
| 33 | + apply_filters( 'themeisle_sdk_should_overwrite_path', false, $themeisle_sdk_path, $themeisle_sdk_max_path ) ) { | |
| 34 | + $themeisle_sdk_max_path = $themeisle_sdk_path; | |
| 35 | +} | |
| 36 | + | |
| 37 | +if ( is_null( $themeisle_sdk_max_version ) || version_compare( $themeisle_sdk_version, $themeisle_sdk_max_version ) > 0 ) { | |
| 21 | 38 | $themeisle_sdk_max_version = $themeisle_sdk_version; |
| 22 | 39 | $themeisle_sdk_max_path = $themeisle_sdk_path; |
| 23 | 40 | } |
| 24 | 41 | |
| 25 | -// load the latest sdk version from the active Themeisle products | |
| 42 | +// load the latest sdk version from the active Themeisle products. | |
| 43 | +if ( ! function_exists( 'themeisle_sdk_load_licenser_if_present' ) ) : | |
| 44 | + /** | |
| 45 | + * Always load the licenser, if present. | |
| 46 | + * | |
| 47 | + * @param array $to_load Previously files to load. | |
| 48 | + */ | |
| 49 | + function themeisle_sdk_load_licenser_if_present( $to_load ) { | |
| 50 | + global $themeisle_sdk_abs_licenser_path; | |
| 51 | + $to_load[] = $themeisle_sdk_abs_licenser_path; | |
| 52 | + | |
| 53 | + return $to_load; | |
| 54 | + } | |
| 55 | +endif; | |
| 56 | + | |
| 57 | +// load the latest sdk version from the active Themeisle products. | |
| 26 | 58 | if ( ! function_exists( 'themeisle_sdk_load_latest' ) ) : |
| 27 | 59 | /** |
| 28 | 60 | * Always load the latest sdk version. |
| 29 | 61 | */ |
| 30 | 62 | function themeisle_sdk_load_latest() { |
| 63 | + /** | |
| 64 | + * Don't load the library if we are on < 5.4. | |
| 65 | + */ | |
| 66 | + if ( version_compare( PHP_VERSION, '5.4.32', '<' ) ) { | |
| 67 | + return; | |
| 68 | + } | |
| 31 | 69 | global $themeisle_sdk_max_path; |
| 32 | 70 | require_once $themeisle_sdk_max_path . '/start.php'; |
| 33 | 71 | } |
| 34 | 72 | endif; |
| 35 | 73 | add_action( 'init', 'themeisle_sdk_load_latest' ); |
| 74 | + | |
| 75 | +if ( ! function_exists( 'tsdk_utmify' ) ) { | |
| 76 | + /** | |
| 77 | + * Utmify a link. | |
| 78 | + * | |
| 79 | + * @param string $url URL to add utms. | |
| 80 | + * @param string $area Area in page where this is used ( CTA, image, section name). | |
| 81 | + * @param string $location Location, such as customizer, about page. | |
| 82 | + * | |
| 83 | + * @return string | |
| 84 | + */ | |
| 85 | + function tsdk_utmify( $url, $area, $location = null ) { | |
| 86 | + static $current_page = null; | |
| 87 | + if ( $location === null && $current_page === null ) { | |
| 88 | + global $pagenow; | |
| 89 | + $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : $pagenow; | |
| 90 | + $current_page = isset( $screen->id ) ? $screen->id : ( ( $screen === null ) ? 'non-admin' : $screen ); | |
| 91 | + $current_page = sanitize_key( str_replace( '.php', '', $current_page ) ); | |
| 92 | + } | |
| 93 | + $location = $location === null ? $current_page : $location; | |
| 94 | + $content = sanitize_key( | |
| 95 | + trim( | |
| 96 | + str_replace( | |
| 97 | + [ | |
| 98 | + 'https://', | |
| 99 | + 'themeisle.com', | |
| 100 | + '/themes/', | |
| 101 | + '/plugins/', | |
| 102 | + '/upgrade', | |
| 103 | + ], | |
| 104 | + '', | |
| 105 | + $url | |
| 106 | + ), | |
| 107 | + '/' | |
| 108 | + ) | |
| 109 | + ); | |
| 110 | + return esc_url_raw( | |
| 111 | + add_query_arg( | |
| 112 | + [ | |
| 113 | + 'utm_source' => 'wpadmin', | |
| 114 | + 'utm_medium' => $location, | |
| 115 | + 'utm_campaign' => $area, | |
| 116 | + 'utm_content' => $content, | |
| 117 | + ], | |
| 118 | + $url | |
| 119 | + ) | |
| 120 | + ); | |
| 121 | + } | |
| 122 | + | |
| 123 | + add_filter( 'tsdk_utmify', 'tsdk_utmify', 10, 3 ); | |
| 124 | +} | |
| 125 | + | |
| 126 | + | |
| 127 | +if ( ! function_exists( 'tsdk_lstatus' ) ) { | |
| 128 | + /** | |
| 129 | + * Check license status. | |
| 130 | + * | |
| 131 | + * @param string $file Product basefile. | |
| 132 | + * | |
| 133 | + * @return string Status. | |
| 134 | + */ | |
| 135 | + function tsdk_lstatus( $file ) { | |
| 136 | + return \ThemeisleSDK\Modules\Licenser::status( $file ); | |
| 137 | + } | |
| 138 | +} | |
| 139 | +if ( ! function_exists( 'tsdk_lis_valid' ) ) { | |
| 140 | + /** | |
| 141 | + * Check if license is valid. | |
| 142 | + * | |
| 143 | + * @param string $file Product basefile. | |
| 144 | + * | |
| 145 | + * @return bool Validness. | |
| 146 | + */ | |
| 147 | + function tsdk_lis_valid( $file ) { | |
| 148 | + return \ThemeisleSDK\Modules\Licenser::is_valid( $file ); | |
| 149 | + } | |
| 150 | +} | |
| 151 | +if ( ! function_exists( 'tsdk_lplan' ) ) { | |
| 152 | + /** | |
| 153 | + * Get license plan. | |
| 154 | + * | |
| 155 | + * @param string $file Product basefile. | |
| 156 | + * | |
| 157 | + * @return string Plan. | |
| 158 | + */ | |
| 159 | + function tsdk_lplan( $file ) { | |
| 160 | + return \ThemeisleSDK\Modules\Licenser::plan( $file ); | |
| 161 | + } | |
| 162 | +} | |
| 163 | + | |
| 164 | +if ( ! function_exists( 'tsdk_lkey' ) ) { | |
| 165 | + /** | |
| 166 | + * Get license key. | |
| 167 | + * | |
| 168 | + * @param string $file Product basefile. | |
| 169 | + * | |
| 170 | + * @return string Key. | |
| 171 | + */ | |
| 172 | + function tsdk_lkey( $file ) { | |
| 173 | + return \ThemeisleSDK\Modules\Licenser::key( $file ); | |
| 174 | + } | |
| 175 | +} | |