',
$theme_name
)
);
}
echo $enclosure['close'];
do_action( "in_theme_update_message-$theme_key", $theme, $response );
}
}
/**
* Create branch switcher row for multisite installation.
*
* @param string $theme_key
* @param array $theme
*
* @return bool
*/
public function multisite_branch_switcher( $theme_key, $theme ) {
if ( empty( static::$options['branch_switch'] ) ) {
return false;
}
$enclosure = $this->update_row_enclosure( $theme_key, 'theme', true );
$id = $theme_key . '-id';
$branches = isset( $this->config[ $theme_key ]->branches )
? $this->config[ $theme_key ]->branches
: null;
$nonced_update_url = wp_nonce_url(
$this->get_update_url( 'theme', 'upgrade-theme', $theme_key ),
'upgrade-theme_' . $theme_key
);
// Get current branch.
$repo = $this->config[ $theme_key ];
$branch = Singleton::get_instance( 'Branch', $this )->get_current_branch( $repo );
$branch_switch_data = [];
$branch_switch_data['slug'] = $theme_key;
$branch_switch_data['nonced_update_url'] = $nonced_update_url;
$branch_switch_data['id'] = $id;
$branch_switch_data['branch'] = $branch;
$branch_switch_data['branches'] = $branches;
/*
* Create after_theme_row_
*/
echo $enclosure['open'];
$this->make_branch_switch_row( $branch_switch_data );
echo $enclosure['close'];
return true;
}
/**
* Remove default after_theme_row_$stylesheet.
*
* @author @grappler
*
* @param string $theme_key
* @param array $theme
*/
public function remove_after_theme_row( $theme_key, $theme ) {
$themes = $this->get_theme_configs();
foreach ( static::$git_servers as $server ) {
$repo_header = $server . ' Theme URI';
$repo_uri = $theme->get( $repo_header );
/**
* Filter to add themes not containing appropriate header line.
*
* @since 5.4.0
* @access public
*
* @param array $additions Listing of themes to add.
* Default null.
* @param array $themes Listing of all themes.
* @param string 'theme' Type being passed.
*/
$additions = apply_filters( 'github_updater_additions', null, $themes, 'theme' );
foreach ( (array) $additions as $addition ) {
if ( $theme_key === $addition['slug'] ) {
if ( ! empty( $addition[ $server . ' Theme URI' ] ) ) {
$repo_uri = $addition[ $server . ' Theme URI' ];
break;
}
}
}
if ( empty( $repo_uri ) ) {
continue;
}
break;
}
if ( array_key_exists( $theme_key, $themes ) ) {
remove_action( "after_theme_row_$theme_key", 'wp_theme_update_row' );
}
}
/**
* Call theme messaging for single site installation.
*
* @author Seth Carstens
*
* @param array $prepared_themes
*
* @return mixed
*/
public function customize_theme_update_html( $prepared_themes ) {
foreach ( (array) $this->config as $theme ) {
if ( empty( $prepared_themes[ $theme->slug ] ) ) {
continue;
}
if ( ! empty( $prepared_themes[ $theme->slug ]['hasUpdate'] ) ) {
$prepared_themes[ $theme->slug ]['update'] = $this->append_theme_actions_content( $theme );
} else {
$prepared_themes[ $theme->slug ]['description'] .= $this->append_theme_actions_content( $theme );
}
if ( ! $theme->release_asset ) {
$prepared_themes[ $theme->slug ]['description'] .= $this->single_install_switcher( $theme );
}
}
return $prepared_themes;
}
/**
* Create theme update messaging for single site installation.
*
* @author Seth Carstens
*
* @access protected
*
* @param \stdClass $theme
*
* @return string (content buffer)
*/
protected function append_theme_actions_content( $theme ) {
$details_url = esc_attr(
add_query_arg(
[
'tab' => 'theme-information',
'theme' => $theme->slug,
'TB_iframe' => 'true',
'width' => 270,
'height' => 400,
],
self_admin_url( 'theme-install.php' )
)
);
$nonced_update_url = wp_nonce_url(
$this->get_update_url( 'theme', 'upgrade-theme', $theme->slug ),
'upgrade-theme_' . $theme->slug
);
$current = get_site_transient( 'update_themes' );
/**
* Display theme update links.
*/
ob_start();
if ( isset( $current->response[ $theme->slug ] ) ) {
?>
name
);
printf(
' ',
$details_url,
esc_attr( $theme->name )
);
printf(
/* translators: 1: version number, 2: closing anchor tag, 3: update URL */
esc_html__( 'View version %1$s details%2$s or %3$supdate now%2$s.', 'github-updater' ),
$theme->remote_version = isset( $theme->remote_version ) ? $theme->remote_version : null,
'',
sprintf(
/* translators: %s: theme name */
'',
$theme->name
)
);
?>
get_update_url( 'theme', 'upgrade-theme', $theme->slug ),
'upgrade-theme_' . $theme->slug
);
$rollback_url = sprintf( '%s%s', $nonced_update_url, '&rollback=' );
if ( ! isset( static::$options['branch_switch'] ) ) {
return;
}
ob_start();
if ( '1' === static::$options['branch_switch'] ) {
printf(
/* translators: 1: branch name, 2: jQuery dropdown, 3: closing tag */
'' . esc_html__( 'Current branch is `%1$s`, try %2$sanother version%3$s', 'github-updater' ),
$theme->branch,
'',
'.
'
);
?>
';
}
?>
config as $theme ) {
if ( $this->can_update_repo( $theme ) ) {
$response = [
'theme' => $theme->slug,
'new_version' => $theme->remote_version,
'url' => $theme->uri,
'package' => $theme->download_link,
'branch' => $theme->branch,
'branches' => array_keys( $theme->branches ),
'type' => "{$theme->git}-{$theme->type}",
];
// Skip on RESTful updating.
if ( isset( $_GET['action'], $_GET['theme'] ) &&
'github-updater-update' === $_GET['action'] &&
$response['theme'] === $_GET['theme']
) {
continue;
}
// Pull update from dot org if not overriding.
if ( ! $this->override_dot_org( 'theme', $theme ) ) {
continue;
}
$transient->response[ $theme->slug ] = $response;
} else {
/**
* Filter to return array of overrides to dot org.
*
* @since 8.5.0
* @return array
*/
$overrides = apply_filters( 'github_updater_override_dot_org', [] );
if ( isset( $transient->response[ $theme->slug ] ) && in_array( $theme->slug, $overrides, true ) ) {
unset( $transient->response[ $theme->slug ] );
}
}
// Set transient for rollback.
if ( isset( $_GET['theme'], $_GET['rollback'] ) && $theme->slug === $_GET['theme']
) {
$transient->response[ $theme->slug ] = $this->set_rollback_transient( 'theme', $theme );
}
}
return $transient;
}
}