| 1 |
<?php |
| 2 |
/** |
| 3 |
* LoginPress Utilities |
| 4 |
* |
| 5 |
* @package loginpress |
| 6 |
* @since 6.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Generate UTM link for LoginPress Pro upgrade. |
| 15 |
* |
| 16 |
* @since 6.0.0 |
| 17 |
* |
| 18 |
* @param string $link Base URL. |
| 19 |
* @param string $source UTM source parameter. |
| 20 |
* @param string $medium UTM medium parameter. |
| 21 |
* @param string $campaign UTM campaign parameter. |
| 22 |
* @param string $term UTM term parameter. |
| 23 |
* @param string $content UTM content parameter. |
| 24 |
* |
| 25 |
* @return string |
| 26 |
*/ |
| 27 |
function loginpress_utm_link( $link, $source = 'loginpress-lite', $medium = '', $campaign = 'pro-upgrade', $term = '', $content = '' ) { |
| 28 |
|
| 29 |
// Manually construct the URL to ensure correct parameter order. |
| 30 |
$params = array(); |
| 31 |
|
| 32 |
// Add parameters in the correct order: utm_source, utm_medium, utm_campaign, utm_content, utm_term. |
| 33 |
$params[] = 'utm_source=' . rawurlencode( $source ); |
| 34 |
$params[] = 'utm_medium=' . rawurlencode( $medium ); |
| 35 |
$params[] = 'utm_campaign=' . rawurlencode( $campaign ); |
| 36 |
|
| 37 |
if ( ! empty( $content ) ) { |
| 38 |
$params[] = 'utm_content=' . rawurlencode( $content ); |
| 39 |
} |
| 40 |
|
| 41 |
if ( ! empty( $term ) ) { |
| 42 |
$params[] = 'utm_term=' . rawurlencode( $term ); |
| 43 |
} |
| 44 |
|
| 45 |
$separator = strpos( $link, '?' ) !== false ? '&' : '?'; |
| 46 |
return $link . $separator . implode( '&', $params ); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Generate upgrade link for LoginPress Pro. |
| 51 |
* |
| 52 |
* @since 6.0.0 |
| 53 |
* |
| 54 |
* @param string $medium UTM medium parameter. |
| 55 |
* @param string $content UTM content parameter. |
| 56 |
* |
| 57 |
* @return string |
| 58 |
*/ |
| 59 |
function loginpress_admin_upgrade_link( $medium = 'link', $content = '' ) { |
| 60 |
|
| 61 |
$url = 'https://loginpress.pro/pricing/'; |
| 62 |
|
| 63 |
// Don't add content for admin-menu as it will be added dynamically by loginpress_adjust_pro_menu_item. |
| 64 |
if ( 'settings-tab' !== $medium && 'admin-menu' !== $medium ) { |
| 65 |
$current_screen = get_current_screen(); |
| 66 |
if ( $current_screen ) { |
| 67 |
$content = $content ? $content . ' - ' . $current_screen->base : $current_screen->base; |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
// Add view parameter if available (not for admin-menu). |
| 72 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- GET parameter for UTM tracking purposes. |
| 73 |
if ( 'admin-menu' !== $medium && isset( $_GET['view'] ) ) { |
| 74 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- GET parameter for UTM tracking purposes. |
| 75 |
$content = $content ? $content . ': ' . sanitize_key( $_GET['view'] ) : sanitize_key( $_GET['view'] ); |
| 76 |
} |
| 77 |
|
| 78 |
// Add tab parameter if available (not for admin-menu). |
| 79 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- GET parameter for UTM tracking purposes. |
| 80 |
if ( 'admin-menu' !== $medium && isset( $_GET['tab'] ) ) { |
| 81 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- GET parameter for UTM tracking purposes. |
| 82 |
$content = $content ? $content . ': ' . sanitize_key( $_GET['tab'] ) : sanitize_key( $_GET['tab'] ); |
| 83 |
} |
| 84 |
$source = 'loginpress-lite'; |
| 85 |
$campaign = 'pro-upgrade'; |
| 86 |
$term = ''; |
| 87 |
/** |
| 88 |
* Filter the upgrade link medium parameter. |
| 89 |
* |
| 90 |
* @since 6.0.0 |
| 91 |
* |
| 92 |
* @param string $medium UTM medium parameter. |
| 93 |
*/ |
| 94 |
$medium = apply_filters( 'loginpress_upgrade_link_medium', $medium ); |
| 95 |
|
| 96 |
// Build the upgrade link from the (possibly filtered) medium. |
| 97 |
$upgrade = loginpress_utm_link( $url, $source, $medium, $campaign, $term, $content ); |
| 98 |
|
| 99 |
/** |
| 100 |
* Filter the upgrade link. |
| 101 |
* |
| 102 |
* Allows plugins to modify the final URL or append tracking/affiliate parameters. |
| 103 |
* |
| 104 |
* @since 6.0.0 |
| 105 |
* |
| 106 |
* @param string $upgrade Upgrade link. |
| 107 |
*/ |
| 108 |
return apply_filters( 'loginpress_upgrade_link', $upgrade ); |
| 109 |
} |
| 110 |
|
| 111 |
/** |
| 112 |
* Check if LoginPress Pro is active. |
| 113 |
* |
| 114 |
* @since 6.0.0 |
| 115 |
* |
| 116 |
* @return bool |
| 117 |
*/ |
| 118 |
function loginpress_is_pro() { |
| 119 |
return class_exists( 'LoginPress_Pro' ) || defined( 'LOGINPRESS_PRO_VERSION' ); |
| 120 |
} |
| 121 |
|
| 122 |
/** |
| 123 |
* Maximum session expiration time in minutes for the settings field. |
| 124 |
* |
| 125 |
* @since 6.2.3 |
| 126 |
* |
| 127 |
* @return int Non-negative minute cap (default 43200 = 30 days). |
| 128 |
*/ |
| 129 |
function loginpress_session_expiration_max() { |
| 130 |
/** |
| 131 |
* Filter the maximum session expiration time in minutes. |
| 132 |
* |
| 133 |
* @since 6.2.3 |
| 134 |
* |
| 135 |
* @param int $max Maximum minutes. Default 43200 (30 days). |
| 136 |
*/ |
| 137 |
$max = absint( apply_filters( 'loginpress_session_expiration_max', 43200 ) ); |
| 138 |
|
| 139 |
return max( 0, $max ); |
| 140 |
} |
| 141 |
|