activation-actions.php
4 years ago
build-inline-scripts.php
3 weeks ago
build-modules.php
4 months ago
build-widgets.php
4 months ago
config-list.php
4 months ago
editor-promotion.php
3 weeks ago
handler-api.php
6 months ago
handler-widget.php
4 years ago
plugin-unsubscribe.php
3 weeks ago
build-inline-scripts.php
54 lines
| 1 | <?php |
| 2 | namespace ElementsKit_Lite\Core; |
| 3 | |
| 4 | defined( 'ABSPATH' ) || exit; |
| 5 | |
| 6 | /** |
| 7 | * Inline script registrar. |
| 8 | * |
| 9 | * Returns all necessary inline js & css. |
| 10 | * |
| 11 | * @since 1.0.0 |
| 12 | * @access public |
| 13 | */ |
| 14 | class Build_Inline_Scripts { |
| 15 | |
| 16 | use \ElementsKit_Lite\Traits\Singleton; |
| 17 | |
| 18 | public function __construct() { |
| 19 | // Frontend + Admin scripts |
| 20 | add_action( 'wp_print_scripts', array( $this, 'print_inline_script' ) ); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Get common inline JavaScript. |
| 25 | * |
| 26 | * @return string |
| 27 | */ |
| 28 | public function common_js() { |
| 29 | ob_start(); ?> |
| 30 | |
| 31 | var elementskit = { |
| 32 | resturl: '<?php echo defined( 'ICL_SITEPRESS_VERSION' ) ? esc_url(home_url('/wp-json/elementskit/v1/')) : esc_url(get_rest_url() . 'elementskit/v1/'); ?>', |
| 33 | } |
| 34 | |
| 35 | <?php |
| 36 | $output = ob_get_contents(); |
| 37 | ob_end_clean(); |
| 38 | return $output; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Print inline JavaScript. |
| 43 | * |
| 44 | * @return void |
| 45 | */ |
| 46 | public function print_inline_script() { |
| 47 | printf( |
| 48 | "<script type='text/javascript'>%s</script>", |
| 49 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Outputs trusted inline JavaScript generated by ElementsKit. |
| 50 | \ElementsKit_Lite\Utils::render( $this->common_js() ) |
| 51 | ); |
| 52 | } |
| 53 | } |
| 54 |