• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress core a2z

WordPress core a2z

WordPress core only

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / Theme_Upgrader::check_parent_theme_filter() – Check if a child theme is being installed and we need to install its parent.

You appear to be a bot. Output may be restricted

Description

Check if a child theme is being installed and we need to install its parent.

Hooked to the upgrader_post_install filter by Theme_Upgrader::install().

Usage

$bool = Theme_Upgrader::check_parent_theme_filter( $install_result, $hook_extra, $child_result );

Parameters

$install_result
( bool ) required –
$hook_extra
( array ) required –
$child_result
( array ) required –

Returns

bool

Source

File name: wordpress/wp-admin/includes/class-theme-upgrader.php
Lines:

1 to 72 of 72
  public function check_parent_theme_filter( $install_result, $hook_extra, $child_result ) {
    // Check to see if we need to install a parent theme.
    $theme_info = $this->Theme_Upgrader::theme_info();

    if ( ! $theme_info->parent() ) {
      return $install_result;
    }

    $this->skin->feedback( 'parent_theme_search' );

    if ( ! $theme_info->parent()->errors() ) {
      $this->skin->feedback( 'parent_theme_currently_installed', $theme_info->parent()->display( 'Name' ), $theme_info->parent()->display( 'Version' ) );
      // We already have the theme, fall through.
      return $install_result;
    }

    // We don't have the parent theme, let's install it.
    $api = themes_api(
      'theme_information',
      array(
        'slug'   => $theme_info->get( 'Template' ),
        'fields' => array(
          'sections' => false,
          'tags'     => false,
        ),
      )
    ); // Save on a bit of bandwidth.

    if ( ! $api || is_wp_error( $api ) ) {
      $this->skin->feedback( 'parent_theme_not_found', $theme_info->get( 'Template' ) );
      // Don't show activate or preview actions after installation.
      add_filter( 'install_theme_complete_actions', array( $this, 'hide_activate_preview_actions' )  < );
      return $install_result;
    }

    // Backup required data we're going to override:
    $child_api             = $this->skin->api;
    $child_success_message = $this->strings['process_success'];

    // Override them.
    $this->skin->api = $api;

    $this->strings['process_success_specific'] = $this->strings['parent_theme_install_success'];

    $this->skin->feedback( 'parent_theme_prepare_install', $api->name, $api->version );

    add_filter( 'install_theme_complete_actions', '__return_false',  < 999 ); // Don't show any actions after installing the theme.

    // Install the parent theme.
    $parent_result = $this->run(
      array(
        'package'           => $api->download_link,
        'destination'       => get_theme_root(),
        'clear_destination' => false, // Do not overwrite files.
        'clear_working'     => true,
      )
    );

    if ( is_wp_error( $parent_result ) ) {
      add_filter( 'install_theme_complete_actions', array( $this, 'hide_activate_preview_actions' )  < );
    }

    // Start cleaning up after the parent's installation.
    remove_filter( 'install_theme_complete_actions', '__return_false', 999 );

    // Reset child's result and data.
    $this->result                     = $child_result;
    $this->skin->api                  = $child_api;
    $this->strings['process_success'] = $child_success_message;

    return $install_result;
  }
 

 View on GitHub View on Trac

Published: 25th November 2019 | Last updated: 21st August 2020

Primary Sidebar

Information

Function name: Theme_Upgrader::check_parent_theme_filter
Class ref: Theme_Upgrader
Plugin ref: WordPress
Version: 5.6
Sourcefile: wp-admin/includes/class-theme-upgrader.php
File ref: wp-admin/includes/class-theme-upgrader.php
Deprecated?: No
API Letters: C,P,T,U

Footer

WP-a2z
WordPress core a2z
WordPress core only
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  core.wp-a2z.org
© Copyright WP-a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites