Skip to content

Commit faaf295

Browse files
committed
Merge branch 'develop' of github.com:ampproject/amp-wp into add/sandboxing-levels
* 'develop' of github.com:ampproject/amp-wp: (41 commits) Bump eslint-plugin-jsdoc from 36.1.0 to 36.1.1 Bump lint-staged from 11.1.2 to 11.2.3 Use assertContains for array Use DependencyInjectedTestCase Add test assertions Update comments Update unit test cases Remove unwanted style, Fix notice style in mobile Revert some changes and update unit test case Bump @babel/core from 7.15.5 to 7.15.8 Fix grammar in comment Bump css-minimizer-webpack-plugin from 3.0.2 to 3.1.1 Apply suggestions from code review Remove changes from .github Bump postcss from 8.3.8 to 8.3.9 Remove template change notice from other pages Remove template change notice from other pages Add unit test case Add data removal notice to plugin description Update unit test case ...
2 parents 502873c + 68bccbf commit faaf295

24 files changed

+508
-195
lines changed

amp.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* Plugin Name: AMP
4-
* Description: An easier path to great Page Experience for everyone. Powered by AMP.
4+
* Description: An easier path to great Page Experience for everyone. Powered by AMP. <em class="amp-deletion-notice"><strong>Uninstall Note:</strong> To control whether all data from this plugin is deleted at uninstallation, first activate the plugin, go to the Other section on the Settings screen, and set the “Delete plugin data at uninstall” toggle.</em>
55
* Plugin URI: https://amp-wp.org
66
* Author: AMP Project Contributors
77
* Author URI: https://github.com/ampproject/amp-wp/graphs/contributors

assets/src/components/options-context-provider/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export function OptionsContextProvider( { children, optionsRestPath, populateDef
4242
const [ savingOptions, setSavingOptions ] = useState( false );
4343
const [ didSaveOptions, setDidSaveOptions ] = useState( false );
4444
const [ originalOptions, setOriginalOptions ] = useState( {} );
45+
const [ modifiedOptions, setModifiedOptions ] = useState( {} );
4546

4647
const { error, setError } = useContext( ErrorContext );
4748
const { setAsyncError } = useAsyncError();
@@ -162,10 +163,12 @@ export function OptionsContextProvider( { children, optionsRestPath, populateDef
162163
return;
163164
}
164165

166+
setModifiedOptions( { ...modifiedOptions, ...updates } );
167+
165168
setUpdates( {} );
166169
setDidSaveOptions( true );
167170
setSavingOptions( false );
168-
}, [ delaySave, hasErrorBoundary, optionsRestPath, setAsyncError, originalOptions, setError, updates ] );
171+
}, [ delaySave, hasErrorBoundary, optionsRestPath, setAsyncError, originalOptions, setError, updates, modifiedOptions ] );
169172

170173
/**
171174
* Updates options in state.
@@ -200,6 +203,7 @@ export function OptionsContextProvider( { children, optionsRestPath, populateDef
200203
updateOptions,
201204
readerModeWasOverridden,
202205
setReaderModeWasOverridden,
206+
modifiedOptions,
203207
}
204208
}
205209
>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
import { useContext } from '@wordpress/element';
5+
import { __ } from '@wordpress/i18n';
6+
7+
/**
8+
* Internal dependencies
9+
*/
10+
import { AMPSettingToggle } from '../components/amp-setting-toggle';
11+
import { Options } from '../components/options-context-provider';
12+
import { Loading } from '../components/loading';
13+
14+
/**
15+
* Data deletion at uninstallation toggle on the settings page.
16+
*/
17+
export function DeleteDataAtUninstall() {
18+
const { editedOptions, fetchingOptions, updateOptions } = useContext( Options );
19+
20+
if ( fetchingOptions ) {
21+
return <Loading />;
22+
}
23+
24+
const deleteDataAtUninstall = editedOptions?.delete_data_at_uninstall;
25+
return (
26+
<section className="delete-data-at-uninstall">
27+
<AMPSettingToggle
28+
checked={ true === deleteDataAtUninstall }
29+
title={ __( 'Delete plugin data at uninstall', 'amp' ) }
30+
onChange={ () => {
31+
updateOptions( { delete_data_at_uninstall: ! deleteDataAtUninstall } );
32+
} }
33+
/>
34+
<p>
35+
{ __( 'When you uninstall the plugin you have the choice of whether its data should also be deleted. Examples of plugin data include the settings, validated URLs, and transients used to store image dimensions and parsed stylesheets.', 'amp' ) }
36+
</p>
37+
</section>
38+
);
39+
}

assets/src/settings-page/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import { Analytics } from './analytics';
4848
import { PairedUrlStructure } from './paired-url-structure';
4949
import { MobileRedirection } from './mobile-redirection';
5050
import { DeveloperTools } from './developer-tools';
51+
import { DeleteDataAtUninstall } from './delete-data-at-uninstall';
5152

5253
const { ajaxurl: wpAjaxUrl } = global;
5354

@@ -250,6 +251,7 @@ function Root( { appRoot } ) {
250251
>
251252
<MobileRedirection />
252253
<DeveloperTools />
254+
<DeleteDataAtUninstall />
253255
</AMPDrawer>
254256
<SettingsFooter />
255257
</form>

assets/src/settings-page/settings-footer.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
* External dependencies
33
*/
44
import PropTypes from 'prop-types';
5+
import {
6+
HAS_PAGE_CACHING,
7+
} from 'amp-settings';
58

69
/**
710
* WordPress dependencies
@@ -52,7 +55,7 @@ ErrorNotice.propTypes = {
5255
* The bottom section of the settings page.
5356
*/
5457
export function SettingsFooter() {
55-
const { didSaveOptions, editedOptions, hasOptionsChanges, savingOptions } = useContext( Options );
58+
const { didSaveOptions, editedOptions, hasOptionsChanges, savingOptions, modifiedOptions } = useContext( Options );
5659
const { downloadingTheme } = useContext( ReaderThemes );
5760
const { error } = useContext( ErrorContext );
5861
const { didSaveDeveloperToolsOption, hasDeveloperToolsOptionChange, savingDeveloperToolsOption } = useContext( User );
@@ -63,6 +66,8 @@ export function SettingsFooter() {
6366
const isBusy = savingOptions || downloadingTheme || savingDeveloperToolsOption;
6467
const disabled = ! hasChanges || isBusy || ! themeSupport || ( READER === themeSupport && ! readerTheme );
6568

69+
const shouldShowPageCacheFlushNotice = ( modifiedOptions?.theme_support || modifiedOptions?.reader_theme );
70+
6671
return (
6772
<section className="amp-settings-nav">
6873
<div className="amp-settings-nav__inner">
@@ -79,7 +84,20 @@ export function SettingsFooter() {
7984
type={ NOTICE_TYPE_SUCCESS }
8085
>
8186
<p>
82-
{ __( 'Saved', 'amp' ) }
87+
{
88+
HAS_PAGE_CACHING && shouldShowPageCacheFlushNotice ? (
89+
<>
90+
{ __( 'Saved. Consider flushing page cache.', 'amp' ) + ' ' }
91+
<a
92+
href="https://amp-wp.org/documentation/getting-started/amp-site-setup/page-caching-with-amp-and-wordpress/"
93+
target="_blank"
94+
rel="noreferrer noopener"
95+
>
96+
{ __( 'Learn More', 'amp' ) }
97+
</a>
98+
</>
99+
) : __( 'Saved', 'amp' )
100+
}
83101
</p>
84102
</AMPNotice>
85103
) }

assets/src/settings-page/style.css

+12-6
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,21 @@ li.error-kept {
301301
.amp .amp-save-success-notice.amp-notice,
302302
.amp-error-notice .amp-notice {
303303
bottom: 3rem;
304+
margin-left: 0.5rem;
304305
padding-left: 1.5rem;
305-
padding-right: 3rem;
306+
padding-right: .5rem;
306307
z-index: 99;
307308
}
308309

310+
@media (min-width: 576px) {
311+
312+
.amp .amp-save-success-notice.amp-notice,
313+
.amp-error-notice .amp-notice {
314+
margin-left: 0;
315+
padding-right: 3rem;
316+
}
317+
}
318+
309319
.amp-settings-nav .components-button.is-primary {
310320
box-shadow: none;
311321
}
@@ -610,10 +620,6 @@ li.error-kept {
610620
margin: 0;
611621
}
612622

613-
.amp-other-settings .developer-tools h4 {
614-
margin-bottom: 0;
615-
}
616-
617-
.amp-other-settings .developer-tools p {
623+
.amp-other-settings p {
618624
font-size: 0.875rem;
619625
}

includes/amp-helper-functions.php

+25
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ function amp_bootstrap_plugin() {
9898
add_action( 'after_setup_theme', 'amp_after_setup_theme', 5 );
9999

100100
add_action( 'plugins_loaded', '_amp_bootstrap_customizer', 9 ); // Should be hooked before priority 10 on 'plugins_loaded' to properly unhook core panels.
101+
102+
// @todo Eliminate this once https://core.trac.wordpress.org/ticket/20578 has finally landed.
103+
add_filter( 'all_plugins', 'amp_modify_plugin_description' );
101104
}
102105

103106
/**
@@ -219,6 +222,28 @@ function() {
219222
);
220223
}
221224

225+
/**
226+
* When AMP plugin is active remove instruction of plugin data removal steps.
227+
*
228+
* @since 2.2
229+
* @internal
230+
*
231+
* @param array $meta An array of plugins to display in the list table.
232+
* @return array An array of plugins to display in the list table.
233+
*/
234+
function amp_modify_plugin_description( $meta ) {
235+
236+
if ( isset( $meta['amp/amp.php']['Description'] ) ) {
237+
$meta['amp/amp.php']['Description'] = preg_replace(
238+
':\s*<em class=\"amp-deletion-notice\">.+?</em>:',
239+
'',
240+
$meta['amp/amp.php']['Description']
241+
);
242+
}
243+
244+
return $meta;
245+
}
246+
222247
/**
223248
* Set up AMP.
224249
*

includes/options/class-amp-options-manager.php

+14-9
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ class AMP_Options_Manager {
2828
* @var array
2929
*/
3030
protected static $defaults = [
31-
Option::THEME_SUPPORT => AMP_Theme_Support::READER_MODE_SLUG,
32-
Option::SUPPORTED_POST_TYPES => [ 'post', 'page' ],
33-
Option::ANALYTICS => [],
34-
Option::ALL_TEMPLATES_SUPPORTED => true,
35-
Option::SUPPORTED_TEMPLATES => [ 'is_singular' ],
36-
Option::VERSION => AMP__VERSION,
37-
Option::READER_THEME => ReaderThemes::DEFAULT_READER_THEME,
38-
Option::PAIRED_URL_STRUCTURE => Option::PAIRED_URL_STRUCTURE_QUERY_VAR,
39-
Option::PLUGIN_CONFIGURED => false,
31+
Option::THEME_SUPPORT => AMP_Theme_Support::READER_MODE_SLUG,
32+
Option::SUPPORTED_POST_TYPES => [ 'post', 'page' ],
33+
Option::ANALYTICS => [],
34+
Option::ALL_TEMPLATES_SUPPORTED => true,
35+
Option::SUPPORTED_TEMPLATES => [ 'is_singular' ],
36+
Option::VERSION => AMP__VERSION,
37+
Option::READER_THEME => ReaderThemes::DEFAULT_READER_THEME,
38+
Option::PAIRED_URL_STRUCTURE => Option::PAIRED_URL_STRUCTURE_QUERY_VAR,
39+
Option::PLUGIN_CONFIGURED => false,
40+
Option::DELETE_DATA_AT_UNINSTALL => true,
4041
];
4142

4243
/**
@@ -320,6 +321,10 @@ public static function validate_options( $new_options ) {
320321
$options[ Option::PLUGIN_CONFIGURED ] = (bool) $new_options[ OPTION::PLUGIN_CONFIGURED ];
321322
}
322323

324+
if ( isset( $new_options[ Option::DELETE_DATA_AT_UNINSTALL ] ) ) {
325+
$options[ Option::DELETE_DATA_AT_UNINSTALL ] = (bool) $new_options[ OPTION::DELETE_DATA_AT_UNINSTALL ];
326+
}
327+
323328
// Validate analytics.
324329
if ( isset( $new_options[ Option::ANALYTICS ] ) && $new_options[ Option::ANALYTICS ] !== $options[ Option::ANALYTICS ] ) {
325330
$new_analytics_option = [];

includes/uninstall-functions.php

+13-6
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ function delete_transients() {
175175

176176
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Cannot cache result since we're deleting the records.
177177
$wpdb->query(
178-
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- See use of prepare in foreach loop above.
178+
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- See use of prepare in foreach loop above.
179179
"DELETE FROM $wpdb->options WHERE " . implode( ' OR ', $where_clause )
180180
);
181181
}
@@ -187,10 +187,17 @@ function delete_transients() {
187187
* @internal
188188
*/
189189
function remove_plugin_data() {
190+
$options = get_option( 'amp-options' );
190191

191-
delete_options();
192-
delete_user_metadata();
193-
delete_posts();
194-
delete_terms();
195-
delete_transients();
192+
if (
193+
is_array( $options ) && array_key_exists( 'delete_data_at_uninstall', $options )
194+
? $options['delete_data_at_uninstall']
195+
: true
196+
) {
197+
delete_options();
198+
delete_user_metadata();
199+
delete_posts();
200+
delete_terms();
201+
delete_transients();
202+
}
196203
}

0 commit comments

Comments
 (0)