/** * Add language translations to update_plugins or update_themes transients. * * @param $transient * * @return mixed */ public function pre_set_site_transient($transient) { $locales = get_available_languages(); $locales = !empty($locales) ? $locales : array(get_locale()); $repos = array(); if (!isset($transient->translations)) { return $transient; } if ('pre_set_site_transient_update_plugins' === current_filter()) { $repos = Plugin::instance()->get_plugin_configs(); $translations = wp_get_installed_translations('plugins'); } if ('pre_set_site_transient_update_themes' === current_filter()) { $repos = Theme::instance()->get_theme_configs(); $translations = wp_get_installed_translations('themes'); } $repos = array_filter($repos, function ($e) { return isset($e->language_packs); }); foreach ($repos as $repo) { foreach ($locales as $locale) { $lang_pack_mod = isset($repo->language_packs->{$locale}) ? strtotime($repo->language_packs->{$locale}->updated) : 0; $translation_mod = isset($translations[$repo->repo][$locale]) ? strtotime($translations[$repo->repo][$locale]['PO-Revision-Date']) : 0; if ($lang_pack_mod > $translation_mod) { $transient->translations[] = (array) $repo->language_packs->{$locale}; } } } $transient->translations = array_unique($transient->translations, SORT_REGULAR); return $transient; }
protected function getLanguageMutation() { $i84676540daef1510ea5729a183290848a9e7accb = 0; $i05355412b857f5174e9a2f71b1e936a86ad60cd22621e8ed49bfcd8c8447959e1a834cd7df379456 = $i05355412b857f5174e9a2f71b1e936a86ad60cd20469dd29d7fc00508902b5648b5460a24be01900 = array(); if (file_exists(ABSPATH . 'wp-admin/includes/translation-install.php')) { require_once ABSPATH . 'wp-admin/includes/translation-install.php'; $i05355412b857f5174e9a2f71b1e936a86ad60cd22621e8ed49bfcd8c8447959e1a834cd7df379456 = get_available_languages(); $i05355412b857f5174e9a2f71b1e936a86ad60cd20469dd29d7fc00508902b5648b5460a24be01900 = wp_get_available_translations(); } if (isset($i05355412b857f5174e9a2f71b1e936a86ad60cd20469dd29d7fc00508902b5648b5460a24be01900[SMS_DEFAULT_MUTATION]) && isset($i05355412b857f5174e9a2f71b1e936a86ad60cd20469dd29d7fc00508902b5648b5460a24be01900[SMS_DEFAULT_MUTATION]["native_name"])) { $iced8cbcfca3c880f0f157e119d1cc6f8691e7e89 = array(SMS_DEFAULT_MUTATION => $i05355412b857f5174e9a2f71b1e936a86ad60cd20469dd29d7fc00508902b5648b5460a24be01900[SMS_DEFAULT_MUTATION]["native_name"], "en_US" => "English (United States)"); $this->mutationColors[SMS_DEFAULT_MUTATION] = $i84676540daef1510ea5729a183290848a9e7accb++ % count(self::$colors); $this->mutationColors["en_US"] = $i84676540daef1510ea5729a183290848a9e7accb++ % count(self::$colors); } else { $iced8cbcfca3c880f0f157e119d1cc6f8691e7e89 = array("en_US" => "English (United States)"); $this->mutationColors["en_US"] = $i84676540daef1510ea5729a183290848a9e7accb++ % count(self::$colors); } foreach ($i05355412b857f5174e9a2f71b1e936a86ad60cd22621e8ed49bfcd8c8447959e1a834cd7df379456 as $i05355412b857f5174e9a2f71b1e936a86ad60cd2572358132e4515581ad210b23e0ca988f93e9772) { if ($i05355412b857f5174e9a2f71b1e936a86ad60cd2572358132e4515581ad210b23e0ca988f93e9772 != SMS_DEFAULT_MUTATION) { $this->mutationColors[$i05355412b857f5174e9a2f71b1e936a86ad60cd2572358132e4515581ad210b23e0ca988f93e9772] = $i84676540daef1510ea5729a183290848a9e7accb++ % count(self::$colors); if (isset($i05355412b857f5174e9a2f71b1e936a86ad60cd20469dd29d7fc00508902b5648b5460a24be01900[$i05355412b857f5174e9a2f71b1e936a86ad60cd2572358132e4515581ad210b23e0ca988f93e9772]) && isset($i05355412b857f5174e9a2f71b1e936a86ad60cd20469dd29d7fc00508902b5648b5460a24be01900[$i05355412b857f5174e9a2f71b1e936a86ad60cd2572358132e4515581ad210b23e0ca988f93e9772]["native_name"])) { $iced8cbcfca3c880f0f157e119d1cc6f8691e7e89[$i05355412b857f5174e9a2f71b1e936a86ad60cd2572358132e4515581ad210b23e0ca988f93e9772] = $i05355412b857f5174e9a2f71b1e936a86ad60cd20469dd29d7fc00508902b5648b5460a24be01900[$i05355412b857f5174e9a2f71b1e936a86ad60cd2572358132e4515581ad210b23e0ca988f93e9772]["native_name"]; } } } return $iced8cbcfca3c880f0f157e119d1cc6f8691e7e89; }
/** * Render the language metabox for user profile screen * * @since 0.1.0 * * @param WP_User $user The WP_User object to be edited. */ function wp_user_profiles_language_metabox($user = null) { // Defaults $languages = get_available_languages(); $user_locale = $user->locale; $fallback = get_locale(); // Already en_US if ('en_US' === $user->locale) { $user_locale = false; // Language not available } elseif (!in_array($user->locale, $languages, true)) { $user_locale = $fallback; } ?> <table class="form-table"> <tr class="user-language-wrap"> <th scope="row"> <label for="locale"><?php esc_html_e('Language', 'wp-user-profiles'); ?> </label> </th> <td><?php // Drop it down wp_dropdown_languages(array('name' => 'locale', 'id' => 'locale', 'selected' => $user_locale, 'languages' => $languages, 'show_available_translations' => false)); ?> </td> </tr> </table> <?php }
function mlang_languages() { $languages = get_available_languages(); if (!in_array('en', $languages)) { array_unshift($languages, 'en'); } return $languages; }
/** * * @return array; */ public function getPicklistOptions() { $languages = get_available_languages(); foreach ($languages as $language) { $options[$language] = $language; } return $options; }
/** * @ticket 35950 */ function test_get_available_languages() { $array = get_available_languages(); $this->assertInternalType('array', $array); $array = get_available_languages('.'); $this->assertEmpty($array); $array = get_available_languages(DIR_TESTDATA . '/languages/'); $this->assertEquals(array('en_GB', 'es_ES'), $array); }
/** * Returns the markup for the user setting. * * @since 3.0.0 * * @param WP_User $user User object. * * @return string The markup for the user setting. */ public function markup(WP_User $user) { $languages = get_available_languages(); if (!$languages) { return esc_html__('No languages available.', 'multilingual-press'); } // Add English manually, because it won't get added by WordPress itself. $languages[] = 'en_US'; return sprintf('<select name="%2$s" id="%2$s" autocomplete="off">%1$s</select>%3$s', $this->get_language_options($languages, $this->language_repository->get_user_language($user->ID)), esc_attr($this->meta_key), \Inpsyde\MultilingualPress\nonce_field($this->nonce)); }
function languages_options() { // Initialization global $locale; $return = array(is_eng_array('Detect', 'language', ' - ') => 'Detect'); $languages = get_available_languages(); $languages_list = languages_list(); $languages_self_list = languages_self_list(); $is_en = substr($locale, 0, 2) == 'en'; foreach ($languages as $language) { $return[] = array(isset($languages_self_list[$language]) ? $languages_self_list[$language] : $languages_list[$language] => array((isset($languages_list[$language]) ? $languages_list[$language] : $language) . ($is_en ? '' : ' - ' . $language) => $language)); } if (!in_array('en', $languages) && !in_array('en_US', $languages) && !in_array('en_GB', $languages)) { $return[] = array('English' => array(is_eng_array('English', 'language', ' - ') => 'en_US')); } return $return; }
function bogo_available_locales($args = '') { $defaults = array('exclude' => array(), 'current_user_can_access' => false); $args = wp_parse_args($args, $defaults); $installed_locales = get_available_languages(); $installed_locales[] = bogo_get_default_locale(); $installed_locales[] = 'en_US'; $installed_locales = array_unique($installed_locales); $installed_locales = array_filter($installed_locales); $available_locales = array(); foreach ($installed_locales as $locale) { if (in_array($locale, (array) $args['exclude'])) { continue; } if ($args['current_user_can_access'] && !current_user_can('bogo_access_locale', $locale)) { continue; } $available_locales[] = $locale; } return $available_locales; }
public static function existing($all = false, $translate = false) { if (empty(self::$items)) { $languages = array(); $langs = get_available_languages(); if (!in_array(get_locale(), $langs)) { $langs[] = get_locale(); } $i = 0; foreach ($langs as $lang) { $languages[$i] = new stdClass(); $languages[$i]->value = $lang; $languages[$i]->text = $lang; $i++; } self::$items = $languages; if ($all) { array_unshift(self::$items, new MObject(array('value' => '*', 'text' => $translate ? MText::alt('MALL', 'language') : 'MALL_LANGUAGE'))); } } return self::$items; }
public static function getLanguages($key = 'default') { static $languages; if (empty($languages)) { // Installation uses available languages if (MFactory::getApplication()->getClientId() == 2) { $languages[$key] = array(); $knownLangs = MLanguage::getKnownLanguages(MPATH_BASE); foreach ($knownLangs as $metadata) { // Take off 3 letters iso code languages as they can't match browsers' languages and default them to en $languages[$key][] = new MObject(array('lang_code' => $metadata['tag'])); } } else { $cache = MFactory::getCache('com_languages', ''); if (!($languages = $cache->get('languages'))) { $langs = get_available_languages(); $i = 0; $lngs = array(); foreach ($langs as $lang) { $lngs[$i] = new stdClass(); $lngs[$i]->title = $lang; $i++; } $languages['default'] = $lngs; $languages['lang_code'] = array(); if (isset($languages['default'][0])) { foreach ($languages['default'] as $lang) { $languages['lang_code'][$lang->title] = $lang; } } $cache->store($languages, 'languages'); } } } return $languages[$key]; }
function vp_register_hooks() { global $wpdb, $versionPressContainer; /** @var Committer $committer */ $committer = $versionPressContainer->resolve(VersionPressServices::COMMITTER); /** @var Mirror $mirror */ $mirror = $versionPressContainer->resolve(VersionPressServices::MIRROR); /** @var DbSchemaInfo $dbSchemaInfo */ $dbSchemaInfo = $versionPressContainer->resolve(VersionPressServices::DB_SCHEMA); /** @var VpidRepository $vpidRepository */ $vpidRepository = $versionPressContainer->resolve(VersionPressServices::VPID_REPOSITORY); /** @var WpdbMirrorBridge $wpdbMirrorBridge */ $wpdbMirrorBridge = $versionPressContainer->resolve(VersionPressServices::WPDB_MIRROR_BRIDGE); /** * Hook for saving taxonomies into files * WordPress creates plain INSERT query and executes it using wpdb::query method instead of wpdb::insert. * It's too difficult to parse every INSERT query, that's why the WordPress hook is used. */ add_action('save_post', createUpdatePostTermsHook($mirror, $vpidRepository)); add_filter('update_feedback', function () { touch(ABSPATH . 'versionpress.maintenance'); }); add_action('_core_updated_successfully', function () use($committer, $mirror) { require ABSPATH . 'wp-includes/version.php'; // load constants (like $wp_version) /** @var string $wp_version */ $changeInfo = new WordPressUpdateChangeInfo($wp_version); $committer->forceChangeInfo($changeInfo); $mirror->save('option', array('option_name' => 'db_version', 'option_value' => get_option('db_version'))); // We have to re-save the option because WP upgrader uses $wpdb->query() if (!WpdbReplacer::isReplaced()) { WpdbReplacer::replaceMethods(); } }); add_action('activated_plugin', function ($pluginName) use($committer) { $committer->forceChangeInfo(new PluginChangeInfo($pluginName, 'activate')); }); add_action('deactivated_plugin', function ($pluginName) use($committer) { $committer->forceChangeInfo(new PluginChangeInfo($pluginName, 'deactivate')); }); add_action('upgrader_process_complete', function ($upgrader, $hook_extra) use($committer) { if ($hook_extra['type'] === 'theme') { $themes = isset($hook_extra['bulk']) && $hook_extra['bulk'] === true ? $hook_extra['themes'] : array($upgrader->result['destination_name']); foreach ($themes as $theme) { $themeName = wp_get_theme($theme)->get('Name'); if ($themeName === $theme && isset($upgrader->skin->api, $upgrader->skin->api->name)) { $themeName = $upgrader->skin->api->name; } $action = $hook_extra['action']; // can be "install" or "update", see WP_Upgrader and search for `'hook_extra' =>` $committer->forceChangeInfo(new ThemeChangeInfo($theme, $action, $themeName)); } } if (!($hook_extra['type'] === 'plugin' && $hook_extra['action'] === 'update')) { return; } // handled by different hook if (isset($hook_extra['bulk']) && $hook_extra['bulk'] === true) { $plugins = $hook_extra['plugins']; } else { $plugins = array($hook_extra['plugin']); } foreach ($plugins as $plugin) { $committer->forceChangeInfo(new PluginChangeInfo($plugin, 'update')); } }, 10, 2); add_action('added_option', function ($name) use($wpdb, $mirror) { $option = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}options WHERE option_name='{$name}'", ARRAY_A); $mirror->save("option", $option); }); add_filter('upgrader_pre_install', function ($_, $hook_extra) use($committer) { if (!(isset($hook_extra['type']) && $hook_extra['type'] === 'plugin' && $hook_extra['action'] === 'install')) { return; } $pluginsBeforeInstallation = get_plugins(); $postInstallHook = function ($_, $hook_extra) use($pluginsBeforeInstallation, $committer, &$postInstallHook) { if (!($hook_extra['type'] === 'plugin' && $hook_extra['action'] === 'install')) { return; } wp_cache_delete('plugins', 'plugins'); $pluginsAfterInstallation = get_plugins(); $installedPlugin = array_diff_key($pluginsAfterInstallation, $pluginsBeforeInstallation); reset($installedPlugin); $pluginName = key($installedPlugin); $committer->forceChangeInfo(new PluginChangeInfo($pluginName, 'install')); remove_filter('upgrader_post_install', $postInstallHook); }; add_filter('upgrader_post_install', $postInstallHook, 10, 2); }, 10, 2); add_filter('upgrader_pre_download', function ($reply, $_, $upgrader) use($committer) { if (!isset($upgrader->skin->language_update)) { return $reply; } $languages = get_available_languages(); $postInstallHook = function ($_, $hook_extra) use($committer, $languages, &$postInstallHook) { if (!isset($hook_extra['language_update_type'])) { return; } $translations = wp_get_available_translations(); $type = $hook_extra['language_update_type']; $languageCode = $hook_extra['language_update']->language; $languageName = isset($translations[$languageCode]) ? $translations[$languageCode]['native_name'] : 'English (United States)'; $name = $type === "core" ? null : $hook_extra['language_update']->slug; $action = in_array($languageCode, $languages) ? "update" : "install"; $committer->forceChangeInfo(new TranslationChangeInfo($action, $languageCode, $languageName, $type, $name)); remove_filter('upgrader_post_install', $postInstallHook); }; add_filter('upgrader_post_install', $postInstallHook, 10, 2); return false; }, 10, 3); add_action('switch_theme', function () use($committer) { if (defined('WP_CLI') && WP_CLI) { file_get_contents(admin_url()); // } else { $committer->disableCommit(); // the change will be committed on next load } }); add_action('after_switch_theme', function () use($committer) { $theme = wp_get_theme(); $stylesheet = $theme->get_stylesheet(); $themeName = $theme->get('Name'); $committer->forceChangeInfo(new ThemeChangeInfo($stylesheet, 'switch', $themeName)); }); add_action('customize_save_after', function ($customizeManager) use($committer) { /** @var WP_Customize_Manager $customizeManager */ $stylesheet = $customizeManager->theme()->get_stylesheet(); $committer->forceChangeInfo(new ThemeChangeInfo($stylesheet, 'customize')); register_shutdown_function(function () { wp_remote_get(admin_url("admin.php")); }); }); add_action('untrashed_post_comments', function ($postId) use($wpdb, $dbSchemaInfo, $wpdbMirrorBridge) { $commentsTable = $dbSchemaInfo->getPrefixedTableName("comment"); $commentStatusSql = "select comment_ID, comment_approved from {$commentsTable} where comment_post_ID = {$postId}"; $comments = $wpdb->get_results($commentStatusSql, ARRAY_A); foreach ($comments as $comment) { $wpdbMirrorBridge->update($commentsTable, array("comment_approved" => $comment["comment_approved"]), array("comment_ID" => $comment["comment_ID"])); } }); add_action('delete_post_meta', function ($metaIds) use($wpdbMirrorBridge, $dbSchemaInfo) { $idColumnName = $dbSchemaInfo->getEntityInfo("postmeta")->idColumnName; foreach ($metaIds as $metaId) { $wpdbMirrorBridge->delete($dbSchemaInfo->getPrefixedTableName("postmeta"), array($idColumnName => $metaId)); } }); add_action('delete_user_meta', function ($metaIds) use($wpdbMirrorBridge, $dbSchemaInfo) { $idColumnName = $dbSchemaInfo->getEntityInfo("usermeta")->idColumnName; foreach ($metaIds as $metaId) { $wpdbMirrorBridge->delete($dbSchemaInfo->getPrefixedTableName("usermeta"), array($idColumnName => $metaId)); } }); add_action('wp_ajax_save-widget', function () use($committer) { if (defined('DOING_AJAX') && DOING_AJAX && isset($_POST['delete_widget']) && $_POST['delete_widget']) { $committer->postponeCommit('widgets'); } }, 0); // zero because the default WP action with priority 1 calls wp_die() function _vp_get_language_name_by_code($code) { $translations = wp_get_available_translations(); return isset($translations[$code]) ? $translations[$code]['native_name'] : 'English (United States)'; } add_action('add_option_WPLANG', function ($option, $value) use($committer) { $defaultLanguage = defined('WPLANG') ? WPLANG : ''; if ($value === $defaultLanguage) { return; // It's just submitted settings form without changing language } $languageName = _vp_get_language_name_by_code($value); $committer->forceChangeInfo(new TranslationChangeInfo("activate", $value, $languageName)); }, 10, 2); add_action('update_option_WPLANG', function ($oldValue, $newValue) use($committer) { $languageName = _vp_get_language_name_by_code($newValue); $committer->forceChangeInfo(new TranslationChangeInfo("activate", $newValue, $languageName)); }, 10, 2); add_action('wp_update_nav_menu_item', function ($menu_id, $menu_item_db_id) use($committer) { $key = 'menu-item-' . $menu_item_db_id; if (defined('DOING_AJAX') && DOING_AJAX && isset($_POST['action']) && $_POST['action'] === 'add-menu-item') { $committer->postponeCommit($key); $committer->commit(); } elseif (isset($_POST['action']) && $_POST['action'] === 'update') { $committer->usePostponedChangeInfos($key); } if (!defined('DOING_AJAX')) { global $versionPressContainer; /** @var Mirror $mirror */ $mirror = $versionPressContainer->resolve(VersionPressServices::MIRROR); $vpidRepository = $versionPressContainer->resolve(VersionPressServices::VPID_REPOSITORY); $func = createUpdatePostTermsHook($mirror, $vpidRepository); $func($menu_item_db_id); } }, 10, 2); add_action('pre_delete_term', function ($termId, $taxonomy) use($committer, $vpidRepository) { $termVpid = $vpidRepository->getVpidForEntity('term', $termId); $term = get_term($termId, $taxonomy); $committer->forceChangeInfo(new \VersionPress\ChangeInfos\TermChangeInfo('delete', $termVpid, $term->name, $taxonomy)); }, 10, 2); add_action('set_object_terms', createUpdatePostTermsHook($mirror, $vpidRepository)); add_filter('plugin_install_action_links', function ($links, $plugin) { $compatibility = CompatibilityChecker::testCompatibilityBySlug($plugin['slug']); if ($compatibility === CompatibilityResult::COMPATIBLE) { $cssClass = 'vp-compatible'; $compatibilityAdjective = 'Compatible'; } elseif ($compatibility === CompatibilityResult::INCOMPATIBLE) { $cssClass = 'vp-incompatible'; $compatibilityAdjective = '<a href="http://docs.versionpress.net/en/integrations/plugins" target="_blank" title="This plugin is not compatible with VersionPress. These plugins will not work correctly when used together.">Incompatible</a>'; } else { $cssClass = 'vp-untested'; $compatibilityAdjective = '<a href="http://docs.versionpress.net/en/integrations/plugins" target="_blank" title="This plugin was not yet tested with VersionPress. Some functionality may not work as intended.">Untested</a>'; } $compatibilityNotice = '<span class="vp-compatibility %s" data-plugin-name="%s"><strong>%s</strong> with VersionPress</span>'; $links[] = sprintf($compatibilityNotice, $cssClass, $plugin['name'], $compatibilityAdjective); return $links; }, 10, 2); add_filter('plugin_row_meta', function ($plugin_meta, $plugin_file, $plugin_data, $status) { if ($status === "dropins") { return $plugin_meta; } $compatibility = CompatibilityChecker::testCompatibilityByPluginFile($plugin_file); if ($compatibility === CompatibilityResult::COMPATIBLE) { $cssClass = 'vp-compatible'; $compatibilityAdjective = 'Compatible'; } elseif ($compatibility === CompatibilityResult::INCOMPATIBLE) { $cssClass = 'vp-incompatible'; $compatibilityAdjective = '<a href="http://docs.versionpress.net/en/integrations/plugins" target="_blank" title="This plugin is not compatible with VersionPress. These plugins will not work correctly when used together.">Incompatible</a>'; } elseif ($compatibility === CompatibilityResult::UNTESTED) { $cssClass = 'vp-untested'; $compatibilityAdjective = '<a href="http://docs.versionpress.net/en/integrations/plugins" target="_blank" title="This plugin was not yet tested with VersionPress. Some functionality may not work as intended.">Untested</a>'; } else { return $plugin_meta; } $compatibilityNotice = '<span class="vp-compatibility %s" data-plugin-name="%s"><strong>%s</strong> with VersionPress</span>'; $plugin_meta[] = sprintf($compatibilityNotice, $cssClass, $plugin_data['Name'], $compatibilityAdjective); return $plugin_meta; }, 10, 4); add_filter('plugin_action_links', function ($actions, $plugin_file) { $compatibility = CompatibilityChecker::testCompatibilityByPluginFile($plugin_file); if (isset($actions['activate'])) { if ($compatibility === CompatibilityResult::UNTESTED) { $actions['activate'] = "<span class=\"vp-plugin-list vp-untested\">{$actions['activate']}</span>"; } elseif ($compatibility === CompatibilityResult::INCOMPATIBLE) { $actions['activate'] = "<span class=\"vp-plugin-list vp-incompatible\">{$actions['activate']}</span>"; } } return $actions; }, 10, 2); add_action('vp_revert', function () { // We have to flush the rewrite rules in the next request, because // in the current one the changed rewrite rules are not yet effective. set_transient('vp_flush_rewrite_rules', 1); vp_flush_regenerable_options(); }); add_action('pre_delete_term', function ($term, $taxonomy) use($wpdb, $wpdbMirrorBridge) { if (!is_taxonomy_hierarchical($taxonomy)) { return; } $term = get_term($term, $taxonomy); if (is_wp_error($term)) { return; } $wpdbMirrorBridge->update($wpdb->term_taxonomy, array('parent' => $term->parent), array('parent' => $term->term_id)); }, 10, 2); add_action('before_delete_post', function ($postId) use($wpdb) { // Fixing bug in WP (#34803) and WP-CLI (#2246) $post = get_post($postId); if (!is_wp_error($post) && $post->post_type === 'nav_menu_item') { \Tracy\Debugger::log('Deleting menu item ' . $post->ID); $newParent = get_post_meta($post->ID, '_menu_item_menu_item_parent', true); $wpdb->update($wpdb->postmeta, array('meta_value' => $newParent), array('meta_key' => '_menu_item_menu_item_parent', 'meta_value' => $post->ID)); } }); //---------------------------------------- // URL and WP-CLI "hooks" //---------------------------------------- $requestDetector = new \VersionPress\Utils\RequestDetector(); if (defined('DOING_AJAX') && DOING_AJAX && isset($_REQUEST['action']) && $_REQUEST['action'] === 'widgets-order') { $committer->usePostponedChangeInfos('widgets'); } if ($requestDetector->isThemeDeleteRequest()) { $themeIds = $requestDetector->getThemeStylesheets(); foreach ($themeIds as $themeId) { $committer->forceChangeInfo(new ThemeChangeInfo($themeId, 'delete')); } } if ($requestDetector->isPluginDeleteRequest()) { $plugins = $requestDetector->getPluginNames(); foreach ($plugins as $plugin) { $committer->forceChangeInfo(new PluginChangeInfo($plugin, 'delete')); } } if ($requestDetector->isCoreLanguageUninstallRequest()) { $languageCode = $requestDetector->getLanguageCode(); $translations = wp_get_available_translations(); $languageName = isset($translations[$languageCode]) ? $translations[$languageCode]['native_name'] : 'English (United States)'; $committer->forceChangeInfo(new TranslationChangeInfo('uninstall', $languageCode, $languageName, 'core')); } if (basename($_SERVER['PHP_SELF']) === 'theme-editor.php' && isset($_GET['updated']) && $_GET['updated'] === 'true') { $committer->forceChangeInfo(new ThemeChangeInfo($_GET['theme'], 'edit')); } if (basename($_SERVER['PHP_SELF']) === 'plugin-editor.php' && (isset($_POST['action']) && $_POST['action'] === 'update' || isset($_GET['liveupdate']))) { $committer->disableCommit(); } if (basename($_SERVER['PHP_SELF']) === 'plugin-editor.php' && isset($_GET['a']) && $_GET['a'] === 'te') { if (!function_exists('get_plugins')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $editedFile = $_GET['file']; $editedFilePathParts = preg_split("~[/\\\\]~", $editedFile); $plugins = array_keys(get_plugins()); $bestRank = 0; $bestMatch = ""; foreach ($plugins as $plugin) { $rank = 0; $pluginPathParts = preg_split("~[/\\\\]~", $plugin); $maxEqualParts = min(count($editedFilePathParts), count($pluginPathParts)); for ($part = 0; $part < $maxEqualParts; $part++) { if ($editedFilePathParts[$part] !== $pluginPathParts[$part]) { break; } $rank += 1; } if ($rank > $bestRank) { $bestRank = $rank; $bestMatch = $plugin; } } $committer->forceChangeInfo(new PluginChangeInfo($bestMatch, 'edit')); } register_shutdown_function(array($committer, 'commit')); }
/** * change language : if language file not exist return false * if language file not in THEME_LANGUAGE_PATH copy it from DEFAULT_LANG to THEME_LANGUAGE_PATH * @since 1.0 */ function change_language() { $lang = $_REQUEST['lang_name']; if (!in_array($lang, $this->get_language_list())) { wp_send_json(array('success' => false)); } if (!in_array($lang, get_available_languages(THEME_LANGUAGE_PATH))) { $mo = new MO(); $mo->set_header('Project-Id-Version', THEME_NAME . 'v' . ET_VERSION); $mo->set_header('Report-Msgid-Bugs-To', ET_URL); $mo->set_header('MO-Creation-Date', gmdate('Y-m-d H:i:s+00:00')); $mo->set_header('MIME-Version', '1.0'); $mo->set_header('Content-Type', 'text/plain; charset=UTF-8'); $mo->set_header('Content-Transfer-Encoding', '8bit'); $mo->set_header('MO-Revision-Date', '2010-MO-DA HO:MI+ZONE'); $mo->set_header('Last-Translator', 'JOB <EMAIL@ADDRESS>'); $mo->set_header('Language-Team', 'ENGINETHEMES.COM <*****@*****.**>'); $mo->import_from_file(DEFAULT_LANGUAGE_PATH . '/' . $lang . '.mo'); $mo->export_to_file(THEME_LANGUAGE_PATH . '/' . $lang . '.mo'); } $this->set_site_language($lang); wp_send_json(array('success' => true, 'data' => array('ID' => $lang, 'lang_name' => $lang))); }
public function translation_updates($locales) { $languages = get_available_languages(); return array_values($languages); }
/** * Check theme versions against the latest versions hosted on WordPress.org. * * A list of all themes installed in sent to WP. Checks against the * WordPress server at api.wordpress.org. Will only check if WordPress isn't * installing. * * @since 2.7.0 * * @param array $extra_stats Extra statistics to report to the WordPress.org API. */ function wp_update_themes($extra_stats = array()) { if (wp_installing()) { return; } // include an unmodified $wp_version include ABSPATH . WPINC . '/version.php'; $installed_themes = wp_get_themes(); $translations = wp_get_installed_translations('themes'); $last_update = get_site_transient('update_themes'); if (!is_object($last_update)) { $last_update = new stdClass(); } $themes = $checked = $request = array(); // Put slug of current theme into request. $request['active'] = get_option('stylesheet'); foreach ($installed_themes as $theme) { $checked[$theme->get_stylesheet()] = $theme->get('Version'); $themes[$theme->get_stylesheet()] = array('Name' => $theme->get('Name'), 'Title' => $theme->get('Name'), 'Version' => $theme->get('Version'), 'Author' => $theme->get('Author'), 'Author URI' => $theme->get('AuthorURI'), 'Template' => $theme->get_template(), 'Stylesheet' => $theme->get_stylesheet()); } // Check for update on a different schedule, depending on the page. switch (current_filter()) { case 'upgrader_process_complete': $timeout = 0; break; case 'load-update-core.php': $timeout = MINUTE_IN_SECONDS; break; case 'load-themes.php': case 'load-update.php': $timeout = HOUR_IN_SECONDS; break; default: if (defined('DOING_CRON') && DOING_CRON) { $timeout = 0; } else { $timeout = 12 * HOUR_IN_SECONDS; } } $time_not_changed = isset($last_update->last_checked) && $timeout > time() - $last_update->last_checked; if ($time_not_changed && !$extra_stats) { $theme_changed = false; foreach ($checked as $slug => $v) { if (!isset($last_update->checked[$slug]) || strval($last_update->checked[$slug]) !== strval($v)) { $theme_changed = true; } } if (isset($last_update->response) && is_array($last_update->response)) { foreach ($last_update->response as $slug => $update_details) { if (!isset($checked[$slug])) { $theme_changed = true; break; } } } // Bail if we've checked recently and if nothing has changed if (!$theme_changed) { return; } } // Update last_checked for current to prevent multiple blocking requests if request hangs $last_update->last_checked = time(); set_site_transient('update_themes', $last_update); $request['themes'] = $themes; $locales = array_values(get_available_languages()); /** * Filter the locales requested for theme translations. * * @since 3.7.0 * @since 4.5.0 Changed default value of `$locales` to include all locales. * * @param array $locales Theme locales. Default is all available locales of the site. */ $locales = apply_filters('themes_update_check_locales', $locales); $locales = array_unique($locales); if (defined('DOING_CRON') && DOING_CRON) { $timeout = 30; } else { // Three seconds, plus one extra second for every 10 themes $timeout = 3 + (int) (count($themes) / 10); } $options = array('timeout' => $timeout, 'body' => array('themes' => wp_json_encode($request), 'translations' => wp_json_encode($translations), 'locale' => wp_json_encode($locales)), 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')); if ($extra_stats) { $options['body']['update_stats'] = wp_json_encode($extra_stats); } $url = $http_url = 'http://api.wordpress.org/themes/update-check/1.1/'; if ($ssl = wp_http_supports(array('ssl'))) { $url = set_url_scheme($url, 'https'); } $raw_response = wp_remote_post($url, $options); if ($ssl && is_wp_error($raw_response)) { trigger_error(__('An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.') . ' ' . __('(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)'), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE); $raw_response = wp_remote_post($http_url, $options); } if (is_wp_error($raw_response) || 200 != wp_remote_retrieve_response_code($raw_response)) { return; } $new_update = new stdClass(); $new_update->last_checked = time(); $new_update->checked = $checked; $response = json_decode(wp_remote_retrieve_body($raw_response), true); if (is_array($response)) { $new_update->response = $response['themes']; $new_update->translations = $response['translations']; } set_site_transient('update_themes', $new_update); }
/** * Parse the files in wp-content/languages and work out what * languages we've got available. Populates self::available_langs * with an array of language objects which look like: * 'ar' => * object(stdClass) * public 'name' => string 'Arabic' * public 'code' => string 'ar' * public 'url_prefix' => string 'ar' * public 'text_direction' => string 'rtl' * * @return void **/ protected function parse_available_languages() { unset($this->available_langs); $this->available_langs = array(); foreach (get_available_languages() as $lang_code) { list($prefix) = explode('_', $lang_code); $lang = array('name' => $this->format_code_lang($prefix), 'code' => $lang_code, 'url_prefix' => $prefix, 'text_direction' => self::is_rtl($lang_code) ? 'rtl' : 'ltr'); // Cast to an object, in case we want to start using actual classes // at some point in the future. $this->available_langs[$lang_code] = (object) $lang; } // Add in US English, which is the default on WordPress and has no language files $en = new stdClass(); $en->name = 'English (US)'; $en->code = 'en_US'; $en->url_prefix = 'en'; $en->text_direction = 'ltr'; $this->available_langs['en_US'] = $en; $this->available_langs = apply_filters('bbl_available_langs', $this->available_langs); ksort($this->available_langs); $this->update_option('available_langs', $this->available_langs); }
/** * Update option WPLANG in DB for new sites. * * @param int $blog_id * @return void */ private function update_wplang($blog_id) { $posted = $this->get_posted_language(); if (!$posted) { return; } // search for wp_locale where search = $http_name $search = array('fields' => array('wp_locale'), 'where' => array(array('field' => 'http_name', 'search' => $posted))); $available_language = $this->language_api->get_db()->get_items($search, OBJECT); // no results found? -> return if (empty($available_language)) { return; } // getting the first wp_locale $wp_locale = $available_language[0]->wp_locale; $available_lang_files = get_available_languages(); if (!in_array($wp_locale, $available_lang_files)) { return; } update_blog_option($blog_id, 'WPLANG', $wp_locale); }
<?php /* All Emoncms code is released under the GNU Affero General Public License. See COPYRIGHT.txt and LICENSE.txt. --------------------------------------------------------------------- Emoncms - open source energy visualisation Part of the OpenEnergyMonitor project: http://openenergymonitor.org */ // no direct access defined('EMONCMS_EXEC') or die('Restricted access'); global $path; $languages = get_available_languages(); $languages_name = languagecode_to_name($languages); //languages order by language name $languages_new = array(); foreach ($languages_name as $key => $lang) { $languages_new[$key] = $languages[$key]; } $languages = array_values($languages_new); $languages_name = array_values($languages_name); function languagecode_to_name($langs) { static $lang_names = null; if ($lang_names === null) { $json_data = file_get_contents(__DIR__ . '/language_country.json'); $lang_names = json_decode($json_data, true); } foreach ($langs as $key => $val) {
/** * Execute changes made in WordPress 4.0.0. * * @since 4.0.0 */ function upgrade_400() { global $wp_current_db_version; if ($wp_current_db_version < 29630) { if (!is_multisite() && false === get_option('WPLANG')) { if (defined('WPLANG') && '' !== WPLANG && in_array(WPLANG, get_available_languages())) { update_option('WPLANG', WPLANG); } else { update_option('WPLANG', ''); } } } }
/** * Download a language pack. * * @since 4.0.0 * * @see wp_get_available_translations() * * @param string $download Language code to download. * @return string|bool Returns the language code if successfully downloaded * (or already installed), or false on failure. */ function wp_download_language_pack($download) { // Check if the translation is already installed. if (in_array($download, get_available_languages())) { return $download; } if (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) { return false; } // Confirm the translation is one we can download. $translations = wp_get_available_translations(); if (!$translations) { return false; } foreach ($translations as $translation) { if ($translation['language'] === $download) { $translation_to_load = true; break; } } if (empty($translation_to_load)) { return false; } $translation = (object) $translation; require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; $skin = new Automatic_Upgrader_Skin(); $upgrader = new Language_Pack_Upgrader($skin); $translation->type = 'core'; $result = $upgrader->upgrade($translation, array('clear_update_cache' => false)); if (!$result || is_wp_error($result)) { return false; } return $translation->language; }
/** * Constructor. * * Stores the original locale as well as a list of all available languages. * * @since 4.7.0 */ public function __construct() { $this->original_locale = is_admin() ? get_user_locale() : get_locale(); $this->available_languages = array_merge(array('en_US'), get_available_languages()); }
/** * get avaiable languages */ private static function get_available_languages() { $installed_langs = get_available_languages(); $exists_langs = array(); //get exists .mo file in wp-content/languages folder foreach ((array) glob(WP_CONTENT_DIR . '/languages' . '/*.mo') as $mo_file) { array_push($exists_langs, basename($mo_file, '.mo')); } return array_merge($installed_langs, $exists_langs); }
/** * Display user meta. * * @wp-hook personal_options * * @param WP_User $user User object. * * @return void */ public function edit_user_profile(WP_User $user) { $languages = get_available_languages(); if (!$languages) { return; } // Add English manually, because it won't get added by WordPress itself. $languages[] = 'en_US'; $user_language = $this->get_user_language($user->ID); ?> <tr> <th> <label for="<?php echo $this->key; ?> "> <?php esc_html_e('Your preferred backend language', 'multilingual-press'); ?> </label> </th> <td> <select name="<?php echo $this->key; ?> " id="<?php echo $this->key; ?> " autocomplete="off"> <?php $this->dropdown_languages($languages, $user_language); ?> </select> </td> </tr> <?php }
/** * check if selected language exists before saving, if not check the previous language, and * if that language does not exist neither, revert to the original blog language. */ function admin_locale_pre_update($new, $old) { $langs = get_available_languages(); if (!in_array('', $langs)) { $langs[] = ''; } if (!in_array($new, $langs)) { if (in_array($old, $langs)) { return $old; } return get_option('WPLANG'); } return $new; }
/** * Sanitises various option values based on the nature of the option. * * This is basically a switch statement which will pass $value through a number * of functions depending on the $option. * * @since 2.0.5 * * @global wpdb $wpdb WordPress database abstraction object. * * @param string $option The name of the option. * @param string $value The unsanitised value. * @return string Sanitized value. */ function sanitize_option($option, $value) { global $wpdb; $original_value = $value; $error = ''; switch ($option) { case 'admin_email': case 'new_admin_email': $value = $wpdb->strip_invalid_text_for_column($wpdb->options, 'option_value', $value); if (is_wp_error($value)) { $error = $value->get_error_message(); } else { $value = sanitize_email($value); if (!is_email($value)) { $error = __('The email address entered did not appear to be a valid email address. Please enter a valid email address.'); } } break; case 'thumbnail_size_w': case 'thumbnail_size_h': case 'medium_size_w': case 'medium_size_h': case 'medium_large_size_w': case 'medium_large_size_h': case 'large_size_w': case 'large_size_h': case 'mailserver_port': case 'comment_max_links': case 'page_on_front': case 'page_for_posts': case 'rss_excerpt_length': case 'default_category': case 'default_email_category': case 'default_link_category': case 'close_comments_days_old': case 'comments_per_page': case 'thread_comments_depth': case 'users_can_register': case 'start_of_week': case 'site_icon': $value = absint($value); break; case 'posts_per_page': case 'posts_per_rss': $value = (int) $value; if (empty($value)) { $value = 1; } if ($value < -1) { $value = abs($value); } break; case 'default_ping_status': case 'default_comment_status': // Options that if not there have 0 value but need to be something like "closed" if ($value == '0' || $value == '') { $value = 'closed'; } break; case 'blogdescription': case 'blogname': $value = $wpdb->strip_invalid_text_for_column($wpdb->options, 'option_value', $value); if (is_wp_error($value)) { $error = $value->get_error_message(); } else { $value = esc_html($value); } break; case 'blog_charset': $value = preg_replace('/[^a-zA-Z0-9_-]/', '', $value); // strips slashes break; case 'blog_public': // This is the value if the settings checkbox is not checked on POST. Don't rely on this. if (null === $value) { $value = 1; } else { $value = intval($value); } break; case 'date_format': case 'time_format': case 'mailserver_url': case 'mailserver_login': case 'mailserver_pass': case 'upload_path': $value = $wpdb->strip_invalid_text_for_column($wpdb->options, 'option_value', $value); if (is_wp_error($value)) { $error = $value->get_error_message(); } else { $value = strip_tags($value); $value = wp_kses_data($value); } break; case 'ping_sites': $value = explode("\n", $value); $value = array_filter(array_map('trim', $value)); $value = array_filter(array_map('esc_url_raw', $value)); $value = implode("\n", $value); break; case 'gmt_offset': $value = preg_replace('/[^0-9:.-]/', '', $value); // strips slashes break; case 'siteurl': $value = $wpdb->strip_invalid_text_for_column($wpdb->options, 'option_value', $value); if (is_wp_error($value)) { $error = $value->get_error_message(); } else { if (preg_match('#http(s?)://(.+)#i', $value)) { $value = esc_url_raw($value); } else { $error = __('The WordPress address you entered did not appear to be a valid URL. Please enter a valid URL.'); } } break; case 'home': $value = $wpdb->strip_invalid_text_for_column($wpdb->options, 'option_value', $value); if (is_wp_error($value)) { $error = $value->get_error_message(); } else { if (preg_match('#http(s?)://(.+)#i', $value)) { $value = esc_url_raw($value); } else { $error = __('The Site address you entered did not appear to be a valid URL. Please enter a valid URL.'); } } break; case 'WPLANG': $allowed = get_available_languages(); if (!is_multisite() && defined('WPLANG') && '' !== WPLANG && 'en_US' !== WPLANG) { $allowed[] = WPLANG; } if (!in_array($value, $allowed) && !empty($value)) { $value = get_option($option); } break; case 'illegal_names': $value = $wpdb->strip_invalid_text_for_column($wpdb->options, 'option_value', $value); if (is_wp_error($value)) { $error = $value->get_error_message(); } else { if (!is_array($value)) { $value = explode(' ', $value); } $value = array_values(array_filter(array_map('trim', $value))); if (!$value) { $value = ''; } } break; case 'limited_email_domains': case 'banned_email_domains': $value = $wpdb->strip_invalid_text_for_column($wpdb->options, 'option_value', $value); if (is_wp_error($value)) { $error = $value->get_error_message(); } else { if (!is_array($value)) { $value = explode("\n", $value); } $domains = array_values(array_filter(array_map('trim', $value))); $value = array(); foreach ($domains as $domain) { if (!preg_match('/(--|\\.\\.)/', $domain) && preg_match('|^([a-zA-Z0-9-\\.])+$|', $domain)) { $value[] = $domain; } } if (!$value) { $value = ''; } } break; case 'timezone_string': $allowed_zones = timezone_identifiers_list(); if (!in_array($value, $allowed_zones) && !empty($value)) { $error = __('The timezone you have entered is not valid. Please select a valid timezone.'); } break; case 'permalink_structure': case 'category_base': case 'tag_base': $value = $wpdb->strip_invalid_text_for_column($wpdb->options, 'option_value', $value); if (is_wp_error($value)) { $error = $value->get_error_message(); } else { $value = esc_url_raw($value); $value = str_replace('http://', '', $value); } break; case 'default_role': if (!get_role($value) && get_role('subscriber')) { $value = 'subscriber'; } break; case 'moderation_keys': case 'blacklist_keys': $value = $wpdb->strip_invalid_text_for_column($wpdb->options, 'option_value', $value); if (is_wp_error($value)) { $error = $value->get_error_message(); } else { $value = explode("\n", $value); $value = array_filter(array_map('trim', $value)); $value = array_unique($value); $value = implode("\n", $value); } break; } if (!empty($error)) { $value = get_option($option); if (function_exists('add_settings_error')) { add_settings_error($option, "invalid_{$option}", $error); } } /** * Filter an option value following sanitization. * * @since 2.3.0 * @since 4.3.0 Added the `$original_value` parameter. * * @param string $value The sanitized option value. * @param string $option The option name. * @param string $original_value The original value passed to the function. */ return apply_filters("sanitize_option_{$option}", $value, $option, $original_value); }
function vp_register_hooks() { global $versionPressContainer; /** @var Committer $committer */ $committer = $versionPressContainer->resolve(VersionPressServices::COMMITTER); /** @var Mirror $mirror */ $mirror = $versionPressContainer->resolve(VersionPressServices::MIRROR); /** @var DbSchemaInfo $dbSchemaInfo */ $dbSchemaInfo = $versionPressContainer->resolve(VersionPressServices::DB_SCHEMA); /** @var VpidRepository $vpidRepository */ $vpidRepository = $versionPressContainer->resolve(VersionPressServices::VPID_REPOSITORY); /** @var WpdbMirrorBridge $wpdbMirrorBridge */ $wpdbMirrorBridge = $versionPressContainer->resolve(VersionPressServices::WPDB_MIRROR_BRIDGE); /** @var \VersionPress\Database\Database $database */ $database = $versionPressContainer->resolve(VersionPressServices::DATABASE); /** @var ActionsInfoProvider $actionsInfoProvider */ $actionsInfoProvider = $versionPressContainer->resolve(VersionPressServices::ACTIONSINFO_PROVIDER_ACTIVE_PLUGINS); if (!function_exists('get_plugins')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $plugins = wp_get_active_and_valid_plugins(); foreach ($plugins as $pluginFile) { $pluginDir = dirname($pluginFile); $hooksFile = $pluginDir . '/.versionpress/hooks.php'; if (file_exists($hooksFile)) { require_once $hooksFile; } } add_filter('update_feedback', function () { touch(ABSPATH . 'versionpress.maintenance'); }); WordPressMissingFunctions::pipeAction('_core_updated_successfully', 'vp_wordpress_updated'); add_action('activated_plugin', function ($pluginFile) { $plugins = get_plugins(); $pluginName = $plugins[$pluginFile]['Name']; do_action('vp_plugin_changed', 'activate', $pluginFile, $pluginName); }); add_action('deactivated_plugin', function ($pluginFile) { $plugins = get_plugins(); $pluginName = $plugins[$pluginFile]['Name']; do_action('vp_plugin_changed', 'deactivate', $pluginFile, $pluginName); }); add_action('upgrader_process_complete', function ($upgrader, $hook_extra) { if ($hook_extra['type'] === 'theme') { $themes = isset($hook_extra['bulk']) && $hook_extra['bulk'] === true ? $hook_extra['themes'] : [$upgrader->result['destination_name']]; foreach ($themes as $stylesheet) { $themeName = wp_get_theme($stylesheet)->get('Name'); if ($themeName === $stylesheet && isset($upgrader->skin->api, $upgrader->skin->api->name)) { $themeName = $upgrader->skin->api->name; } // action can be "install" or "update", see WP_Upgrader and search for `'hook_extra' =>` $action = $hook_extra['action']; do_action('vp_theme_changed', $action, $stylesheet, $themeName); } } if (!($hook_extra['type'] === 'plugin' && $hook_extra['action'] === 'update')) { return; // handled by different hook } if (isset($hook_extra['bulk']) && $hook_extra['bulk'] === true) { $pluginFiles = $hook_extra['plugins']; } else { $pluginFiles = [$hook_extra['plugin']]; } $plugins = get_plugins(); foreach ($pluginFiles as $pluginFile) { $pluginName = $plugins[$pluginFile]['Name']; do_action('vp_plugin_changed', 'update', $pluginFile, $pluginName); } }, 10, 2); add_filter('upgrader_pre_install', function ($_, $hook_extra) { if (!(isset($hook_extra['type']) && $hook_extra['type'] === 'plugin' && $hook_extra['action'] === 'install')) { return; } $pluginsBeforeInstallation = get_plugins(); $postInstallHook = function ($_, $hook_extra) use($pluginsBeforeInstallation, &$postInstallHook) { if (!($hook_extra['type'] === 'plugin' && $hook_extra['action'] === 'install')) { return; } wp_cache_delete('plugins', 'plugins'); $pluginsAfterInstallation = get_plugins(); $installedPlugins = array_diff_key($pluginsAfterInstallation, $pluginsBeforeInstallation); foreach ($installedPlugins as $pluginFile => $plugin) { do_action('vp_plugin_changed', 'install', $pluginFile, $plugin['Name']); } remove_filter('upgrader_post_install', $postInstallHook); }; add_filter('upgrader_post_install', $postInstallHook, 10, 2); }, 10, 2); add_filter('upgrader_pre_download', function ($reply, $_, $upgrader) use($committer) { if (!isset($upgrader->skin->language_update)) { return $reply; } $languages = get_available_languages(); $postInstallHook = function ($_, $hook_extra) use($committer, $languages, &$postInstallHook) { if (!isset($hook_extra['language_update_type'])) { return; } $type = $hook_extra['language_update_type']; $languageCode = $hook_extra['language_update']->language; $name = $type === "core" ? null : $hook_extra['language_update']->slug; $action = in_array($languageCode, $languages) ? "update" : "install"; do_action('vp_translation_changed', $action, $languageCode, $type, $name); remove_filter('upgrader_post_install', $postInstallHook); }; add_filter('upgrader_post_install', $postInstallHook, 10, 2); return false; }, 10, 3); add_action('switch_theme', function () use($committer) { if (defined('WP_CLI') && WP_CLI) { wp_remote_get(admin_url()); // } else { $committer->disableCommit(); // the change will be committed on next load } }); add_action('after_switch_theme', function () use($committer) { $theme = wp_get_theme(); $stylesheet = $theme->get_stylesheet(); $themeName = $theme->get('Name'); do_action('vp_theme_changed', 'switch', $stylesheet, $themeName); }); function _vp_get_language_name_by_code($code) { require_once ABSPATH . 'wp-admin/includes/translation-install.php'; $translations = wp_get_available_translations(); return isset($translations[$code]) ? $translations[$code]['native_name'] : 'English (United States)'; } add_action('add_option_WPLANG', function ($option, $value) use($committer) { $defaultLanguage = defined('WPLANG') ? WPLANG : ''; if ($value === $defaultLanguage) { return; // It's just submitted settings form without changing language } do_action('vp_translation_changed', 'activate', $value); }, 10, 2); add_action('update_option_WPLANG', function ($oldValue, $newValue) use($committer) { do_action('vp_translation_changed', 'activate', $newValue); }, 10, 2); add_action('wp_update_nav_menu_item', function ($menu_id, $menu_item_db_id) use($committer) { $key = 'menu-item-' . $menu_item_db_id; if (defined('DOING_AJAX') && DOING_AJAX && isset($_POST['action']) && $_POST['action'] === 'add-menu-item') { $committer->postponeCommit($key); $committer->commit(); } elseif (isset($_POST['action']) && $_POST['action'] === 'update') { $committer->usePostponedChangeInfos($key); } }, 10, 2); add_action('pre_delete_term', function ($termId, $taxonomy) use($committer, $vpidRepository, $dbSchemaInfo, $actionsInfoProvider) { $termVpid = $vpidRepository->getVpidForEntity('term', $termId); $term = get_term($termId, $taxonomy); $termEntityInfo = $dbSchemaInfo->getEntityInfo('term'); $actionsInfo = $actionsInfoProvider->getActionsInfo('term'); $changeInfo = new EntityChangeInfo($termEntityInfo, $actionsInfo, 'delete', $termVpid, ['VP-Term-Name' => $term->name, 'VP-Term-Taxonomy' => $taxonomy]); $committer->forceChangeInfo($changeInfo); }, 10, 2); add_filter('wp_save_image_editor_file', function ($saved, $filename, $image, $mime_type, $post_id) use($vpidRepository, $committer, $dbSchemaInfo, $actionsInfoProvider) { $vpid = $vpidRepository->getVpidForEntity('post', $post_id); $post = get_post($post_id); $actionsInfo = $actionsInfoProvider->getActionsInfo('post'); $changeInfo = new EntityChangeInfo($dbSchemaInfo->getEntityInfo('post'), $actionsInfo, 'edit', $vpid, ['VP-Post-Type' => $post->post_type, 'VP-Post-Title' => $post->post_title]); $committer->forceChangeInfo($changeInfo); }, 10, 5); add_filter('plugin_install_action_links', function ($links, $plugin) { $compatibility = CompatibilityChecker::testCompatibilityBySlug($plugin['slug']); if ($compatibility === CompatibilityResult::COMPATIBLE) { $cssClass = 'vp-compatible'; $compatibilityAdjective = 'Compatible'; } elseif ($compatibility === CompatibilityResult::INCOMPATIBLE) { $cssClass = 'vp-incompatible'; // @codingStandardsIgnoreLine $compatibilityAdjective = '<a href="http://docs.versionpress.net/en/integrations/plugins" target="_blank" title="This plugin is not compatible with VersionPress. These plugins will not work correctly when used together.">Incompatible</a>'; } else { $cssClass = 'vp-untested'; // @codingStandardsIgnoreLine $compatibilityAdjective = '<a href="http://docs.versionpress.net/en/integrations/plugins" target="_blank" title="This plugin was not yet tested with VersionPress. Some functionality may not work as intended.">Untested</a>'; } // @codingStandardsIgnoreLine $compatibilityNotice = '<span class="vp-compatibility %s" data-plugin-name="%s"><strong>%s</strong> with VersionPress</span>'; $links[] = sprintf($compatibilityNotice, $cssClass, $plugin['name'], $compatibilityAdjective); return $links; }, 10, 2); add_filter('plugin_row_meta', function ($plugin_meta, $plugin_file, $plugin_data, $status) { if ($status === "dropins") { return $plugin_meta; } $compatibility = CompatibilityChecker::testCompatibilityByPluginFile($plugin_file); if ($compatibility === CompatibilityResult::COMPATIBLE) { $cssClass = 'vp-compatible'; $compatibilityAdjective = 'Compatible'; } elseif ($compatibility === CompatibilityResult::INCOMPATIBLE) { $cssClass = 'vp-incompatible'; // @codingStandardsIgnoreLine $compatibilityAdjective = '<a href="http://docs.versionpress.net/en/integrations/plugins" target="_blank" title="This plugin is not compatible with VersionPress. These plugins will not work correctly when used together.">Incompatible</a>'; } elseif ($compatibility === CompatibilityResult::UNTESTED) { $cssClass = 'vp-untested'; // @codingStandardsIgnoreLine $compatibilityAdjective = '<a href="http://docs.versionpress.net/en/integrations/plugins" target="_blank" title="This plugin was not yet tested with VersionPress. Some functionality may not work as intended.">Untested</a>'; } else { return $plugin_meta; } // @codingStandardsIgnoreLine $compatibilityNotice = '<span class="vp-compatibility %s" data-plugin-name="%s"><strong>%s</strong> with VersionPress</span>'; $plugin_meta[] = sprintf($compatibilityNotice, $cssClass, $plugin_data['Name'], $compatibilityAdjective); return $plugin_meta; }, 10, 4); add_filter('plugin_action_links', function ($actions, $plugin_file) { $compatibility = CompatibilityChecker::testCompatibilityByPluginFile($plugin_file); if (isset($actions['activate'])) { if ($compatibility === CompatibilityResult::UNTESTED) { $actions['activate'] = "<span class=\"vp-plugin-list vp-untested\">{$actions['activate']}</span>"; } elseif ($compatibility === CompatibilityResult::INCOMPATIBLE) { $actions['activate'] = "<span class=\"vp-plugin-list vp-incompatible\">{$actions['activate']}</span>"; } } return $actions; }, 10, 2); add_action('vp_revert', function ($modifiedFiles) { // We have to flush the rewrite rules in the next request, because // in the current one the changed rewrite rules are not yet effective. set_transient('vp_flush_rewrite_rules', 1); vp_flush_regenerable_options(); // Update composer dependencies if (array_search('composer.lock', $modifiedFiles) || array_search('composer.json', $modifiedFiles)) { putenv('COMPOSER_HOME=' . VP_PROJECT_ROOT . '/vendor/bin/composer'); $originalCwd = getcwd(); chdir(VP_PROJECT_ROOT); $input = new \Symfony\Component\Console\Input\ArrayInput(['command' => 'install']); $output = new \Symfony\Component\Console\Output\NullOutput(); $application = new \Composer\Console\Application(); $application->setAutoExit(false); // prevent `$application->run` method from exitting the script $application->run($input, $output); $application->getComposer(); chdir($originalCwd); } }); add_action('pre_delete_term', function ($term, $taxonomy) use($database, $wpdbMirrorBridge) { if (!is_taxonomy_hierarchical($taxonomy)) { return; } $term = get_term($term, $taxonomy); if (is_wp_error($term)) { return; } $wpdbMirrorBridge->update($database->term_taxonomy, ['parent' => $term->parent], ['parent' => $term->term_id]); }, 10, 2); add_action('before_delete_post', function ($postId) use($database, $wpdbMirrorBridge) { // Fixing bug in WP (#34803) and WP-CLI (#2246); $post = get_post($postId); if (!is_wp_error($post) && $post->post_type === 'nav_menu_item') { $newParent = get_post_meta($post->ID, '_menu_item_menu_item_parent', true); $wpdbMirrorBridge->update($database->postmeta, ['meta_value' => $newParent], ['meta_key' => '_menu_item_menu_item_parent', 'meta_value' => $post->ID]); $database->update($database->postmeta, ['meta_value' => $newParent], ['meta_key' => '_menu_item_menu_item_parent', 'meta_value' => $post->ID]); } }); //---------------------------------------- // URL and WP-CLI "hooks" //---------------------------------------- $requestDetector = new \VersionPress\Utils\RequestDetector(); if ($requestDetector->isThemeDeleteRequest()) { $themeIds = $requestDetector->getThemeStylesheets(); foreach ($themeIds as $stylesheet) { $themeName = wp_get_theme($stylesheet)->get('Name'); do_action('vp_theme_changed', 'delete', $stylesheet, $themeName); } } if ($requestDetector->isPluginDeleteRequest()) { $pluginNames = $requestDetector->getPluginNames(); $plugins = get_plugins(); foreach ($pluginNames as $plugin) { do_action('vp_plugin_changed', 'delete', $plugin, $plugins[$plugin]['Name']); } } if ($requestDetector->isCoreLanguageUninstallRequest()) { $languageCode = $requestDetector->getLanguageCode(); do_action('vp_translation_changed', 'uninstall', $languageCode); } if (basename($_SERVER['PHP_SELF']) === 'theme-editor.php' && isset($_GET['updated']) && $_GET['updated'] === 'true') { $stylesheet = $_GET['theme']; $themeName = wp_get_theme($stylesheet)->get('Name'); do_action('vp_theme_changed', 'edit', $stylesheet, $themeName); } if (basename($_SERVER['PHP_SELF']) === 'plugin-editor.php' && (isset($_POST['action']) && $_POST['action'] === 'update' || isset($_GET['liveupdate']))) { $committer->disableCommit(); } if (basename($_SERVER['PHP_SELF']) === 'plugin-editor.php' && isset($_GET['a']) && $_GET['a'] === 'te') { if (!function_exists('get_plugins')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $editedFile = $_GET['file']; $editedFilePathParts = preg_split("~[/\\\\]~", $editedFile); $plugins = get_plugins(); $pluginNames = array_keys($plugins); $bestRank = 0; $bestMatch = ""; foreach ($pluginNames as $plugin) { $rank = 0; $pluginPathParts = preg_split("~[/\\\\]~", $plugin); $maxEqualParts = min(count($editedFilePathParts), count($pluginPathParts)); for ($part = 0; $part < $maxEqualParts; $part++) { if ($editedFilePathParts[$part] !== $pluginPathParts[$part]) { break; } $rank += 1; } if ($rank > $bestRank) { $bestRank = $rank; $bestMatch = $plugin; } } do_action('vp_plugin_changed', 'edit', $bestMatch, $plugins[$bestMatch]['Name']); } add_filter('cron_schedules', function ($schedules) use($dbSchemaInfo) { $intervals = $dbSchemaInfo->getIntervalsForFrequentlyWrittenEntities(); foreach ($intervals as $interval) { if (isset($schedules[$interval])) { continue; } $seconds = strtotime($interval, 0); $schedules[$interval] = ['interval' => $seconds, 'display' => $interval]; } return $schedules; }); $r = $dbSchemaInfo->getRulesForFrequentlyWrittenEntities(); $groupedByInterval = []; foreach ($r as $entityName => $rules) { foreach ($rules as $rule) { $groupedByInterval[$rule['interval']][$entityName][] = $rule; } } foreach ($groupedByInterval as $interval => $allRulesInInterval) { $actionName = "vp_commit_frequently_written_entities_{$interval}"; if (!wp_next_scheduled($actionName)) { wp_schedule_event(time(), $interval, $actionName); } add_action($actionName, function () use($allRulesInInterval) { vp_save_frequently_written_entities($allRulesInInterval); }); } if (!function_exists('get_plugins')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } register_shutdown_function([$committer, 'commit']); }
do_action('wpmuadminedit', ''); if (isset($_GET['id'])) { $id = intval($_GET['id']); } elseif (isset($_POST['id'])) { $id = intval($_POST['id']); } switch ($_GET['action']) { case 'siteoptions': check_admin_referer('siteoptions'); if (!current_user_can('manage_network_options')) { wp_die(__('You do not have permission to access this page.')); } if (empty($_POST)) { wp_die(sprintf(__('You probably need to go back to the <a href="%s">options page</a>.', esc_url(admin_url('ms-options.php'))))); } if (isset($_POST['WPLANG']) && ('' === $_POST['WPLANG'] || in_array($_POST['WPLANG'], get_available_languages()))) { update_site_option('WPLANG', $_POST['WPLANG']); } if (is_email($_POST['admin_email'])) { update_site_option('admin_email', $_POST['admin_email']); } $illegal_names = split(' ', $_POST['illegal_names']); foreach ((array) $illegal_names as $name) { $name = trim($name); if ($name != '') { $names[] = trim($name); } } update_site_option('illegal_names', $names); if ($_POST['limited_email_domains'] != '') { $limited_email_domains = str_replace(' ', "\n", $_POST['limited_email_domains']);
/** * Loads plugin and theme textdomains just-in-time. * * When a textdomain is encountered for the first time, we try to load * the translation file from `wp-content/languages`, removing the need * to call load_plugin_texdomain() or load_theme_texdomain(). * * Holds a cached list of available .mo files to improve performance. * * @since 4.6.0 * @access private * * @see get_translations_for_domain() * @global array $l10n_unloaded An array of all text domains that have been unloaded again. * * @param string $domain Text domain. Unique identifier for retrieving translated strings. * @return bool True when the textdomain is successfully loaded, false otherwise. */ function _load_textdomain_just_in_time($domain) { global $l10n_unloaded; $l10n_unloaded = (array) $l10n_unloaded; static $cached_mofiles = null; // Short-circuit if domain is 'default' which is reserved for core. if ('default' === $domain || isset($l10n_unloaded[$domain])) { return false; } if (null === $cached_mofiles) { $cached_mofiles = array(); $locations = array(WP_LANG_DIR . '/plugins', WP_LANG_DIR . '/themes'); foreach ($locations as $location) { foreach (get_available_languages($location) as $file) { $cached_mofiles[] = "{$location}/{$file}.mo"; } } } $locale = get_locale(); $mofile = "{$domain}-{$locale}.mo"; if (in_array(WP_LANG_DIR . '/plugins/' . $mofile, $cached_mofiles)) { return load_textdomain($domain, WP_LANG_DIR . '/plugins/' . $mofile); } if (in_array(WP_LANG_DIR . '/themes/' . $mofile, $cached_mofiles)) { return load_textdomain($domain, WP_LANG_DIR . '/themes/' . $mofile); } return false; }
/** * Sanitises various option values based on the nature of the option. * * This is basically a switch statement which will pass $value through a number * of functions depending on the $option. * * @since 2.0.5 * * @param string $option The name of the option. * @param string $value The unsanitised value. * @return string Sanitized value. */ function sanitize_option($option, $value) { switch ($option) { case 'admin_email': case 'new_admin_email': $value = sanitize_email($value); if (!is_email($value)) { $value = get_option($option); // Resets option to stored value in the case of failed sanitization if (function_exists('add_settings_error')) { add_settings_error($option, 'invalid_admin_email', __('The email address entered did not appear to be a valid email address. Please enter a valid email address.')); } } break; case 'thumbnail_size_w': case 'thumbnail_size_h': case 'medium_size_w': case 'medium_size_h': case 'large_size_w': case 'large_size_h': case 'mailserver_port': case 'comment_max_links': case 'page_on_front': case 'page_for_posts': case 'rss_excerpt_length': case 'default_category': case 'default_email_category': case 'default_link_category': case 'close_comments_days_old': case 'comments_per_page': case 'thread_comments_depth': case 'users_can_register': case 'start_of_week': $value = absint($value); break; case 'posts_per_page': case 'posts_per_rss': $value = (int) $value; if (empty($value)) { $value = 1; } if ($value < -1) { $value = abs($value); } break; case 'default_ping_status': case 'default_comment_status': // Options that if not there have 0 value but need to be something like "closed" if ($value == '0' || $value == '') { $value = 'closed'; } break; case 'blogdescription': case 'blogname': $value = wp_kses_post($value); $value = esc_html($value); break; case 'blog_charset': $value = preg_replace('/[^a-zA-Z0-9_-]/', '', $value); // strips slashes break; case 'blog_public': // This is the value if the settings checkbox is not checked on POST. Don't rely on this. if (null === $value) { $value = 1; } else { $value = intval($value); } break; case 'date_format': case 'time_format': case 'mailserver_url': case 'mailserver_login': case 'mailserver_pass': case 'upload_path': $value = strip_tags($value); $value = wp_kses_data($value); break; case 'ping_sites': $value = explode("\n", $value); $value = array_filter(array_map('trim', $value)); $value = array_filter(array_map('esc_url_raw', $value)); $value = implode("\n", $value); break; case 'gmt_offset': $value = preg_replace('/[^0-9:.-]/', '', $value); // strips slashes break; case 'siteurl': if ((bool) preg_match('#http(s?)://(.+)#i', $value)) { $value = esc_url_raw($value); } else { $value = get_option($option); // Resets option to stored value in the case of failed sanitization if (function_exists('add_settings_error')) { add_settings_error('siteurl', 'invalid_siteurl', __('The WordPress address you entered did not appear to be a valid URL. Please enter a valid URL.')); } } break; case 'home': if ((bool) preg_match('#http(s?)://(.+)#i', $value)) { $value = esc_url_raw($value); } else { $value = get_option($option); // Resets option to stored value in the case of failed sanitization if (function_exists('add_settings_error')) { add_settings_error('home', 'invalid_home', __('The Site address you entered did not appear to be a valid URL. Please enter a valid URL.')); } } break; case 'WPLANG': $allowed = get_available_languages(); if (!in_array($value, $allowed) && !empty($value)) { $value = get_option($option); } break; case 'illegal_names': if (!is_array($value)) { $value = explode("\n", $value); } $value = array_values(array_filter(array_map('trim', $value))); if (!$value) { $value = ''; } break; case 'limited_email_domains': case 'banned_email_domains': if (!is_array($value)) { $value = explode("\n", $value); } $domains = array_values(array_filter(array_map('trim', $value))); $value = array(); foreach ($domains as $domain) { if (!preg_match('/(--|\\.\\.)/', $domain) && preg_match('|^([a-zA-Z0-9-\\.])+$|', $domain)) { $value[] = $domain; } } if (!$value) { $value = ''; } break; case 'timezone_string': $allowed_zones = timezone_identifiers_list(); if (!in_array($value, $allowed_zones) && !empty($value)) { $value = get_option($option); // Resets option to stored value in the case of failed sanitization if (function_exists('add_settings_error')) { add_settings_error('timezone_string', 'invalid_timezone_string', __('The timezone you have entered is not valid. Please select a valid timezone.')); } } break; case 'permalink_structure': case 'category_base': case 'tag_base': $value = esc_url_raw($value); $value = str_replace('http://', '', $value); break; } $value = apply_filters("sanitize_option_{$option}", $value, $option); return $value; }
/** * Sanitises various option values based on the nature of the option. * * This is basically a switch statement which will pass $value through a number * of functions depending on the $option. * * @since 2.0.5 * * @param string $option The name of the option. * @param string $value The unsanitised value. * @return string Sanitized value. */ function sanitize_option($option, $value) { switch ($option) { case 'admin_email': $value = sanitize_email($value); if (!is_email($value)) { $value = get_option($option); // Resets option to stored value in the case of failed sanitization if (function_exists('add_settings_error')) { add_settings_error('admin_email', 'invalid_admin_email', __('The email address entered did not appear to be a valid email address. Please enter a valid email address.')); } } break; case 'new_admin_email': $value = sanitize_email($value); if (!is_email($value)) { $value = get_option($option); // Resets option to stored value in the case of failed sanitization if (function_exists('add_settings_error')) { add_settings_error('new_admin_email', 'invalid_admin_email', __('The email address entered did not appear to be a valid email address. Please enter a valid email address.')); } } break; case 'thumbnail_size_w': case 'thumbnail_size_h': case 'medium_size_w': case 'medium_size_h': case 'large_size_w': case 'large_size_h': case 'embed_size_h': case 'default_post_edit_rows': case 'mailserver_port': case 'comment_max_links': case 'page_on_front': case 'page_for_posts': case 'rss_excerpt_length': case 'default_category': case 'default_email_category': case 'default_link_category': case 'close_comments_days_old': case 'comments_per_page': case 'thread_comments_depth': case 'users_can_register': case 'start_of_week': $value = absint($value); break; case 'embed_size_w': if ('' !== $value) { $value = absint($value); } break; case 'posts_per_page': case 'posts_per_rss': $value = (int) $value; if (empty($value)) { $value = 1; } if ($value < -1) { $value = abs($value); } break; case 'default_ping_status': case 'default_comment_status': // Options that if not there have 0 value but need to be something like "closed" if ($value == '0' || $value == '') { $value = 'closed'; } break; case 'blogdescription': case 'blogname': $value = addslashes($value); $value = wp_filter_post_kses($value); // calls stripslashes then addslashes $value = stripslashes($value); $value = esc_html($value); break; case 'blog_charset': $value = preg_replace('/[^a-zA-Z0-9_-]/', '', $value); // strips slashes break; case 'date_format': case 'time_format': case 'mailserver_url': case 'mailserver_login': case 'mailserver_pass': case 'ping_sites': case 'upload_path': $value = strip_tags($value); $value = addslashes($value); $value = wp_filter_kses($value); // calls stripslashes then addslashes $value = stripslashes($value); break; case 'gmt_offset': $value = preg_replace('/[^0-9:.-]/', '', $value); // strips slashes break; case 'siteurl': if ((bool) preg_match('#http(s?)://(.+)#i', $value)) { $value = esc_url_raw($value); } else { $value = get_option($option); // Resets option to stored value in the case of failed sanitization if (function_exists('add_settings_error')) { add_settings_error('siteurl', 'invalid_siteurl', __('The WordPress address you entered did not appear to be a valid URL. Please enter a valid URL.')); } } break; case 'home': if ((bool) preg_match('#http(s?)://(.+)#i', $value)) { $value = esc_url_raw($value); } else { $value = get_option($option); // Resets option to stored value in the case of failed sanitization if (function_exists('add_settings_error')) { add_settings_error('home', 'invalid_home', __('The Site address you entered did not appear to be a valid URL. Please enter a valid URL.')); } } break; case 'WPLANG': $allowed = get_available_languages(); if (!in_array($value, $allowed) && !empty($value)) { $value = get_option($option); } break; case 'timezone_string': $allowed_zones = timezone_identifiers_list(); if (!in_array($value, $allowed_zones) && !empty($value)) { $value = get_option($option); // Resets option to stored value in the case of failed sanitization if (function_exists('add_settings_error')) { add_settings_error('timezone_string', 'invalid_timezone_string', __('The timezone you have entered is not valid. Please select a valid timezone.')); } } break; default: $value = apply_filters("sanitize_option_{$option}", $value, $option); break; } return $value; }