@@ -25,6 +25,8 @@ function setup() {
25
25
add_action ( 'wp_enqueue_scripts ' , $ n ( 'scripts ' ) );
26
26
add_action ( 'admin_enqueue_scripts ' , $ n ( 'admin_styles ' ) );
27
27
add_action ( 'admin_enqueue_scripts ' , $ n ( 'admin_scripts ' ) );
28
+ add_action ( 'wp_footer ' , $ n ( 'add_profitwell_script ' ) );
29
+
28
30
do_action ( 'paddlepress_loaded ' );
29
31
}
30
32
@@ -217,3 +219,39 @@ function admin_styles() {
217
219
);
218
220
219
221
}
222
+
223
+
224
+ /**
225
+ * Add ProfitWell Integration Script
226
+ *
227
+ * @return void
228
+ * @since 2.1
229
+ */
230
+ function add_profitwell_script () {
231
+ $ settings = Utils \get_settings ();
232
+ if ( ! $ settings ['enable_profitwell ' ] ) {
233
+ return ;
234
+ }
235
+
236
+ $ token = $ settings ['profitwell_public_api_token ' ];
237
+ if ( empty ( $ token ) ) {
238
+ return ;
239
+ }
240
+
241
+ $ start_options = '{} ' ;
242
+ $ current_user = wp_get_current_user ();
243
+ if ( $ current_user ->exists () ) {
244
+ $ start_options = "{user_email: ' {$ current_user ->user_email }'} " ;
245
+ }
246
+
247
+ ?>
248
+ <script id='profitwell-js' data-pw-auth='<?php echo esc_attr ( $ token ); ?> '>
249
+ (function(i,s,o,g,r,a,m){i[o]=i[o]||function(){(i[o].q=i[o].q||[]).push(arguments)};
250
+ a=s.createElement(g);m=s.getElementsByTagName(g)[0];a.async=1;a.src=r+'?auth='+
251
+ s.getElementById(o+'-js').getAttribute('data-pw-auth');m.parentNode.insertBefore(a,m);
252
+ })(window,document,'profitwell','script','https://public.profitwell.com/js/profitwell.js');
253
+
254
+ profitwell('start', <?php echo wp_kses_post ( $ start_options ); ?> );
255
+ </script>
256
+ <?php
257
+ }
0 commit comments