Skip to content

Commit 623f7a1

Browse files
committed
Add plugin and theme update options
1 parent 5f5aed7 commit 623f7a1

File tree

5 files changed

+58
-49
lines changed

5 files changed

+58
-49
lines changed

plugin/assets/css/src/settings/updater.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@
1919
border-radius: 8px;
2020
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
2121
margin-bottom: 15px;
22+
23+
&.no__last-update .mdc-typography--headline6 {
24+
margin-bottom: 0;
25+
}
2226
}

plugin/assets/src/settings/components/integrations/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const Integrations = () => {
7878
checked={ state.updaters[ key ].autoUpdates }
7979
lastUpdated={ state.updaters[ key ].lastUpdated }
8080
type={ UPDATERS[ key ].type }
81+
displayUpdatedOn={ UPDATERS[ key ].displayUpdatedOn }
8182
/>
8283
) ) }
8384
</div>

plugin/assets/src/settings/components/integrations/updater.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
/**
1818
* External dependencies
1919
*/
20+
import classNames from 'classnames';
2021
import _uniqueId from 'lodash/uniqueId';
2122

2223
/**
@@ -35,7 +36,14 @@ import Switch from './switch';
3536
import Button from '../../../wizard/components/navigation/button';
3637
import { update, toggleAutoUpdate } from '../../utils';
3738

38-
const Updater = ( { title, lastUpdated, needsKey, checked, type } ) => {
39+
const Updater = ( {
40+
title,
41+
lastUpdated,
42+
needsKey,
43+
checked,
44+
type,
45+
displayUpdatedOn,
46+
} ) => {
3947
const [ id ] = useState( _uniqueId( 'updater-' ) );
4048
const { state, dispatch } = useContext( SettingsContext );
4149
const isDisabled = needsKey && 'ok' !== state.apiStatus;
@@ -80,7 +88,11 @@ const Updater = ( { title, lastUpdated, needsKey, checked, type } ) => {
8088
};
8189

8290
return (
83-
<div className="material-settings__updater">
91+
<div
92+
className={ classNames( 'material-settings__updater', {
93+
'no__last-update': false === displayUpdatedOn,
94+
} ) }
95+
>
8496
<div className="mdc-layout-grid">
8597
<div className="mdc-layout-grid__inner">
8698
<div className="mdc-layout-grid__cell mdc-layout-grid__cell--span-7 mdc-layout-grid__cell--align-middle">
@@ -104,7 +116,7 @@ const Updater = ( { title, lastUpdated, needsKey, checked, type } ) => {
104116
></p>
105117
) }
106118

107-
{ ! isDisabled && (
119+
{ ! isDisabled && false !== displayUpdatedOn && (
108120
<p className="mdc-typography--body1">
109121
{ sprintf(
110122
__( 'Last update on %s', 'material-design' ),

plugin/assets/src/settings/constants.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ export const UPDATERS = {
5151
updateAvailable: 'update' === getConfig( 'iconsUpdateStatus' ),
5252
autoUpdates: parseInt( getConfig( 'iconsAutoUpdate' ), 10 ),
5353
},
54+
PLUGIN: {
55+
title: __( 'Material Design Plugin', 'material-design' ),
56+
type: 'PLUGIN',
57+
lastUpdated: false,
58+
needsKey: false,
59+
updateAvailable: 1 === parseInt( getConfig( 'pluginUpdateStatus' ), 10 ),
60+
autoUpdates: parseInt( getConfig( 'pluginAutoUpdate' ), 10 ),
61+
displayUpdatedOn: false,
62+
},
63+
THEME: {
64+
title: __( 'Material Design Theme', 'material-design' ),
65+
type: 'THEME',
66+
lastUpdated: false,
67+
needsKey: false,
68+
updateAvailable: 1 === parseInt( getConfig( 'themeUpdateStatus' ), 10 ),
69+
autoUpdates: parseInt( getConfig( 'themeAutoUpdate' ), 10 ),
70+
displayUpdatedOn: false,
71+
},
5472
};
5573

5674
export const KEY_PLACEHOLDER = '•••••••••••••••••••••••••••••';

plugin/php/class-admin.php

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ public function init() {
4040
add_action( 'switch_theme', [ $this, 'switch_theme_material' ], 10, 2 );
4141
add_action( 'admin_notices', [ $this, 'theme_not_installed_notice' ], 10, 2 );
4242
add_action( 'admin_notices', [ $this, 'plugin_activated_notice' ], 9, 2 );
43-
add_filter( 'auto_update_plugin', [ $this, 'enable_plugin_auto_update' ], 10, 2 );
44-
add_filter( 'auto_update_theme', [ $this, 'enable_theme_auto_update' ], 10, 2 );
4543
}
4644

4745
/**
@@ -291,22 +289,30 @@ public function enqueue_assets() {
291289
true
292290
);
293291

292+
$plugin_file = 'material-design/material-design.php';
293+
$plugin_updates = get_site_transient( 'update_plugins' );
294+
$theme_updates = get_site_transient( 'update_themes' );
295+
294296
wp_localize_script(
295297
'material-settings',
296298
'materialDesignWizard',
297299
[
298-
'restPath' => esc_url( $this->plugin->onboarding_rest_controller->get_base_path() ),
299-
'redirect' => esc_url( admin_url( 'themes.php' ) ),
300-
'nonce' => wp_create_nonce( 'wp_rest' ),
301-
'themeStatus' => esc_html( $this->plugin->theme_status() ),
302-
'assetsRestPath' => esc_url( $this->plugin->assets_rest_controller->get_base_path() ),
303-
'apiStatus' => esc_html( $this->plugin->assets_rest_controller->get_api_status() ),
304-
'fontsLastUpdated' => esc_html( $this->plugin->assets_rest_controller->get_fonts_last_updated() ),
305-
'iconsLastUpdated' => esc_html( $this->plugin->assets_rest_controller->get_icons_last_updated() ),
306-
'fontsAutoUpdate' => esc_html( $this->plugin->assets_rest_controller->get_fonts_auto_update() ),
307-
'iconsAutoUpdate' => esc_html( $this->plugin->assets_rest_controller->get_icons_auto_update() ),
308-
'fontsUpdateStatus' => esc_html( $this->plugin->assets_rest_controller->get_fonts_update_status() ),
309-
'iconsUpdateStatus' => esc_html( $this->plugin->assets_rest_controller->get_icons_update_status() ),
300+
'restPath' => esc_url( $this->plugin->onboarding_rest_controller->get_base_path() ),
301+
'redirect' => esc_url( admin_url( 'themes.php' ) ),
302+
'nonce' => wp_create_nonce( 'wp_rest' ),
303+
'themeStatus' => esc_html( $this->plugin->theme_status() ),
304+
'assetsRestPath' => esc_url( $this->plugin->assets_rest_controller->get_base_path() ),
305+
'apiStatus' => esc_html( $this->plugin->assets_rest_controller->get_api_status() ),
306+
'fontsLastUpdated' => esc_html( $this->plugin->assets_rest_controller->get_fonts_last_updated() ),
307+
'iconsLastUpdated' => esc_html( $this->plugin->assets_rest_controller->get_icons_last_updated() ),
308+
'fontsAutoUpdate' => esc_html( $this->plugin->assets_rest_controller->get_fonts_auto_update() ),
309+
'iconsAutoUpdate' => esc_html( $this->plugin->assets_rest_controller->get_icons_auto_update() ),
310+
'fontsUpdateStatus' => esc_html( $this->plugin->assets_rest_controller->get_fonts_update_status() ),
311+
'iconsUpdateStatus' => esc_html( $this->plugin->assets_rest_controller->get_icons_update_status() ),
312+
'pluginAutoUpdate' => in_array( 'material-design/material-design.php', get_site_option( 'auto_update_plugins', [] ), true ),
313+
'themeAutoUpdate' => in_array( Plugin::THEME_SLUG, get_site_option( 'auto_update_themes', [] ), true ),
314+
'pluginUpdateStatus' => isset( $plugin_updates->response[ $plugin_file ] ) ? 1 : 0,
315+
'pluginUpdateStatus' => isset( $theme_updates->response[ Plugin::THEME_SLUG ] ) ? 1 : 0,
310316
]
311317
);
312318
}
@@ -462,36 +468,4 @@ public function plugin_activated_notice() {
462468
)
463469
);
464470
}
465-
466-
/**
467-
* Enable auto updates for the plugin.
468-
*
469-
* @param bool|null $update Whether to update.
470-
* @param object $item The update offer.
471-
*
472-
* @return bool
473-
*/
474-
public function enable_plugin_auto_update( $update, $item ) {
475-
if ( 'material-design' === $item->slug ) {
476-
return true;
477-
}
478-
479-
return $update;
480-
}
481-
482-
/**
483-
* Enable auto updates for the theme.
484-
*
485-
* @param bool|null $update Whether to update.
486-
* @param object $item The update offer.
487-
*
488-
* @return bool
489-
*/
490-
public function enable_theme_auto_update( $update, $item ) {
491-
if ( Plugin::THEME_SLUG === $item->slug ) {
492-
return true;
493-
}
494-
495-
return $update;
496-
}
497471
}

0 commit comments

Comments
 (0)