public static function controller()
 {
     /**
      * @see \WP_Customize_Manager::wp_loaded
      * It calls the `customize_register` action first,
      * and then - the `customize_preview_init` action
      */
     /*
     			add_action( 'customize_register', array(
     				'WPGlobus_Customize',
     				'action__customize_register'
     			) ); */
     /**
      * @since 1.5.0
      */
     if (WPGlobus_WP::is_pagenow('customize.php')) {
         require_once 'admin/wpglobus-customize-filters.php';
     }
     add_action('customize_preview_init', array('WPGlobus_Customize', 'action__customize_preview_init'));
     /**
      * This is called by wp-admin/customize.php
      */
     add_action('customize_controls_enqueue_scripts', array('WPGlobus_Customize', 'action__customize_controls_enqueue_scripts'), 1000);
     if (WPGlobus_WP::is_admin_doing_ajax()) {
         add_filter('clean_url', array('WPGlobus_Customize', 'filter__clean_url'), 10, 2);
     }
 }
 /**
  * Constructor
  */
 public function __construct()
 {
     if (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) {
         self::$_SCRIPT_DEBUG = true;
         self::$_SCRIPT_SUFFIX = '';
     }
     $enabled_pages = array('widgets.php', 'customize.php');
     if (WPGlobus_WP::is_pagenow($enabled_pages)) {
         add_filter('mce_buttons', array($this, 'add_buttons'), 1);
         add_filter('mce_external_plugins', array($this, 'mce_external_plugins'), 1);
         add_action('admin_print_scripts', array($this, 'on_admin_scripts'));
         add_action('admin_head', array($this, 'on_admin_head'));
     }
 }
 /**
  * @covers WPGlobus_WP::pagenow
  * @covers WPGlobus_WP::is_pagenow
  */
 public function test_is_pagenow()
 {
     // False because global is not initialized
     self::assertFalse(WPGlobus_WP::is_pagenow('unit-test-page'));
     global $pagenow;
     /** @noinspection OnlyWritesOnParameterInspection */
     $pagenow = 'unit-test-page';
     self::assertTrue(WPGlobus_WP::is_pagenow('unit-test-page'));
     self::assertTrue(WPGlobus_WP::is_pagenow(array('unit-test-page', 'another-page')));
     self::assertTrue(WPGlobus_WP::is_pagenow(array(new stdClass(), 'unit-test-page')));
     self::assertFalse(WPGlobus_WP::is_pagenow('not-unit-test-page'));
     self::assertFalse(WPGlobus_WP::is_pagenow(array('not-unit-test-page', 'another-page')));
     self::assertFalse(WPGlobus_WP::is_pagenow(3.14));
     self::assertFalse(WPGlobus_WP::is_pagenow(new stdClass()));
 }
 /**
  * Get options from DB and wp-config.php
  * @return void
  */
 protected function _get_options()
 {
     /**
      * For developers use only. Re-creates language table with no warning! Irreversible!
      *
      * @link wp-admin/?wpglobus-reset-language-table=1
      */
     if (!defined('DOING_AJAX') && !empty($_GET['wpglobus-reset-language-table']) && is_admin()) {
         delete_option($this->option_language_names);
     }
     $wpglobus_option = get_option($this->option);
     /**
      * FIX: after "Reset All" Redux options we must reset all WPGlobus options
      * first of all look at $wpglobus_option['more_languages']
      */
     if (isset($wpglobus_option['more_languages']) && is_array($wpglobus_option['more_languages'])) {
         $wpglobus_option = array();
         delete_option($this->option);
         delete_option($this->option_language_names);
         delete_option($this->option_en_language_names);
         delete_option($this->option_locale);
         delete_option($this->option_flags);
     }
     if (isset($wpglobus_option['more_languages'])) {
         unset($wpglobus_option['more_languages']);
     }
     /**
      * Get enabled languages and default language ( just one main language )
      */
     if (isset($wpglobus_option['enabled_languages']) && !empty($wpglobus_option['enabled_languages'])) {
         $this->enabled_languages = array();
         foreach ($wpglobus_option['enabled_languages'] as $lang => $value) {
             if (!empty($value)) {
                 $this->enabled_languages[] = $lang;
             }
         }
         /**
          * Set default language
          */
         $this->default_language = $this->enabled_languages[0];
         unset($wpglobus_option['enabled_languages']);
     }
     /**
      * Set available languages for editors
      */
     $this->open_languages = $this->enabled_languages;
     /**
      * Set flags URL
      */
     $this->_set_flags_url();
     /**
      * Get languages name
      * big array of used languages
      */
     $this->language_name = get_option($this->option_language_names);
     if (empty($this->language_name)) {
         $this->_set_languages();
         $this->_init_language_table();
     }
     /**
      * Get locales
      */
     $this->locale = get_option($this->option_locale);
     if (empty($this->locale)) {
         $this->_set_languages();
         $this->_init_language_table();
     }
     /**
      * Get enabled locales
      */
     foreach ($this->enabled_languages as $language) {
         $this->enabled_locale[] = $this->locale[$language];
     }
     /**
      * Get en_language_name
      */
     $this->en_language_name = get_option($this->option_en_language_names);
     /**
      * Get option 'show_flag_name'
      */
     if (isset($wpglobus_option['show_flag_name'])) {
         $this->show_flag_name = $wpglobus_option['show_flag_name'];
         unset($wpglobus_option['show_flag_name']);
     }
     if (defined('WPGLOBUS_SHOW_FLAG_NAME')) {
         if ('name' === WPGLOBUS_SHOW_FLAG_NAME) {
             $this->show_flag_name = 'name';
         } elseif (false === WPGLOBUS_SHOW_FLAG_NAME || '' === WPGLOBUS_SHOW_FLAG_NAME) {
             $this->show_flag_name = '';
         }
     }
     /**
      * Get navigation menu slug for add flag in front-end 'use_nav_menu'
      */
     $this->nav_menu = '';
     if (isset($wpglobus_option['use_nav_menu'])) {
         $this->nav_menu = $wpglobus_option['use_nav_menu'];
         unset($wpglobus_option['use_nav_menu']);
     }
     // This can be used in `wp-config` to override the options settings.
     if (defined('WPGLOBUS_USE_NAV_MENU')) {
         $this->nav_menu = WPGLOBUS_USE_NAV_MENU;
     }
     /**
      * Get selector_wp_list_pages option
      * @since 1.0.7
      */
     if (empty($wpglobus_option['selector_wp_list_pages']['show_selector']) || (int) $wpglobus_option['selector_wp_list_pages']['show_selector'] === 0) {
         $this->selector_wp_list_pages = false;
     }
     if (isset($wpglobus_option['selector_wp_list_pages'])) {
         unset($wpglobus_option['selector_wp_list_pages']);
     }
     /**
      * Get custom CSS
      */
     if (isset($wpglobus_option['css_editor'])) {
         $this->css_editor = $wpglobus_option['css_editor'];
         unset($wpglobus_option['css_editor']);
     }
     /**
      * Get flag files without path
      */
     $option = get_option($this->option_flags);
     if (!empty($option)) {
         $this->flag = $option;
     }
     /**
      * Get versioning info
      */
     $option = get_option(self::$option_versioning);
     if (empty($option)) {
         $this->version = array();
     } else {
         $this->version = $option;
     }
     /**
      * WPGlobus devmode.
      */
     if (isset($_GET['wpglobus']) && 'off' === $_GET['wpglobus']) {
         $this->toggle = 'off';
     } else {
         $this->toggle = 'on';
     }
     /**
      * Need additional check for devmode (toggle=OFF)
      * in case 'wpglobus' was not set to 'off' at /wp-admin/post.php
      * and $_SERVER[QUERY_STRING] is empty at the time of `wp_insert_post_data` action
      * @see WPGlobus::on_save_post_data
      */
     if (empty($_SERVER['QUERY_STRING']) && isset($_SERVER['HTTP_REFERER']) && WPGlobus_WP::is_pagenow('post.php') && false !== strpos($_SERVER['HTTP_REFERER'], 'wpglobus=off')) {
         $this->toggle = 'off';
     }
     if (isset($wpglobus_option['last_tab'])) {
         unset($wpglobus_option['last_tab']);
     }
     /**
      * Remaining wpglobus options after unset() is extended options
      * @since 1.2.3
      */
     $this->extended_options = $wpglobus_option;
 }
 /**
  * Enqueue js for WPSEO support
  * @since 1.0.8
  */
 public static function action__admin_print_scripts()
 {
     if (WPGlobus_WP::is_pagenow(array('post.php', 'post-new.php'))) {
         $handle = 'wpglobus-wpseo';
         /**
          * WP-SEO Version 2.2 introduces breaking changes.
          * A new version of our script will be required.
          */
         /** @noinspection PhpInternalEntityUsedInspection */
         $src_version = version_compare(WPSEO_VERSION, '2.2', '>=') ? '22' : '21';
         $src = WPGlobus::$PLUGIN_DIR_URL . 'includes/js/' . $handle . '-' . $src_version . WPGlobus::SCRIPT_SUFFIX() . '.js';
         wp_enqueue_script($handle, $src, array('jquery'), WPGLOBUS_VERSION, true);
         wp_localize_script($handle, 'WPGlobusVendor', array('version' => WPGLOBUS_VERSION, 'vendor' => WPGlobus::O()->vendors_scripts));
     }
 }
Beispiel #6
0
 * Filter @see the_category
 * @scope admin
 * @since 1.0.3
 * Show default category name in the current language - on the
 * wp-admin/edit-tags.php?taxonomy=category page, below the categories table
 */
if (is_admin() && WPGlobus_WP::is_pagenow('edit-tags.php')) {
    add_filter('the_category', array('WPGlobus_Filters', 'filter__text'), 0);
}
/**
 * Filter @see wp_trim_words
 * @scope admin
 * @since 1.0.14
 * Trims text to a certain number of words in the current language
 */
if (is_admin() && WPGlobus_WP::is_pagenow('index.php')) {
    add_filter('wp_trim_words', array('WPGlobus_Filters', 'filter__wp_trim_words'), 0, 4);
}
/**
 * Basic post/page filters
 * -
 * Note: We don't use 'the_excerpt' filter because 'get_the_excerpt' will be run anyway
 * @see  the_excerpt()
 * @see  get_the_excerpt()
 * @todo look at 'the_excerpt_export' filter where the post excerpt used for WXR exports.
 */
add_filter('the_title', array('WPGlobus_Filters', 'filter__text'), 0);
add_filter('the_content', array('WPGlobus_Filters', 'filter__text'), 0);
add_filter('get_the_excerpt', array('WPGlobus_Filters', 'filter__text'), 0);
/**
 * @see   WPGlobus_Filters::filter__the_posts for the description
 /**
  * Enqueue js for YoastSEO support
  * @since 1.4.0
  */
 public static function action__admin_print_scripts()
 {
     if ('off' === WPGlobus::Config()->toggle) {
         return;
     }
     /** @global string $pagenow */
     global $pagenow;
     $enabled_pages = array('post.php', 'post-new.php', 'edit-tags.php', 'term.php');
     if (WPGlobus_WP::is_pagenow($enabled_pages)) {
         WPGlobus::O()->vendors_scripts['WPSEO'] = true;
         $yoastseo_plus_access = sprintf(__('Please see %s to get access to page analysis with YoastSEO.', ''), '<a href="http://www.wpglobus.com/product/wpglobus-plus/#yoastseo" target="_blank">WPGlobus Plus</a>');
         $i18n = array('yoastseo_plus_access' => $yoastseo_plus_access);
         $handle = 'wpglobus-yoastseo';
         /** @noinspection PhpInternalEntityUsedInspection */
         $src_version = version_compare(WPSEO_VERSION, '3.1', '>=') ? '31' : '30';
         /** @noinspection PhpInternalEntityUsedInspection */
         $src_version = version_compare(WPSEO_VERSION, '3.2', '>=') ? '32' : $src_version;
         /** @noinspection PhpInternalEntityUsedInspection */
         $src_version = version_compare(WPSEO_VERSION, '3.3', '>=') ? '33' : $src_version;
         $src = WPGlobus::$PLUGIN_DIR_URL . 'includes/js/' . $handle . '-' . $src_version . WPGlobus::SCRIPT_SUFFIX() . '.js';
         wp_enqueue_script($handle, $src, array('jquery', 'underscore'), WPGLOBUS_VERSION, true);
         wp_localize_script($handle, 'WPGlobusVendor', array('version' => WPGLOBUS_VERSION, 'vendor' => WPGlobus::O()->vendors_scripts, 'pagenow' => $pagenow, 'i18n' => $i18n));
     }
 }
 /**
  * Localize home_url
  * Should be processed on:
  * - front
  * - AJAX, except for several specific actions
  *
  * @param string $url
  *
  * @return string
  */
 public static function filter__home_url($url)
 {
     /**
      * @internal note
      * Example of URL in admin:
      * When admin interface is not in default language, we still should not see
      * any permalinks with language prefixes.
      * For that, we could check if we are at the 'post.php' screen:
      * if ( 'post.php' == $pagenow ) ....
      * However, we do not need it, because we disallowed almost any processing in admin.
      */
     /**
      * 1. Do not work in admin
      */
     $need_to_process = !is_admin();
     if (WPGlobus_WP::is_pagenow('admin-ajax.php')) {
         /**
          * 2. But work in AJAX, which is also admin
          */
         $need_to_process = true;
         /**
          * 3. However, don't convert url for these AJAX actions:
          */
         if (WPGlobus_WP::is_http_post_action(array('heartbeat', 'sample-permalink', 'add-menu-item'))) {
             $need_to_process = false;
         }
     }
     if ($need_to_process) {
         $url = WPGlobus_Utils::localize_url($url);
     }
     return $url;
 }
 /**
  * Enable `themes.php` page to load our scripts and styles
  *
  * @param array $pages List of pages already enabled
  *
  * @return array Modified list of pages
  */
 public function enable_page($pages)
 {
     if (empty($this->config_dir_file)) {
         return $pages;
     }
     if (!empty($_GET['page']) && WPGlobus_WP::is_pagenow('themes.php')) {
         $pages[] = 'themes.php';
     }
     return $pages;
 }
Beispiel #10
0
    /**
     * Make correct Site Title in admin bar.
     * Make template for Site Title (option blogname)
     * a Tagline (option blogdescription) at options-general.php page.
     * @return void
     */
    public function on_admin_footer()
    {
        $blogname = get_option('blogname');
        $bn = WPGlobus_Core::text_filter($blogname, WPGlobus::Config()->language, WPGlobus::RETURN_IN_DEFAULT_LANGUAGE);
        ?>
		<script type='text/javascript'>
			/* <![CDATA[ */
			jQuery('#wp-admin-bar-site-name a').eq(0).text("<?php 
        echo $bn;
        ?>
");
			/* ]]> */
		</script>
		<?php 
        /**
         * For dialog form
         * @since 1.2.0
         */
        /** @global string $pagenow */
        global $pagenow;
        $page = empty($_GET['page']) ? '' : $_GET['page'];
        // @todo remove after testing
        //if ( WPGlobus_WP::is_pagenow( array( 'post.php', 'widgets.php' ) ) ) {
        if (in_array($pagenow, $this->enabled_pages) || in_array($page, $this->enabled_pages)) {
            /**
             * Output dialog form for window.WPGlobusDialogApp
             */
            ?>
			<div id="wpglobus-dialog-wrapper" class="hidden wpglobus-dialog-wrapper">
				<form id="wpglobus-dialog-form">
					<div id="wpglobus-dialog-tabs" class="wpglobus-dialog-tabs">
						<ul class="wpglobus-dialog-tabs-list">    <?php 
            $order = 0;
            foreach (WPGlobus::Config()->open_languages as $language) {
                ?>
								<li id="dialog-link-tab-<?php 
                echo $language;
                ?>
"
								    data-language="<?php 
                echo $language;
                ?>
"
								    data-order="<?php 
                echo $order;
                ?>
"
								    class="wpglobus-dialog-tab"><a
										href="#dialog-tab-<?php 
                echo $language;
                ?>
"><?php 
                echo WPGlobus::Config()->en_language_name[$language];
                ?>
</a>
								</li> <?php 
                $order++;
            }
            ?>
						</ul> <?php 
            foreach (WPGlobus::Config()->open_languages as $language) {
                ?>
							<div id="dialog-tab-<?php 
                echo $language;
                ?>
" class="wpglobus-dialog-general">
								<textarea name="wpglobus-dialog-<?php 
                echo $language;
                ?>
"
								          id="wpglobus-dialog-<?php 
                echo $language;
                ?>
"
								          class="wpglobus_dialog_textarea textarea"
								          data-language="<?php 
                echo $language;
                ?>
"
								          data-order="save_dialog"></textarea>
							</div> <?php 
            }
            ?>
					</div>
				</form>
			</div>        <?php 
        }
        if (!WPGlobus_WP::is_pagenow('options-general.php')) {
            return;
        }
        $blogdesc = get_option('blogdescription');
        ?>
		<div id="wpglobus-blogname" class="hidden">        <?php 
        foreach (self::Config()->enabled_languages as $language) {
            $return = $language == self::Config()->default_language ? WPGlobus::RETURN_IN_DEFAULT_LANGUAGE : WPGlobus::RETURN_EMPTY;
            ?>

				<input type="text" class="regular-text wpglobus-blogname wpglobus-translatable"
				       value="<?php 
            echo WPGlobus_Core::text_filter($blogname, $language, $return);
            ?>
"
				       id="blogname-<?php 
            echo $language;
            ?>
" name="blogname-<?php 
            echo $language;
            ?>
"
				       data-language="<?php 
            echo $language;
            ?>
"
				       placeholder="<?php 
            echo self::Config()->en_language_name[$language];
            ?>
"><br />

				<?php 
        }
        ?>
		</div>

		<div id="wpglobus-blogdescription" class="hidden">        <?php 
        foreach (self::Config()->enabled_languages as $language) {
            $return = $language == self::Config()->default_language ? WPGlobus::RETURN_IN_DEFAULT_LANGUAGE : WPGlobus::RETURN_EMPTY;
            ?>

				<input type="text" class="regular-text wpglobus-blogdesc wpglobus-translatable"
				       value="<?php 
            echo WPGlobus_Core::text_filter($blogdesc, $language, $return);
            ?>
"
				       id="blogdescription-<?php 
            echo $language;
            ?>
" name="blogdescription-<?php 
            echo $language;
            ?>
"
				       data-language="<?php 
            echo $language;
            ?>
"
				       placeholder="<?php 
            echo self::Config()->en_language_name[$language];
            ?>
"><br />

				<?php 
        }
        ?>
		</div>
		<?php 
    }
        /**
         * Displays an inactive notice when the software is inactive.
         */
        public function notice_license_inactive()
        {
            // Show notice to admins only and only on the "Plugins" page.
            if (!(current_user_can('manage_options') && WPGlobus_WP::is_pagenow('plugins.php'))) {
                return;
            }
            ?>
			<div class="notice <?php 
            echo WPGlobus_WP::ADMIN_NOTICE_WARNING;
            ?>
">
				<p>
					<strong><?php 
            echo esc_html($this->ame_software_product_id);
            ?>
: </strong>
					<?php 
            esc_html_e('License has not been activated.', 'wpglobus');
            echo ' ';
            echo '<a href="' . esc_url(admin_url('index.php?page=' . $this->ame_activation_tab_key)) . '">';
            esc_html_e('Click here to enter the license key and get the updates.', 'wpglobus');
            echo '</a>';
            ?>
				</p>
			</div>
			<?php 
        }