Skip to content

Commit 54b7f6e

Browse files
committed
Add ProfitWell integration
1 parent 7caec02 commit 54b7f6e

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

includes/core.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ function setup() {
2525
add_action( 'wp_enqueue_scripts', $n( 'scripts' ) );
2626
add_action( 'admin_enqueue_scripts', $n( 'admin_styles' ) );
2727
add_action( 'admin_enqueue_scripts', $n( 'admin_scripts' ) );
28+
add_action( 'wp_footer', $n( 'add_profitwell_script' ) );
29+
2830
do_action( 'paddlepress_loaded' );
2931
}
3032

@@ -217,3 +219,39 @@ function admin_styles() {
217219
);
218220

219221
}
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

Comments
 (0)