PluginProbe ʕ •ᴥ•ʔ
Popup Builder & Popup Maker for WordPress – OptinMonster Email Marketing and Lead Generation / 2.16.5
Popup Builder & Popup Maker for WordPress – OptinMonster Email Marketing and Lead Generation v2.16.5
2.16.24 trunk 2.13.8 2.14.0 2.14.1 2.15.0 2.15.1 2.15.2 2.15.3 2.16.0 2.16.1 2.16.10 2.16.11 2.16.12 2.16.13 2.16.14 2.16.15 2.16.16 2.16.17 2.16.18 2.16.19 2.16.2 2.16.20 2.16.21 2.16.22 2.16.3 2.16.4 2.16.5 2.16.6 2.16.7 2.16.8 2.16.9
optinmonster / OMAPI / Partners.php
optinmonster / OMAPI Last commit date
EasyDigitalDownloads 3 years ago Elementor 2 years ago Integrations 3 years ago MemberPress 2 years ago Plugins 2 years ago Promos 3 years ago Rules 2 years ago Shortcodes 2 years ago WPForms 1 year ago WooCommerce 1 year ago Actions.php 1 year ago Ajax.php 4 years ago Api.php 1 year ago ApiAuth.php 4 years ago ApiKey.php 1 year ago AssetLoader.php 5 years ago BaseRestApi.php 3 years ago Blocks.php 1 year ago ClassicEditor.php 3 years ago ConstantContact.php 1 year ago Debug.php 1 year ago EasyDigitalDownloads.php 1 year ago Elementor.php 3 years ago Inserter.php 3 years ago InstallSkin.php 5 years ago InstallSkinCompat.php 5 years ago MailPoet.php 1 year ago MemberPress.php 2 years ago Menu.php 1 year ago Notifications.php 1 year ago OmuApi.php 4 years ago Output.php 1 year ago Pages.php 1 year ago Partners.php 1 year ago Plugins.php 2 years ago Promos.php 3 years ago Refresh.php 1 year ago RestApi.php 1 year ago RevenueAttribution.php 4 years ago Review.php 4 years ago Rules.php 1 year ago Save.php 2 years ago Shortcode.php 4 years ago Sites.php 1 year ago Support.php 1 year ago Type.php 3 years ago Urls.php 1 year ago Utils.php 1 year ago Validate.php 2 years ago WPForms.php 2 years ago Welcome.php 4 years ago Widget.php 4 years ago WooCommerce.php 1 year ago Wordfence.php 3 years ago WpErrorException.php 5 years ago
Partners.php
223 lines
1 <?php
2 /**
3 * Partners class.
4 *
5 * @since 2.0.0
6 *
7 * @package OMAPI
8 * @author Justin Sternberg
9 */
10
11 // Exit if accessed directly.
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 /**
17 * The Partners class.
18 *
19 * @since 2.0.0
20 */
21 class OMAPI_Partners {
22
23 /**
24 * The OM landing page url.
25 *
26 * @since 1.8.4
27 */
28 const LANDING_URL = 'https://optinmonster.com/wp/?utm_source=orgplugin&utm_medium=link&utm_campaign=wpdashboard';
29
30 /**
31 * The SaS affiliate url.
32 *
33 * @since 2.0.0
34 */
35 const SAS_URL = 'https://www.shareasale.com/r.cfm?u=%1$s&b=601672&m=49337&afftrack=&urllink=optinmonster.com';
36
37 /**
38 * Get the SAS Partner ID.
39 *
40 * 3 ways to specify an ID, ordered by highest to lowest priority:
41 * - add_filter( 'optinmonster_sas_id', function() { return 1234; } );
42 * - define( 'OPTINMONSTER_SAS_ID', 1234 );
43 * - get_option( 'optinmonster_sas_id' ); (with the option being in the
44 * wp_options table) If an ID is present, returns the affiliate link
45 * with the affiliate ID.
46 *
47 * @since 2.0.0
48 *
49 * @return string
50 */
51 public static function get_sas_id() {
52 $sas_id = '';
53
54 // Check if sas ID is a constant.
55 if ( defined( 'OPTINMONSTER_SAS_ID' ) ) {
56 $sas_id = OPTINMONSTER_SAS_ID;
57 }
58
59 // Now run any filters that may be on the sas ID.
60 $sas_id = apply_filters( 'optinmonster_sas_id', $sas_id );
61
62 /**
63 * If we still don't have a sas ID by this point
64 * check the DB for an option
65 */
66 if ( empty( $sas_id ) ) {
67 $sas_id = get_option( 'optinmonster_sas_id', $sas_id );
68 }
69
70 return $sas_id;
71 }
72
73 /**
74 * Get the trial Partner ID.
75 *
76 * 3 ways to specify an ID, ordered by highest to lowest priority:
77 * - add_filter( 'optinmonster_trial_id', function() { return 1234; } );
78 * - define( 'OPTINMONSTER_TRIAL_ID', 1234 );
79 * - get_option( 'optinmonster_trial_id' ); (with the option being in the
80 * wp_options table) If an ID is present, returns the affiliate link
81 * with the affiliate ID.
82 *
83 * @since 2.0.0
84 *
85 * @return string
86 */
87 public static function get_trial_id() {
88 $trial_id = '';
89
90 // Check if trial ID is a constant.
91 if ( defined( 'OPTINMONSTER_TRIAL_ID' ) ) {
92 $trial_id = OPTINMONSTER_TRIAL_ID;
93 }
94
95 // Now run any filters that may be on the trial ID.
96 $trial_id = apply_filters( 'optinmonster_trial_id', $trial_id );
97
98 /**
99 * If we still don't have a trial ID by this point
100 * check the DB for an option
101 */
102 if ( empty( $trial_id ) ) {
103 $trial_id = get_option( 'optinmonster_trial_id', $trial_id );
104 }
105
106 return $trial_id;
107 }
108
109 /**
110 * Get the affiliate url for given id.
111 *
112 * @since 1.8.4
113 *
114 * @param mixed $partner_id The Partner ID.
115 *
116 * @return string The affilaite url.
117 */
118 protected static function get_affiliate_url( $partner_id ) {
119 return sprintf( self::SAS_URL, rawurlencode( trim( $partner_id ) ) );
120 }
121
122 /**
123 * Get the partner url.
124 *
125 * Not used directly, but parsed for query args.
126 *
127 * @since 2.0.0
128 *
129 * @return boolean
130 */
131 protected static function get_partner_url() {
132 $id = self::get_trial_id();
133 $type = 'trial';
134 if ( empty( $id ) ) {
135 $id = self::get_sas_id();
136 $type = 'sas';
137 }
138
139 // Return the regular WP landing page by default.
140 $url = self::LANDING_URL;
141
142 // Return the trial link if we have a trial ID.
143 if ( ! empty( $id ) ) {
144 $url = self::get_affiliate_url( $id );
145 }
146
147 return apply_filters(
148 'optin_monster_action_link',
149 $url,
150 array(
151 'type' => $type,
152 'id' => $id,
153 )
154 );
155 }
156
157 /**
158 * Returns partner url, if it exists.
159 *
160 * Not used directly, but parsed for query args.
161 *
162 * @since 2.0.0
163 *
164 * @return string|boolean
165 */
166 public static function has_partner_url() {
167 $url = self::get_partner_url();
168
169 return false === strpos( $url, 'optinmonster.com/wp' )
170 ? $url
171 : false;
172 }
173
174 /**
175 * Get the Partner ID.
176 *
177 * @since 2.0.0
178 * @since 2.15.0 Fallback to parsing the partner url for the ID.
179 *
180 * @return string
181 */
182 public static function get_id() {
183 $id = self::get_trial_id();
184 if ( empty( $id ) ) {
185 $id = self::get_sas_id();
186 }
187
188 if ( empty( $id ) ) {
189
190 // Try to get the ID from the partner url.
191 $url = self::has_partner_url();
192 if ( $url ) {
193 $parsed = wp_parse_url( $url );
194 if (
195 ! empty( $parsed['host'] )
196 // Only get the ID if it's a shareasale url.
197 && false !== stripos( $parsed['host'], 'shareasale.com' )
198 && ! empty( $parsed['query'] )
199 ) {
200 $args = wp_parse_args( $parsed['query'] );
201 if ( ! empty( $args['u'] ) ) {
202 $id = $args['u'];
203 }
204 }
205 }
206 }
207
208 return $id;
209 }
210
211 /**
212 * Get the referrer, if stored.
213 *
214 * @since 2.10.0
215 *
216 * @return string Referrer
217 */
218 public static function referred_by() {
219 return sanitize_text_field( get_option( 'optinmonster_referred_by', '' ) );
220 }
221
222 }
223