LLMS_Admin_Assets::admin_print_scripts()
Initialize the “llms” object for other scripts to hook into
Return Return
(void)
Source Source
File: includes/admin/class.llms.admin.assets.php
public function admin_print_scripts() {
$screen = get_current_screen();
global $post;
$postdata = array();
if ( ! empty( $post ) ) {
$postdata = array(
'id' => $post->ID,
'post_type' => $post->post_type,
);
}
echo '
<script type="text/javascript">
window.llms = window.llms || {};
window.llms.ajax_nonce = "' . esc_attr( wp_create_nonce( LLMS_AJAX::NONCE ) ) . '";
window.llms.admin_url = "' . esc_url( admin_url() ) . '";
window.llms.home_url = "' . esc_url( home_url() ) . '";
window.llms.post = ' . wp_json_encode( $postdata ) . ';
window.llms.analytics = ' . wp_json_encode( $this->get_analytics_options() ) . ';
</script>
';
echo '<script type="text/javascript">window.LLMS = window.LLMS || {};</script>';
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- get_js_strings returns json_encoded strings.
echo '<script type="text/javascript">window.LLMS.l10n = window.LLMS.l10n || {}; window.LLMS.l10n.strings = ' . wp_json_encode( LLMS_L10n::get_js_strings( false ) ) . ';</script>';
$forms = LLMS_Forms::instance()->get_post_type();
if ( $forms === $screen->id ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output is escaped in `wp_slash()`.and wp_json_encode()
echo "<script>window.llms.formLocations = JSON.parse( '" . wp_slash( wp_json_encode( LLMS_Forms::instance()->get_locations() ) ) . "' );</script>";
}
if ( ! empty( $screen->is_block_editor ) || 'customize' === $screen->base ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output is escaped in `wp_slash()`.and wp_json_encode()
echo "<script>window.llms.userInfoFields = JSON.parse( '" . wp_slash( wp_json_encode( llms_get_user_information_fields_for_editor() ) ) . "' );</script>";
}
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 7.1.1 | Add home_url. |
| 5.9.0 | Use wp_slash() after wp_json_encode() to prevent issues encountered when strings contain single quotes. |
| 5.0.0 | Output Form location information as a window variable for block editor utilization. |
| 4.5.1 | Add an analytics localization object. |
| 4.4.0 | Add ajax_nonce. |
| 3.7.5 | Unknown. |
| 1.0.0 | Introduced. |