function op_localize_script($types = '') { //Get the localized variables $localize = apply_filters(OP_SN . '-script-localize', op_default_localize()); //Get localized variables if a type is set if (!empty($types)) { //Init types $types = is_array($types) ? $types : ($types = array($types)); //Loop through types and get variables foreach ($types as $type) { $localize = apply_filters(OP_SN . '-script-localize-' . $type, $localize); } } //Finally, assuming we have data to localize, we print out the data in a JSON object echo count($localize) > 0 ? '<script type="text/javascript">OP = (typeof(OP)=="undefined" ? ' . json_encode($localize) . ' : OP);</script>' : ''; }
function print_scripts() { wp_enqueue_style(OP_SN . '-fancybox', OP_JS . 'fancybox/jquery.fancybox.css'); wp_enqueue_script(OP_SN . '-fancybox', OP_JS . 'fancybox/jquery.fancybox.pack.js', array('jquery')); wp_register_script(OP_SN . '-fancybox-op', OP_JS . 'fancybox/helpers/jquery.fancybox-op.js', array(OP_SN . '-fancybox')); wp_enqueue_script(OP_SN . '-admin', OP_JS . 'admin.js', array(OP_SN . '-fancybox'), '2011-10-05'); wp_enqueue_style(OP_SN . '-admin-assets', OP_CSS . 'assets.css', array(OP_SN . '-admin-common', OP_SN . '-fancybox'), '2011-10-05'); wp_register_style(OP_SN . '-admin-common', OP_CSS . 'common.css', array('farbtastic', 'thickbox'), '2011-10-05'); wp_register_script(OP_SN . '-ajax-upload', OP_JS . 'fileuploader.js', false); wp_register_script(OP_SN . '-checkbox-js', OP_JS . 'jquery/jquery.ibutton.min.js', array('jquery'), '2011-10-05'); wp_register_script(OP_SN . '-placeholder', OP_JS . 'jquery/jquery.placeholder.min.js', array('jquery'), '2011-10-05'); wp_register_script(OP_SN . '-admin-common', OP_JS . 'common.js', array('farbtastic', OP_SN . '-checkbox-js', 'jquery-ui-position', 'media-upload', 'thickbox'), '2011-10-05'); wp_register_script(OP_SN . '-blog-settings', OP_JS . 'blog_settings.js', array(OP_SN . '-admin-common'), '2012-01-17'); wp_enqueue_script('jquery-ui-slider'); $localize = array('ajaxurl' => admin_url('admin-ajax.php'), 'SN' => OP_SN, 'imgurl' => OP_IMG, 'OP_URL' => OP_URL, 'OP_JS' => OP_JS, 'pb_unload_alert' => __('This page is asking you to confirm that you want to leave - data you have entered may not be saved.', OP_SN), 'pb_save_alert' => __('Please make sure you are happy with all of your options as some options will not be able to be changed for this page later.', OP_SN), 'include_url' => includes_url(), 'paths' => array('url' => OP_URL, 'img' => OP_IMG, 'js' => OP_JS, 'css' => OP_CSS), 'social' => array('twitter' => OP_SOCIAL_ACCT_TWITTER, 'facebook' => OP_SOCIAL_ACCT_FACEBOOK, 'googleplus' => OP_SOCIAL_ACCT_GOOGLEPLUS)); $localize = array_merge(op_default_localize(), $localize); //Finally, assuming we have data to localize, we print out the data in a JSON object echo count($localize) > 0 ? '<script type="text/javascript">OP = (typeof(OP)=="undefined" ? ' . json_encode($localize) . ' : OP);</script>' : ''; wp_localize_script(OP_SN . '-admin', 'OptimizePress', apply_filters(OP_SN . '-script-localize', $localize)); }
function print_scripts() { if ($this->print_scripts_initialized == true) { return false; } $this->print_scripts_initialized = true; //If jQuery version is higher than 1.9 we require jQuery migrate plugin (which is by default registered in WP versions that come with jQuery 1.9 or higher) if (wp_script_is('jquery-migrate', 'registered')) { wp_enqueue_script(OP_SN . '-noconflict-js', OP_JS . 'jquery/jquery.noconflict.js', array('jquery', 'jquery-migrate'), OP_VERSION); } else { wp_enqueue_script(OP_SN . '-noconflict-js', OP_JS . 'jquery/jquery.noconflict.js', array('jquery'), OP_VERSION); } wp_enqueue_style(OP_SN . '-fancybox', OP_JS . 'fancybox/jquery.fancybox.css', false, OP_VERSION); wp_enqueue_script(OP_SN . '-fancybox', OP_JS . 'fancybox/jquery.fancybox.pack.js', array(OP_SN . '-noconflict-js'), OP_VERSION); wp_register_script(OP_SN . '-fancybox-op', OP_JS . 'fancybox/helpers/jquery.fancybox-op.js', array(OP_SN . '-noconflict-js', OP_SN . '-fancybox'), OP_VERSION); // Fancybox for images $fancybox_images = op_default_option('fancybox_images'); if (is_array($fancybox_images) && $fancybox_images['enabled'] === 'Y') { wp_enqueue_script(OP_SN . '-fancybox-images', OP_JS . 'fancybox_images' . OP_SCRIPT_DEBUG . '.js', array(OP_SN . '-noconflict-js', OP_SN . '-fancybox'), OP_VERSION, true); } wp_enqueue_script(OP_SN . '-admin', OP_JS . 'admin.js', array(OP_SN . '-noconflict-js', OP_SN . '-fancybox'), OP_VERSION); wp_enqueue_style(OP_SN . '-admin-assets', OP_CSS . 'assets.css', array(OP_SN . '-admin-common', OP_SN . '-fancybox'), OP_VERSION); wp_register_style(OP_SN . '-admin-common', OP_CSS . 'common.css', array('farbtastic', 'thickbox'), OP_VERSION); wp_register_script(OP_SN . '-ajax-upload', OP_JS . 'fileuploader.js', array(OP_SN . '-noconflict-js'), OP_VERSION); wp_register_script(OP_SN . '-checkbox-js', OP_JS . 'jquery/jquery.ibutton.min.js', array(OP_SN . '-noconflict-js'), OP_VERSION); wp_register_script(OP_SN . '-placeholder', OP_JS . 'jquery/jquery.placeholder.min.js', array(OP_SN . '-noconflict-js', OP_SN . '-noconflict-js'), OP_VERSION); wp_register_script(OP_SN . '-admin-common', OP_JS . 'common.js', array(OP_SN . '-noconflict-js', 'farbtastic', OP_SN . '-checkbox-js', 'jquery-ui-position', 'media-upload', 'thickbox'), OP_VERSION); wp_register_script(OP_SN . '-blog-settings', OP_JS . 'blog_settings.js', array(OP_SN . '-noconflict-js', OP_SN . '-admin-common'), OP_VERSION); wp_enqueue_script('jquery-ui-slider', false, array(OP_SN . '-noconflict-js'), OP_VERSION); $localize = array('ajaxurl' => admin_url('admin-ajax.php'), 'SN' => OP_SN, 'imgurl' => OP_IMG, 'OP_URL' => OP_URL, 'OP_JS' => OP_JS, 'pb_unload_alert' => __('This page is asking you to confirm that you want to leave - data you have entered may not be saved.', OP_SN), 'pb_save_alert' => __('Please make sure you are happy with all of your options as some options will not be able to be changed for this page later.', OP_SN), 'include_url' => includes_url(), 'paths' => array('url' => OP_URL, 'img' => OP_IMG, 'js' => OP_JS, 'css' => OP_CSS), 'social' => array('twitter' => OP_SOCIAL_ACCT_TWITTER, 'facebook' => OP_SOCIAL_ACCT_FACEBOOK, 'googleplus' => OP_SOCIAL_ACCT_GOOGLEPLUS)); $localize = array_merge(op_default_localize(), $localize); //Finally, assuming we have data to localize, we print out the data in a JSON object echo count($localize) > 0 ? '<script type="text/javascript">OP = (typeof(OP)=="undefined" ? ' . json_encode($localize) . ' : OP);</script>' : ''; wp_localize_script(OP_SN . '-admin', 'OptimizePress', apply_filters(OP_SN . '-script-localize', $localize)); }