WC_Install::theme_background_installer() – Install a theme from .org in the background via a cron job (used by installer – opt in).

You appear to be a bot. Output may be restricted

Description

Install a theme from .org in the background via a cron job (used by installer – opt in).

Usage

WC_Install::theme_background_installer( $theme_slug );

Parameters

$theme_slug
( string ) required – Theme slug.

Returns

void

Source

File name: woocommerce/includes/class-wc-install.php
Lines:

1 to 56 of 56
  public static function theme_background_installer( $theme_slug ) {
    // Explicitly clear the event.
    $args = func_get_args();

    if ( ! empty( $theme_slug ) ) {
      // Suppress feedback.
      ob_start();

      try {
        $theme = wp_get_theme( $theme_slug );

        if ( ! $theme->exists() ) {
          require_once ABSPATH . 'wp-admin/includes/file.php';
          include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
          include_once ABSPATH . 'wp-admin/includes/theme.php';

          WP_Filesystem();

          $skin     = new Automatic_Upgrader_Skin();
          $upgrader = new Theme_Upgrader( $skin );
          $api      = themes_api(
            'theme_information',
            array(
              'slug'   => $theme_slug,
              'fields' => array( 'sections' => false ),
            )
          );
          $result   = $upgrader->install( $api->download_link );

          if ( is_wp_error( $result ) ) {
            throw new Exception( $result->get_error_message() );
          } elseif ( is_wp_error( $skin->result ) ) {
            throw new Exception( $skin->result->get_error_message() );
          } elseif ( is_null( $result ) ) {
            throw new Exception( 'Unable to connect to the filesystem. Please confirm your credentials.' );
          }
        }

        switch_theme( $theme_slug );
      } catch ( Exception $e ) {
        WC_Admin_Notices::add_custom_notice(
          $theme_slug . '_install_error',
          sprintf(
            // translators: 1: theme slug, 2: error message, 3: URL to install theme manually.
            __( '%1$s could not be installed (%2$s). <a href="%3$s">Please install it manually by clicking here.</a>', 'woocommerce' ),
            $theme_slug,
            $e->getMessage(),
            esc_url( admin_url( 'update.php?action=install-theme&theme=' . $theme_slug . '&_wpnonce=' . wp_create_nonce( 'install-theme_' . $theme_slug ) ) )
          )
        );
      }

      // Discard feedback.
      ob_end_clean();
    }
  }
 

 View on GitHub View on Trac