/** * Add a call to jQuery.noConflict() as an inline script to jQuery core. */ public function jquery_noconflict_mode() { if (!apply_filters('homonoia_jq_noconflict', true)) { return; } if (!isset($this->script_map['jquery-core']['src'])) { return; } wp_add_inline_script('jquery-core', 'jQuery.noConflict();'); }
public function render($form) { wp_enqueue_script('itsec-mc-validate', plugins_url('/js/mc-validate.js', __FILE__), array('jquery'), '20160526', true); $this->inline_js = "(function(\$) {window.fnames = new Array(); window.ftypes = new Array();fnames[0]='EMAIL';ftypes[0]='email';fnames[1]='FNAME';ftypes[1]='text';fnames[2]='LNAME';ftypes[2]='text';}(jQuery));"; if (function_exists('wp_add_inline_script')) { wp_add_inline_script('itsec-mc-validate', $this->inline_js); } else { add_filter('script_loader_tag', array($this, 'script_loader_tag'), null, 2); } ?> <div id="mc_embed_signup"> <form action="https://ithemes.us2.list-manage.com/subscribe/post?u=7acf83c7a47b32c740ad94a4e&id=5176bfed9e" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate> <div style="text-align: center;"> <img src="<?php echo plugins_url('img/security-ebook.png', __FILE__); ?> " width="145" height="187" alt="WordPress Security - A Pocket Guide"> </div> <p><?php _e('Get tips for securing your site + the latest WordPress security updates, news and releases from iThemes.', 'better-wp-security'); ?> </p> <div id="mce-responses" class="clear"> <div class="response" id="mce-error-response" style="display:none"></div> <div class="response" id="mce-success-response" style="display:none"></div> </div> <label for="mce-EMAIL" style="display: block;margin-bottom: 3px;"><?php _e('Email Address', 'better-wp-security'); ?> </label> <input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL" placeholder="*****@*****.**"> <br/><br/> <input type="submit" value="<?php _e('Subscribe', 'better-wp-security'); ?> " name="subscribe" id="mc-embedded-subscribe" class="button button-secondary"> </form> </div> <?php }
public static function addHeaderTag(array $element, $in_footer = false) { switch ($element['tag']) { case 'link': if (!empty($element['href']) && !empty($element['rel']) && $element['rel'] == 'stylesheet') { $href = $element['href']; $media = !empty($element['media']) ? $element['media'] : null; \wp_register_style(basename($href, '.css'), $href, array(), false, $media); \wp_enqueue_style(basename($href, '.css')); return true; } break; case 'style': if (!empty($element['content'])) { $content = $element['content']; if (is_admin()) { $type = !empty($element['type']) ? $element['type'] : 'text/css'; self::$styles[] = "<style type=\"{$type}\">{$content}</style>"; } else { \wp_add_inline_style(md5($content), $content); } return true; } break; case 'script': if (!empty($element['src'])) { $src = $element['src']; \wp_register_script(basename($src, '.js'), $src, array(), false, $in_footer); \wp_enqueue_script(basename($src, '.js')); return true; } elseif (!empty($element['content'])) { $content = $element['content']; if (is_admin()) { $type = !empty($element['type']) ? $element['type'] : 'text/css'; self::$scripts[] = "<script type=\"{$type}\">{$content}</script>"; } else { \wp_add_inline_script(md5($content), $content); } return true; } break; } return false; }
protected static function registerScripts($pos) { if (empty(self::$scripts[$pos])) { return; } $in_footer = $pos != 'head'; krsort(self::$scripts[$pos], SORT_NUMERIC); foreach (self::$scripts[$pos] as $scripts) { foreach ($scripts as $script) { switch ($script[':type']) { case 'file': $src = preg_replace('/(\\?.*)$/', '', $script['src']); \wp_register_script(basename($src, '.js'), $src, array(), false, $in_footer); \wp_enqueue_script(basename($src, '.js')); break; case 'inline': if (is_admin()) { $type = !empty($script['type']) ? $script['type'] : 'text/css'; self::$wp_scripts[] = "<script type=\"{$type}\">{$script['content']}</script>"; } else { \wp_add_inline_script(md5($script['content']), $script['content']); } break; } } } self::$scripts[$pos] = []; }
public function __construct() { add_action('admin_enqueue_scripts', function () { if (did_action('wp_enqueue_media') == false) { wp_enqueue_media(); } wp_add_inline_script('image-edit', ' jQuery(".plance-medial-button-select").live("click",function() { var send_attachment_bkp = wp.media.editor.send.attachment; var $btn = jQuery(this); wp.media.editor.send.attachment = function(props, attachment) { jQuery($btn).parents(".plance-medial").find(".plance-medial-img").attr("src", attachment.url); jQuery($btn).parents(".plance-medial").find(".plance-medial-src").val(attachment.url); wp.media.editor.send.attachment = send_attachment_bkp; } wp.media.editor.open($btn); return false; }); jQuery(".plance-medial-button-remove").live("click",function() { var $p = jQuery(this).parents(".plance-medial"); var src = $p.find(".plance-medial-img").attr("data-src"); $p.find(".plance-medial-img").attr("src", src); $p.find(".plance-medial-src").val(""); return false; }); '); }); }
public static function init() { // Hotfix for NextGEN Gallery plugin if (defined('NGG_PLUGIN_VERSION')) { add_filter('elementor/utils/get_edit_link', function ($edit_link) { return add_query_arg('display_gallery_iframe', '', $edit_link); }); } // Hack for Ninja Forms if (class_exists('\\Ninja_Forms')) { add_action('elementor/preview/enqueue_styles', function () { ob_start(); \NF_Display_Render::localize(0); ob_clean(); wp_add_inline_script('nf-front-end', 'var nfForms = nfForms || [];'); }); } // Exclude our Library from sitemap.xml in Yoast SEO plugin add_filter('wpseo_sitemaps_supported_post_types', function ($post_types) { unset($post_types[TemplateLibrary\Source_Local::CPT]); return $post_types; }); // Disable optimize files in Editor from Autoptimize plugin add_filter('autoptimize_filter_noptimize', function ($retval) { if (Plugin::instance()->editor->is_edit_mode()) { $retval = true; } return $retval; }); }
/** * Add inline JS handler * * @return void */ public function add_js_handler() { if (!self::$handler_file) { return; } wp_add_inline_script($this->get_handle(), self::$handler_file); }
public static function javascript() { global $wp_query; wp_reset_query(); wp_print_scripts('jquery'); $token = wp_create_nonce('wmp_token'); if (!is_front_page() && (is_page() || is_single())) { /*================================================== Add code by SECT. ================================================== */ // echo '<!-- WordPress Most Popular --><script type="text/javascript">/* <![CDATA[ */ jQuery.post("' . admin_url('admin-ajax.php') . '", { action: "wmp_update", id: ' . $wp_query->post->ID . ', token: "' . $token . '" }); /* ]]> */</script><!-- /WordPress Most Popular -->'; $paged = get_query_var('page') ? get_query_var('page') : 1; // echo '<!-- WordPress Most Popular Custom --><script type="text/javascript">/* <![CDATA[ */ jQuery.post("' . admin_url('admin-ajax.php') . '", { action: "wmp_update", id: ' . $wp_query->post->ID . ', paged: ' . $paged . ', token: "' . $token . '" }); /* ]]> */</script><!-- /WordPress Most Popular Custom -->'; $script = ' /* WordPress Most Popular Custom */ jQuery.post("' . admin_url('admin-ajax.php') . '", { action: "wmp_update", id: ' . $wp_query->post->ID . ', paged: ' . $paged . ', token: "' . $token . '" }); '; wp_add_inline_script('jquery', $script); } }
/** * Enqueue Customizer frontend scripts. */ public function enqueue_frontend_scripts() { if (!$this->snapshot || is_customize_preview()) { return; } $handle = 'customize-snapshots-frontend'; wp_enqueue_script($handle); $exports = array('uuid' => $this->snapshot ? $this->snapshot->uuid() : null, 'home_url' => wp_parse_url(home_url('/')), 'l10n' => array('restoreSessionPrompt' => __('It seems you may have inadvertently navigated away from previewing a customized state. Would you like to restore the snapshot context?', 'customize-snapshots'))); wp_add_inline_script($handle, sprintf('CustomizeSnapshotsFrontend.init( %s )', wp_json_encode($exports)), 'after'); }
/** * Localizes the jQuery UI datepicker. * * @since 4.6.0 * * @link http://api.jqueryui.com/datepicker/#options * * @global WP_Locale $wp_locale The WordPress date and time locale object. */ function wp_localize_jquery_ui_datepicker() { global $wp_locale; if (!wp_script_is('jquery-ui-datepicker', 'enqueued')) { return; } // Convert the PHP date format into jQuery UI's format. $datepicker_date_format = str_replace(array('d', 'j', 'l', 'z', 'F', 'M', 'n', 'm', 'Y', 'y'), array('dd', 'd', 'DD', 'o', 'MM', 'M', 'm', 'mm', 'yy', 'y'), get_option('date_format')); $datepicker_defaults = wp_json_encode(array('closeText' => __('Close'), 'currentText' => __('Today'), 'monthNames' => array_values($wp_locale->month), 'monthNamesShort' => array_values($wp_locale->month_abbrev), 'nextText' => __('Next'), 'prevText' => __('Previous'), 'dayNames' => array_values($wp_locale->weekday), 'dayNamesShort' => array_values($wp_locale->weekday_abbrev), 'dayNamesMin' => array_values($wp_locale->weekday_initial), 'dateFormat' => $datepicker_date_format, 'firstDay' => absint(get_option('start_of_week')), 'isRTL' => $wp_locale->is_rtl())); wp_add_inline_script('jquery-ui-datepicker', "jQuery(document).ready(function(jQuery){jQuery.datepicker.setDefaults({$datepicker_defaults});});"); }
/** * Enqueue and localize livestamp.js script. * * @since 2.7.0 */ function bp_core_enqueue_livestamp() { // If bp-livestamp isn't enqueued, do it now. if (wp_script_is('bp-livestamp')) { return; } /* * Only enqueue Moment.js locale if we registered it in * bp_core_register_common_scripts(). */ if (wp_script_is('bp-moment-locale', 'registered')) { wp_enqueue_script('bp-moment-locale'); if (function_exists('wp_add_inline_script')) { wp_add_inline_script('bp-livestamp', bp_core_moment_js_config()); } else { add_action('wp_footer', '_bp_core_moment_js_config_footer', 20); } } wp_enqueue_script('bp-livestamp'); }
/** * Register inline code. * * @param Asset $asset */ protected function registerInline(Asset $asset) { $args = $asset->getArgs(); if (empty($args) || !isset($args['inline'])) { return; } // Process if there are inline codes. $inlines = $args['inline']; foreach ($inlines as $inline) { if ('script' === $asset->getType()) { wp_add_inline_script($args['handle'], $inline['data'], $inline['position']); } elseif ('style' === $asset->getType()) { wp_add_inline_style($args['handle'], $inline['data']); } } }
/** * Enqueue preview scripts and styles. * * @since 1.0.0 * @return void */ public function enqueue_styles() { // Hold-on all jQuery plugins after all HTML markup render wp_add_inline_script('jquery-migrate', 'jQuery.holdReady( true );'); // Make sure jQuery embed in preview window wp_enqueue_script('jquery'); Plugin::instance()->frontend->enqueue_styles(); $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; $direction_suffix = is_rtl() ? '-rtl' : ''; wp_register_style('editor-preview', ELEMENTOR_ASSETS_URL . 'css/editor-preview' . $direction_suffix . $suffix . '.css', [], Plugin::instance()->get_version()); wp_enqueue_style('editor-preview'); do_action('elementor/preview/enqueue_styles'); }
$is_required = isset($field['required']) ? $field['required'] : false; $value = isset($field['value']) ? esc_attr($field['value']) : ''; $min_date = isset($field['min_date']) ? esc_attr($field['min_date']) : ''; $max_date = isset($field['max_date']) ? esc_attr($field['max_date']) : ''; $json_args = array('changeMonth' => true, 'changeYear' => true, 'dateFormat' => 'MM d, yy'); if (array_key_exists('min_date', $field)) { $json_args['minDate'] = '+' . $field['min_date']; } if (array_key_exists('max_date', $field)) { $json_args['maxDate'] = '+' . $field['max_date']; } /* Enqueue the datepicker */ if (!wp_script_is('jquery-ui-datepicker')) { wp_enqueue_script('jquery-ui-datepicker'); } wp_add_inline_script('jquery-ui-datepicker', "jQuery(document).ready( function(){\n\t\tjQuery( '.datepicker' ).datepicker( " . json_encode($json_args) . ");\n\t});"); ?> <div id="charitable_field_<?php echo $field['key']; ?> " class="<?php echo $classes; ?> "> <?php if (isset($field['label'])) { ?> <label for="charitable_field_<?php echo $field['key']; ?> ">
/** * @param string $name * @param string $handle */ public static function add_inline_script($name, $handle) { wp_add_inline_script($handle, static::get_script($name)); }
/** * Enqueue JavaScript * Inline script with jQuery dependency * * @return void */ function mss_enqueue_scripts() { ob_start(); ?> jQuery(document).ready( function($) { $('#wp-admin-bar-my-sites-search.hide-if-no-js').show(); $('#wp-admin-bar-my-sites-search input').keyup( function( ) { var searchValRegex = new RegExp( $(this).val(), 'i'); $('#wp-admin-bar-my-sites-list > li.menupop').hide().filter(function() { return searchValRegex.test( $(this).find('> a').text() ); }).show(); }); }); <?php $script = ob_get_clean(); wp_enqueue_script('jquery-core'); wp_add_inline_script('jquery-core', $script); }
/** * @ticket 14853 */ public function test_wp_add_inline_script_concat_with_conditional() { global $wp_scripts; $wp_scripts->do_concat = true; $wp_scripts->default_dirs = array('/wp-admin/js/', '/wp-includes/js/'); // Default dirs as in wp-includes/script-loader.php $expected_localized = "<!--[if gte IE 9]>\n"; $expected_localized .= "<script type='text/javascript'>\n/* <![CDATA[ */\nvar testExample = {\"foo\":\"bar\"};\n/* ]]> */\n</script>\n"; $expected_localized .= "<![endif]-->\n"; $expected = "<!--[if gte IE 9]>\n"; $expected .= "<script type='text/javascript'>\nconsole.log(\"before\");\n</script>\n"; $expected .= "<script type='text/javascript' src='http://example.com'></script>\n"; $expected .= "<script type='text/javascript'>\nconsole.log(\"after\");\n</script>\n"; $expected .= "<![endif]-->\n"; wp_enqueue_script('test-example', 'example.com', array(), null); wp_localize_script('test-example', 'testExample', array('foo' => 'bar')); wp_add_inline_script('test-example', 'console.log("before");', 'before'); wp_add_inline_script('test-example', 'console.log("after");'); wp_script_add_data('test-example', 'conditional', 'gte IE 9'); $this->assertEquals($expected_localized, get_echo('wp_print_scripts')); $this->assertEquals($expected, $wp_scripts->print_html_before); $this->assertEquals('', $wp_scripts->print_html); }
/** * Load scripts/styles for embeds. * * @since 3.0.0 * @access public * @return void */ function stargazer_embed_enqueue() { wp_add_inline_script('wp-mediaelement', stargazer_get_mediaelement_inline_script()); wp_enqueue_script('stargazer'); wp_enqueue_style('stargazer-fonts'); wp_enqueue_style('hybrid-one-five'); wp_enqueue_style('stargazer-mediaelement'); wp_enqueue_style('stargazer-media'); wp_enqueue_style('stargazer-embed'); wp_enqueue_style('stargazer-locale'); }
public function js_dialog($name, $params = array()) { if (true !== $this->open_link_in_new) { return; } $defaults = array('menubar' => 1, 'resizable' => 1, 'width' => 600, 'height' => 400); $params = array_merge($defaults, $params); $opts = array(); foreach ($params as $key => $val) { $opts[] = "{$key}={$val}"; } $opts = implode(',', $opts); // Add JS after sharing-js has been enqueued. wp_add_inline_script('sharing-js', "var windowOpen;\n\t\t\tjQuery( document.body ).on( 'click', 'a.share-{$name}', function() {\n\t\t\t\t// If there's another sharing window open, close it.\n\t\t\t\tif ( 'undefined' !== typeof windowOpen ) {\n\t\t\t\t\twindowOpen.close();\n\t\t\t\t}\n\t\t\t\twindowOpen = window.open( jQuery( this ).attr( 'href' ), 'wpcom{$name}', '{$opts}' );\n\t\t\t\treturn false;\n\t\t\t});"); }
/** * @ticket 36392 */ public function test_wp_add_inline_script_before_third_core_script_prints_two_concat_scripts() { global $wp_scripts; $wp_scripts->do_concat = true; $wp_scripts->default_dirs = array('/wp-admin/js/', '/wp-includes/js/'); // Default dirs as in wp-includes/script-loader.php wp_enqueue_script('one', '/wp-includes/js/script.js'); wp_enqueue_script('two', '/wp-includes/js/script2.js', array('one')); wp_enqueue_script('three', '/wp-includes/js/script3.js'); wp_add_inline_script('three', 'console.log("before three");', 'before'); wp_enqueue_script('four', '/wp-includes/js/script4.js'); $ver = get_bloginfo('version'); $expected = "<script type='text/javascript' src='/wp-admin/load-scripts.php?c=0&load%5B%5D=one,two&ver={$ver}'></script>\n"; $expected .= "<script type='text/javascript'>\nconsole.log(\"before three\");\n</script>\n"; $expected .= "<script type='text/javascript' src='/wp-includes/js/script3.js?ver={$ver}'></script>\n"; $expected .= "<script type='text/javascript' src='/wp-includes/js/script4.js?ver={$ver}'></script>\n"; $this->assertEquals($expected, get_echo('wp_print_scripts')); }