Skip to content
This repository was archived by the owner on May 29, 2020. It is now read-only.

Commit

Permalink
Remove theme autoupdates for the moment from the scope and add readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Jb authored and Jb committed Feb 18, 2020
1 parent f355efb commit 9367ca2
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 77 deletions.
18 changes: 14 additions & 4 deletions css/wp-autoupdates.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.theme-overlay .theme-autoupdate a {
text-decoration: none;
}

#autoupdates_column {
min-width: 200px;
}
Expand All @@ -17,4 +13,18 @@
.plugin-autoupdate-enabled,
.theme-autoupdate-enabled {
color: #006505;
}

.plugins .plugin-title .plugin-autoupdate-enabled .dashicons {
float: none;
padding: 0;
width: auto;
height: auto;
}
.plugins .plugin-title .plugin-autoupdate-enabled .dashicons:before {
padding: 0;
background: transparent;
box-shadow: none;
font-size: 20px;
color: #006505;
}
68 changes: 68 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# WordPress Autoupdates 🤖

A feature plugin to integrate Plugins & Themes automatic updates in WordPress Core.

## About 🔎

The purpose of this repository is to prepare a future Plugins & Themes automatic updates feature.

To test/contribute, just install this plugin and activate it on your WordPress installation.

## Context ⏳

In 2018, Matt Mullenweg posted 9 projects for Core to focus on in 2019. We didn’t ship as many as hoped, but we made a lot of progress. Plugins and Themes Automatic Updates were one of those 9 projects. This project is now milestoned to WordPress 5.5 and this feature plugin is here to help move towards this achievement.

- [See also: Update on the 9 projects for 2019](https://make.wordpress.org/core/2019/12/06/update-9-projects-for-2019/):
- [Related Trac ticket for plugins autoupdates](https://core.trac.wordpress.org/ticket/48850)
- [Related Trac ticket for themes autoupdates](https://core.trac.wordpress.org/ticket/48850)

## Features / to-do list 🛠

- ✅ Open a Trac ticket to handle Core merge for plugins
- ✅ Open a Trac ticket to handle Core merge for themes
- ✅ Handle plugin autoupdates
- 🔲 Handle themes autoupdates
- ✅ Handle plugin autoupdates in a multisite context
- 🔲 Handle themes autoupdates in a multisite context
- 🔲 Validate design for plugins screen
- 🔲 Validate design for themes screen
- 🔲 Validate design for update-core screen
- 🔲 Email notifications for plugins
- 🔲 Email notifications for themes
- 🔲 Documentation
- 🔲 Submit Feature Plugin on WordPress.org repository
- 🔲 Publish the feature plugin proposal
- 🔲 Get the plugin featured as beta plugin on WordPress.org
- 🔲 Open a dedicated Slack channel on Make WordPress
- 🔲 Copy review
- 🔲 Accessibility audit
- 🔲 Security audit
- 🔲 Coding standards audit
- 🔲 Inline Docs audit

## Contributors 👥

- audrasjb
- whodunitagency

## Documentation 📚

TODO.

## Screenshots 🖼

### Plugins Admin screen - screenshot

![Plugins Admin screen - screenshot](https://jeanbaptisteaudras.com/images/wp-autoupdates-togglesingleplugin-01.gif)

### Plugins Admin screen - Toggle update single plugin - screenshot

![Plugins Admin screen - Toggle update single plugin - animated screenshot](https://jeanbaptisteaudras.com/images/wp-autoupdates-plugins-01.png)

### Plugins Admin screen - Buk Edit - animated screenshot

![Plugins Admin screen - Buk Edit - animated screenshot](https://jeanbaptisteaudras.com/images/wp-autoupdates-bulkeditplugins-01.gif)

### Update Core Admin Screen

![Update Core Admin screen - screenshot](wp-autoupdates-updatecore-01.png)
147 changes: 147 additions & 0 deletions wp-autoupdates-themes-draft.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( 'Invalid request.' );
}

/**
* Enqueue styles and scripts
*/
function wp_auto_updates_styles_scripts( $hook ) {
if ( ! in_array( $hook, array( 'themes.php', 'update-core.php' ) ) ) {
return;
}
if ( 'update-core.php' === $hook ) {
$script = 'jQuery( document ).ready(function() {';
if ( wp_is_themes_auto_update_enabled() ) {
$wp_auto_update_themes = get_site_option( 'wp_auto_update_themes', array() );
foreach ( $wp_auto_update_themes as $theme ) {
$next_update_time = wp_next_scheduled( 'wp_version_check' );
$time_to_next_update = human_time_diff( intval( $next_update_time ) );
$autoupdate_text = ' | <span class="theme-autoupdate-enabled">';
$autoupdate_text .= sprintf(
/* translators: Time until the next update. */
__( 'Automatic update scheduled in %s', 'wp-autoupdates' ),
$time_to_next_update
);
$autoupdate_text .= '</span> ';
$script .= 'jQuery(".check-column input[value=\'' . $theme . '\']").closest("tr").find(".plugin-title > p").append(\'' . $autoupdate_text . '\');';
}
}
$script .= '});';
wp_add_inline_script( 'jquery', $script );
}
if ( 'themes.php' === $hook ) {
if ( 'autoupdate' === esc_url( $_GET['action'] ) ) {
check_admin_referer( 'autoupdate-theme_' . $_GET['stylesheet'] );
$theme = wp_get_theme( $_GET['stylesheet'] );
$slug = $theme->get_stylesheet();
if ( ! current_user_can( 'update_themes' ) ) {
wp_die(
'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
'<p>' . __( 'Sorry, you are not allowed to enable automatic update for themes.' ) . '</p>',
403
);
}
$autoupdated_themes = get_option( 'wp_autoupdated_themes', array() );
if ( ! in_array( $slug, $autoupdated_themes, true ) ) {
$autoupdate_action = 'enable';
$autoupdated_themes[] = $slug;
} else {
$autoupdate_action = 'disable';
$autoupdated_themes = array_diff( $autoupdated_themes, array( $slug ) );
}
update_option( 'wp_autoupdated_themes', $autoupdated_themes );
wp_redirect( admin_url( 'themes.php?autoupdated=' . $autoupdate_action ) );
exit;
}
if ( wp_is_themes_auto_update_enabled() ) {
$script = 'jQuery( document ).ready(function() {';
$wp_auto_update_themes = get_site_option( 'wp_auto_update_themes', array() );
foreach ( $wp_auto_update_themes as $theme ) {
$aria_label_enabled = esc_attr__( 'Disable automatic updates', 'plugin', 'wp-autoupdates' );
$autoupdate_enabled_text = '<p class="theme-autoupdate-enabled">';
$autoupdate_enabled_text .= '<span class="dashicons dashicons-update" aria-hidden="true"></span> ' . __( 'Automatic updates enabled', 'wp-autoupdates' );
$autoupdate_enabled_text = '<br />';
if ( current_user_can( 'update_themes', $theme ) ) {
$autoupdate_enabled_text .= sprintf(
'<a href="%s" class="disable" aria-label="%s">%s</a>',
wp_nonce_url( 'plugins.php?action=autoupdate&amp;plugin=' . urlencode( $theme ) . '&amp;paged=' . $page, 'autoupdate-plugin_' . $theme ),
$aria_label,
__( 'Disable', 'wp-autoupdates' )
);
}
$autoupdate_enabled_text .= '</p>';
$script .= 'jQuery(".check-column input[value=\'' . $theme . '\']").closest("tr").find(".plugin-title > p").append(\'' . $autoupdate_enabled_text . '\');';
}
$script .= '});';
wp_add_inline_script( 'jquery', $script );
}
}
}
add_action( 'admin_enqueue_scripts', 'wp_auto_updates_styles_scripts' );


/**
* Checks whether themes manual autoupdate is enabled.
*/
function wp_is_themes_auto_update_enabled() {
$enabled = ! defined( 'WP_DISABLE_THEMES_AUTO_UPDATE' ) || ! WP_DISABLE_THEMES_AUTO_UPDATE;

/**
* Filters whether themes manual autoupdate is enabled.
*
* @param bool $enabled True if themes auto udpate is enabled, false otherwise.
*/
return apply_filters( 'wp_themes_auto_update_enabled', $enabled );
}

/**
* Autoupdate selected themes.
*/
function wp_auto_update_theme( $update, $item ) {
$wp_auto_update_themes = get_site_option( 'wp_auto_update_themes', array() );
if ( in_array( $item->theme, $wp_auto_update_themes, true ) && wp_is_themes_auto_update_enabled() ) {
return true;
} else {
return $update;
}
}
add_filter( 'auto_update_theme', 'wp_auto_update_theme', 10, 2 );

/**
* Filter the themes prepared for JavaScript, for themes.php.
*/
function wp_filter_themes_for_js( $prepared_themes ) {
$autoupdated_themes = get_option( 'wp_autoupdated_themes', array() );
foreach( $autoupdated_themes as $theme ) {
$slug = $theme['id'];
$encoded_slug = urlencode( $slug );
if ( in_array( $slug, $autoupdated_themes, true ) ) {
$theme['autoupdated'] = true;
$theme['actions']['autoupdate'] = current_user_can( 'update_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=autoupdate&amp;stylesheet=' . $encoded_slug ), 'autoupdate-theme_' . $slug ) : null;
}
}
return $prepared_themes;
}
add_filter( 'wp_prepare_themes_for_js', 'wp_filter_themes_for_js' );

/**
* Auto-update notices
*/
function wp_autoupdates_themes_notices() {
// Themes screen
if ( isset( $_GET['autoupdated'] ) ) {
$autoupdated_themes = get_option( 'wp_autoupdated_themes', array() );
$autoupdate_notice = __( 'The selected theme won’t update automatically anymore.' );
if ( 'enable' === $_GET['autoupdated'] ) {
echo '<div id="message" class="updated notice is-dismissible"><p>';
_e( 'The selected theme will now update automatically.', 'wp-autoupdates' );
echo '</p></div>';
} else {
echo '<div id="message" class="updated notice is-dismissible"><p>';
_e( 'The selected theme won’t automatically update anymore.', 'wp-autoupdates' );
echo '</p></div>';
}
}
}
add_action( 'admin_notices', 'wp_autoupdates_themes_notices' );
Loading

0 comments on commit 9367ca2

Please sign in to comment.