| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; |
| 4 |
} |
| 5 |
|
| 6 |
/** |
| 7 |
* Emits the Pushly SDK initialization snippet. |
| 8 |
* |
| 9 |
* Outputs the inline <script> directly with all dynamic values JSON-encoded |
| 10 |
* for safe embedding in JS contexts. |
| 11 |
* |
| 12 |
* @param string $sdk_key The Pushly SDK / domain key. |
| 13 |
* @param string $sw_root Base plugin URL used to build the service-worker path and scope. |
| 14 |
*/ |
| 15 |
function pushly_render_sdk_snippet( $sdk_key, $sw_root ) { |
| 16 |
?> |
| 17 |
<script> |
| 18 |
var PushlySDK = window.PushlySDK || []; |
| 19 |
function pushly() { PushlySDK.push(arguments) } |
| 20 |
pushly('load', { |
| 21 |
domainKey: decodeURIComponent("<?php echo rawurlencode( (string) $sdk_key ); ?>"), |
| 22 |
sw: <?php echo wp_json_encode( esc_url( $sw_root . 'assets/js/pushly-sdk-worker.js.php' ), JSON_UNESCAPED_SLASHES ); ?>, |
| 23 |
swScope: <?php echo wp_json_encode( esc_url( $sw_root ), JSON_UNESCAPED_SLASHES ); ?> |
| 24 |
}); |
| 25 |
</script> |
| 26 |
<?php |
| 27 |
} |
| 28 |
|