Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * @ticket 35284
  */
 function test_wp_get_installed_translations_for_core()
 {
     $installed_translations = wp_get_installed_translations('core');
     $this->assertInternalType('array', $installed_translations);
     $textdomains_expected = array('admin', 'admin-network', 'continents-cities', 'default');
     $this->assertEqualSets($textdomains_expected, array_keys($installed_translations));
     $this->assertNotEmpty($installed_translations['default']['en_GB']);
     $data_en_GB = $installed_translations['default']['en_GB'];
     $this->assertEquals('2016-10-26 00:01+0200', $data_en_GB['PO-Revision-Date']);
     $this->assertEquals('Development (4.4.x)', $data_en_GB['Project-Id-Version']);
     $this->assertEquals('Poedit 1.8.10', $data_en_GB['X-Generator']);
     $this->assertNotEmpty($installed_translations['admin']['es_ES']);
     $data_es_ES = $installed_translations['admin']['es_ES'];
     $this->assertEquals('2016-10-25 18:29+0200', $data_es_ES['PO-Revision-Date']);
     $this->assertEquals('Administration', $data_es_ES['Project-Id-Version']);
     $this->assertEquals('Poedit 1.8.10', $data_es_ES['X-Generator']);
 }
Exemplo n.º 3
0
 /**
  * @ticket 35284
  */
 function test_wp_get_installed_translations_for_core()
 {
     $installed_translations = wp_get_installed_translations('core');
     $this->assertInternalType('array', $installed_translations);
     $textdomains_expected = array('admin', 'admin-network', 'continents-cities', 'default');
     $this->assertEqualSets($textdomains_expected, array_keys($installed_translations));
     $this->assertNotEmpty($installed_translations['default']['en_GB']);
     $data_en_GB = $installed_translations['default']['en_GB'];
     $this->assertEquals('2016-01-14 21:14:29+0000', $data_en_GB['PO-Revision-Date']);
     $this->assertEquals('Development (4.4.x)', $data_en_GB['Project-Id-Version']);
     $this->assertEquals('GlotPress/1.0-alpha-1100', $data_en_GB['X-Generator']);
     $this->assertNotEmpty($installed_translations['admin']['es_ES']);
     $data_es_ES = $installed_translations['admin']['es_ES'];
     $this->assertEquals('2015-12-22 20:26:46+0000', $data_es_ES['PO-Revision-Date']);
     $this->assertEquals('Administration', $data_es_ES['Project-Id-Version']);
     $this->assertEquals('GlotPress/1.0-alpha-1100', $data_es_ES['X-Generator']);
 }
Exemplo n.º 4
0
            // Do not allow to delete Activated plugins.
            if (empty($plugins)) {
                wp_redirect(self_admin_url("plugins.php?error=true&main=true&plugin_status={$status}&paged={$page}&s={$s}"));
                exit;
            }
            include ABSPATH . 'wp-admin/update.php';
            $parent_file = 'plugins.php';
            if (!isset($_REQUEST['verify-delete'])) {
                wp_enqueue_script('jquery');
                require_once ABSPATH . 'wp-admin/admin-header.php';
                ?>
			<div class="wrap">
				<?php 
                $files_to_delete = $plugin_info = array();
                $have_non_network_plugins = false;
                $plugin_translations = wp_get_installed_translations('plugins');
                foreach ((array) $plugins as $plugin) {
                    $plugin_slug = dirname($plugin);
                    if ('.' == $plugin_slug) {
                        $files_to_delete[] = WP_PLUGIN_DIR . '/' . $plugin;
                        if ($data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin)) {
                            $plugin_info[$plugin] = $data;
                            $plugin_info[$plugin]['is_uninstallable'] = is_uninstallable_plugin($plugin);
                            if (!$plugin_info[$plugin]['Network']) {
                                $have_non_network_plugins = true;
                            }
                        }
                    } else {
                        // Locate all the files in that folder.
                        $files = list_files(WP_PLUGIN_DIR . '/' . $plugin_slug);
                        if ($files) {
Exemplo n.º 5
0
 if (!current_user_can('delete_themes')) {
     wp_die(__('You do not have sufficient permissions to delete themes for this site.'));
 }
 check_admin_referer('bulk-themes');
 $themes = isset($_REQUEST['checked']) ? (array) $_REQUEST['checked'] : array();
 if (empty($themes)) {
     wp_safe_redirect(add_query_arg('error', 'none', $referer));
     exit;
 }
 $themes = array_diff($themes, array(get_option('stylesheet'), get_option('template')));
 if (empty($themes)) {
     wp_safe_redirect(add_query_arg('error', 'main', $referer));
     exit;
 }
 $files_to_delete = $theme_info = array();
 $theme_translations = wp_get_installed_translations('themes');
 foreach ($themes as $key => $theme) {
     $theme_info[$theme] = wp_get_theme($theme);
     // Locate all the files in that folder.
     $files = list_files($theme_info[$theme]->get_stylesheet_directory());
     if ($files) {
         $files_to_delete = array_merge($files_to_delete, $files);
     }
     // Add translation files.
     $theme_slug = $theme_info[$theme]->get_stylesheet();
     if (!empty($theme_translations[$theme_slug])) {
         $translations = $theme_translations[$theme_slug];
         foreach ($translations as $translation => $data) {
             $files_to_delete[] = $theme_slug . '-' . $translation . '.po';
             $files_to_delete[] = $theme_slug . '-' . $translation . '.mo';
         }
Exemplo n.º 6
0
/**
 * Remove a theme
 *
 * @since 2.8.0
 *
 * @param string $stylesheet Stylesheet of the theme to delete
 * @param string $redirect Redirect to page when complete.
 * @return mixed
 */
function delete_theme($stylesheet, $redirect = '')
{
    global $wp_filesystem;
    if (empty($stylesheet)) {
        return false;
    }
    ob_start();
    if (empty($redirect)) {
        $redirect = wp_nonce_url('themes.php?action=delete&stylesheet=' . urlencode($stylesheet), 'delete-theme_' . $stylesheet);
    }
    if (false === ($credentials = request_filesystem_credentials($redirect))) {
        $data = ob_get_contents();
        ob_end_clean();
        if (!empty($data)) {
            include_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            include ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!WP_Filesystem($credentials)) {
        request_filesystem_credentials($redirect, '', true);
        // Failed to connect, Error and request again
        $data = ob_get_contents();
        ob_end_clean();
        if (!empty($data)) {
            include_once ABSPATH . 'wp-admin/admin-header.php';
            echo $data;
            include ABSPATH . 'wp-admin/admin-footer.php';
            exit;
        }
        return;
    }
    if (!is_object($wp_filesystem)) {
        return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
    }
    if (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
        return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);
    }
    // Get the base plugin folder.
    $themes_dir = $wp_filesystem->wp_themes_dir();
    if (empty($themes_dir)) {
        return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress theme directory.'));
    }
    $themes_dir = trailingslashit($themes_dir);
    $theme_dir = trailingslashit($themes_dir . $stylesheet);
    $deleted = $wp_filesystem->delete($theme_dir, true);
    if (!$deleted) {
        return new WP_Error('could_not_remove_theme', sprintf(__('Could not fully remove the theme %s.'), $stylesheet));
    }
    $theme_translations = wp_get_installed_translations('themes');
    // Remove language files, silently.
    if (!empty($theme_translations[$stylesheet])) {
        $translations = $theme_translations[$stylesheet];
        foreach ($translations as $translation => $data) {
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.po');
            $wp_filesystem->delete(WP_LANG_DIR . '/themes/' . $stylesheet . '-' . $translation . '.mo');
        }
    }
    // Force refresh of theme update information.
    delete_site_transient('update_themes');
    return true;
}
Exemplo n.º 7
0
/**
 * Remove directory and files of a plugin for a list of plugins.
 *
 * @since 2.6.0
 *
 * @global WP_Filesystem_Base $wp_filesystem
 *
 * @param array  $plugins    List of plugins to delete.
 * @param string $deprecated Deprecated.
 * @return bool|null|WP_Error True on success, false is $plugins is empty, WP_Error on failure.
 *                            Null if filesystem credentials are required to proceed.
 */
function delete_plugins( $plugins, $deprecated = '' ) {
	global $wp_filesystem;

	if ( empty($plugins) )
		return false;

	$checked = array();
	foreach( $plugins as $plugin )
		$checked[] = 'checked[]=' . $plugin;

	ob_start();
	$url = wp_nonce_url('plugins.php?action=delete-selected&verify-delete=1&' . implode('&', $checked), 'bulk-plugins');
	if ( false === ($credentials = request_filesystem_credentials($url)) ) {
		$data = ob_get_contents();
		ob_end_clean();
		if ( ! empty($data) ){
			include_once( ABSPATH . 'wp-admin/admin-header.php');
			echo $data;
			include( ABSPATH . 'wp-admin/admin-footer.php');
			exit;
		}
		return;
	}

	if ( ! WP_Filesystem($credentials) ) {
		request_filesystem_credentials($url, '', true); //Failed to connect, Error and request again
		$data = ob_get_contents();
		ob_end_clean();
		if ( ! empty($data) ){
			include_once( ABSPATH . 'wp-admin/admin-header.php');
			echo $data;
			include( ABSPATH . 'wp-admin/admin-footer.php');
			exit;
		}
		return;
	}

	if ( ! is_object($wp_filesystem) )
		return new WP_Error('fs_unavailable', __('Could not access filesystem.'));

	if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
		return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors);

	// Get the base plugin folder.
	$plugins_dir = $wp_filesystem->wp_plugins_dir();
	if ( empty( $plugins_dir ) ) {
		return new WP_Error( 'fs_no_plugins_dir', __( 'Unable to locate WordPress Plugin directory.' ) );
	}

	$plugins_dir = trailingslashit( $plugins_dir );

	$plugin_translations = wp_get_installed_translations( 'plugins' );

	$errors = array();

	foreach( $plugins as $plugin_file ) {
		// Run Uninstall hook.
		if ( is_uninstallable_plugin( $plugin_file ) ) {
			uninstall_plugin($plugin_file);
		}

		$this_plugin_dir = trailingslashit( dirname( $plugins_dir . $plugin_file ) );
		// If plugin is in its own directory, recursively delete the directory.
		if ( strpos( $plugin_file, '/' ) && $this_plugin_dir != $plugins_dir ) { //base check on if plugin includes directory separator AND that it's not the root plugin folder
			$deleted = $wp_filesystem->delete( $this_plugin_dir, true );
		} else {
			$deleted = $wp_filesystem->delete( $plugins_dir . $plugin_file );
		}

		if ( ! $deleted ) {
			$errors[] = $plugin_file;
			continue;
		}

		// Remove language files, silently.
		$plugin_slug = dirname( $plugin_file );
		if ( '.' !== $plugin_slug && ! empty( $plugin_translations[ $plugin_slug ] ) ) {
			$translations = $plugin_translations[ $plugin_slug ];

			foreach ( $translations as $translation => $data ) {
				$wp_filesystem->delete( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.po' );
				$wp_filesystem->delete( WP_LANG_DIR . '/plugins/' . $plugin_slug . '-' . $translation . '.mo' );
			}
		}
	}

	// Remove deleted plugins from the plugin updates list.
	if ( $current = get_site_transient('update_plugins') ) {
		// Don't remove the plugins that weren't deleted.
		$deleted = array_diff( $plugins, $errors );

		foreach ( $deleted as $plugin_file ) {
			unset( $current->response[ $plugin_file ] );
		}

		set_site_transient( 'update_plugins', $current );
	}

	if ( ! empty($errors) )
		return new WP_Error('could_not_remove_plugin', sprintf(__('Could not fully remove the plugin(s) %s.'), implode(', ', $errors)) );

	return true;
}
Exemplo n.º 8
0
function learn_press_get_plugin_data($plugins)
{
    global $wp_version;
    //$plugins = get_plugins();
    $translations = wp_get_installed_translations('plugins');
    $active = get_option('active_plugins', array());
    $current = get_site_transient('update_plugins');
    $to_send = compact('plugins', 'active');
    $locales = array(get_locale());
    $options = array('timeout' => 30, 'body' => array('plugins' => wp_json_encode($to_send), 'translations' => wp_json_encode($translations), 'locale' => wp_json_encode($locales), 'all' => wp_json_encode(true)), '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/plugins/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&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.', 'learn_press') . ' ' . __('(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)', 'learn_press'), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE);
        $raw_response = wp_remote_post($http_url, $options);
    }
    $response = json_decode(wp_remote_retrieve_body($raw_response), true);
    //print_r($response);
}
Exemplo n.º 9
0
/**
 * 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
 * @uses $wp_version Used to notify the WordPress version.
 *
 * @param array $extra_stats Extra statistics to report to the WordPress.org API.
 */
function wp_update_themes($extra_stats = array())
{
    if (wp_installing()) {
        return;
    }
    global $wp_version;
    // 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;
    /**
     * Filter the locales requested for theme translations.
     *
     * @since 3.7.0
     *
     * @param array $locales Theme locale. Default is current locale of the site.
     */
    $locales = apply_filters('themes_update_check_locales', array(get_locale()));
    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&#8217;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);
}
Exemplo n.º 10
0
/**
 * 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.
 *
 * @package WordPress
 * @since 2.7.0
 * @uses $wp_version Used to notify the WordPress version.
 *
 * @return mixed Returns null if update is unsupported. Returns false if check is too soon.
 */
function wp_update_themes() {
	include ABSPATH . WPINC . '/version.php'; // include an unmodified $wp_version

	if ( defined( 'WP_INSTALLING' ) )
		return false;

	$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 :
			$timeout = 12 * HOUR_IN_SECONDS;
	}

	$time_not_changed = isset( $last_update->last_checked ) && $timeout > ( time() - $last_update->last_checked );

	if ( $time_not_changed ) {
		$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 false;
	}

	// 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( get_locale() );
	/**
	 * Filter the locales requested for theme translations.
	 *
	 * @since 3.7.0
	 *
	 * @param array $locales Theme locale. Default is current locale of the site.
	 */
	$locales = apply_filters( 'themes_update_check_locales', $locales );

	$options = array(
		'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
		'body' => array(
			'themes'       => json_encode( $request ),
			'translations' => json_encode( $translations ),
			'locale'       => json_encode( $locales ),
		),
		'user-agent'	=> 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
	);

	$url = 'http://api.wordpress.org/themes/update-check/1.1/';
	if ( wp_http_supports( array( 'ssl' ) ) )
		$url = set_url_scheme( $url, 'https' );

	$raw_response = wp_remote_post( $url, $options );

	if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) )
		return false;

	$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 );
}
Exemplo n.º 11
0
 /**
  * Return a list of installed languages.
  *
  * @return array
  */
 protected function get_installed_languages()
 {
     $available = wp_get_installed_translations($this->obj_type);
     $available = !empty($available['default']) ? array_keys($available['default']) : array();
     $available[] = 'en_US';
     return $available;
 }
Exemplo n.º 12
0
function check_for_detheme_plugins_update()
{
    include ABSPATH . WPINC . '/version.php';
    // include an unmodified $wp_version
    if (defined('WP_INSTALLING')) {
        return false;
    }
    $tm = wp_get_theme();
    $theme_name = $tm->get('Name');
    $theme_template = $tm->get_template();
    $sn = get_option("detheme_license_" . $tm->get_template());
    if (empty($sn)) {
        return false;
    }
    // If running blog-side, bail unless we've not checked in the last 12 hours
    if (!function_exists('get_plugins')) {
        require_once ABSPATH . 'wp-admin/includes/plugin.php';
    }
    $plugins = get_plugins();
    $translations = wp_get_installed_translations('plugins');
    $active = get_option('active_plugins', array());
    $current = get_site_transient('detheme_update_plugins');
    if (!is_object($current)) {
        $current = new stdClass();
    }
    $new_option = new stdClass();
    $new_option->last_checked = time();
    // 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-plugins.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($current->last_checked) && $timeout > time() - $current->last_checked;
    if ($time_not_changed) {
        return false;
    }
    $updates = array();
    foreach ($plugins as $file => $p) {
        if (preg_match("/(detheme.com)/i", $p['AuthorURI'])) {
            $updates[$file] = $p;
        }
    }
    if (!count($updates)) {
        $new_option->response = array();
        $new_option->translations = array();
        set_site_transient('detheme_update_plugins', $new_option);
        return false;
    }
    $current->last_checked = time();
    set_site_transient('detheme_update_plugins', $current);
    $locales = array(get_locale());
    /**
     * Filter the locales requested for plugin translations.
     *
     * @since 3.7.0
     *
     * @param array $locales Plugin locale. Default is current locale of the site.
     */
    $locales = apply_filters('plugins_update_check_locales', $locales);
    $options = array('timeout' => defined('DOING_CRON') && DOING_CRON ? 30 : 3, 'body' => array('plugins' => json_encode($updates), 'translations' => json_encode($translations), 'locale' => json_encode($locales), 'license' => $sn), 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo('url'));
    $url = $http_url = 'http://repo.detheme.com/plugin/';
    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)) {
        $raw_response = wp_remote_post($http_url, $options);
    }
    if (is_wp_error($raw_response) || 200 != wp_remote_retrieve_response_code($raw_response)) {
        return false;
    }
    $response = json_decode(wp_remote_retrieve_body($raw_response), true);
    if (is_array($response)) {
        foreach ($response['plugins'] as &$plugin) {
            $plugin = (object) $plugin;
        }
        unset($plugin);
        $new_option->response = $response['plugins'];
        $new_option->translations = '';
    } else {
        $new_option->response = array();
        $new_option->translations = array();
    }
    set_site_transient('detheme_update_plugins', $new_option);
}
 /**
  * Uninstall a given language.
  *
  * <language>
  * : Language code to uninstall.
  *
  * @subcommand uninstall
  */
 public function uninstall($args, $assoc_args)
 {
     global $wp_filesystem;
     list($language_code) = $args;
     $available = wp_get_installed_translations($this->obj_type);
     $available = !empty($available['default']) ? array_keys($available['default']) : array();
     if (!in_array($language_code, $available)) {
         \WP_CLI::error("Language not installed.");
     }
     $dir = 'core' === $this->obj_type ? '' : "/{$this->obj_type}";
     $files = scandir(WP_LANG_DIR . $dir);
     if (!$files) {
         \WP_CLI::error("No files found in language directory.");
     }
     // As of WP 4.0, no API for deleting a language pack
     WP_Filesystem();
     $deleted = false;
     foreach ($files as $file) {
         if ('.' === $file[0] || is_dir($file)) {
             continue;
         }
         $extension_length = strlen($language_code) + 4;
         $ending = substr($file, -$extension_length);
         if (!in_array($file, array($language_code . '.po', $language_code . '.mo')) && !in_array($ending, array('-' . $language_code . '.po', '-' . $language_code . '.mo'))) {
             continue;
         }
         $deleted = $wp_filesystem->delete(WP_LANG_DIR . $dir . '/' . $file);
     }
     if ($deleted) {
         \WP_CLI::success("Language uninstalled.");
     } else {
         \WP_CLI::error("Couldn't uninstall language.");
     }
 }
 /**
  * Filter a list of translation updates and return a new list that contains only updates
  * that apply to the current site.
  *
  * @param array $translations
  * @return array
  */
 private function filterApplicableTranslations($translations)
 {
     $languages = array_flip(array_values(get_available_languages()));
     $installedTranslations = wp_get_installed_translations('plugins');
     if (isset($installedTranslations[$this->slug])) {
         $installedTranslations = $installedTranslations[$this->slug];
     } else {
         $installedTranslations = array();
     }
     $applicableTranslations = array();
     foreach ($translations as $translation) {
         //Does it match one of the available core languages?
         $isApplicable = array_key_exists($translation->language, $languages);
         //Is it more recent than an already-installed translation?
         if (isset($installedTranslations[$translation->language])) {
             $updateTimestamp = strtotime($translation->updated);
             $installedTimestamp = strtotime($installedTranslations[$translation->language]['PO-Revision-Date']);
             $isApplicable = $updateTimestamp > $installedTimestamp;
         }
         if ($isApplicable) {
             $applicableTranslations[] = $translation;
         }
     }
     return $applicableTranslations;
 }