-
Notifications
You must be signed in to change notification settings - Fork 2k
/
index.jsx
687 lines (619 loc) · 18.2 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
/** @format */
/**
* External dependencies
*/
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import classNames from 'classnames';
import i18n from 'i18n-calypso';
import { get, includes, some } from 'lodash';
import Gridicon from 'gridicons';
import { localize, moment } from 'i18n-calypso';
/**
* Internal dependencies
*/
import analytics from 'lib/analytics';
import Button from 'components/button';
import Card from 'components/card';
import CompactCard from 'components/card/compact';
import Count from 'components/count';
import NoticeAction from 'components/notice/notice-action';
import ExternalLink from 'components/external-link';
import Notice from 'components/notice';
import PluginIcon from 'my-sites/plugins/plugin-icon/plugin-icon';
import PluginsActions from 'lib/plugins/actions';
import PluginActivateToggle from 'my-sites/plugins/plugin-activate-toggle';
import PluginAutoupdateToggle from 'my-sites/plugins/plugin-autoupdate-toggle';
import safeProtocolUrl from 'lib/safe-protocol-url';
import config from 'config';
import PluginInstallButton from 'my-sites/plugins/plugin-install-button';
import PluginRemoveButton from 'my-sites/plugins/plugin-remove-button';
import PluginInformation from 'my-sites/plugins/plugin-information';
import WpcomPluginInstallButton from 'my-sites/plugins/plugin-install-button-wpcom';
import PluginAutomatedTransfer from 'my-sites/plugins/plugin-automated-transfer';
import { getExtensionSettingsPath } from 'my-sites/plugins/utils';
import { userCan } from 'lib/site/utils';
import Banner from 'components/banner';
import { TYPE_BUSINESS, FEATURE_UPLOAD_PLUGINS } from 'lib/plans/constants';
import { findFirstSimilarPlanKey } from 'lib/plans';
import { isBusiness, isEnterprise } from 'lib/products-values';
import { addSiteFragment } from 'lib/route';
import { getSelectedSiteId, getSelectedSite } from 'state/ui/selectors';
import { getSiteSlug } from 'state/sites/selectors';
import isAutomatedTransferActive from 'state/selectors/is-automated-transfer-active';
import isSiteAutomatedTransfer from 'state/selectors/is-site-automated-transfer';
import QueryEligibility from 'components/data/query-atat-eligibility';
import { isATEnabled } from 'lib/automated-transfer';
import { abtest } from 'lib/abtest';
export class PluginMeta extends Component {
static OUT_OF_DATE_YEARS = 2;
static propTypes = {
siteURL: PropTypes.string,
sites: PropTypes.array,
plugin: PropTypes.object.isRequired,
isInstalledOnSite: PropTypes.bool,
isPlaceholder: PropTypes.bool,
isMock: PropTypes.bool,
allowedActions: PropTypes.shape( {
activation: PropTypes.bool,
autoupdate: PropTypes.bool,
remove: PropTypes.bool,
} ),
};
static defaultProps = {
allowedActions: {
activation: true,
autoupdate: true,
remove: true,
},
};
displayBanner() {
if (
this.props.plugin &&
this.props.plugin.banners &&
( this.props.plugin.banners.high || this.props.plugin.banners.low )
) {
return (
<div className="plugin-meta__banner">
<img
className="plugin-meta__banner-image"
src={ this.props.plugin.banners.high || this.props.plugin.banners.low }
/>
</div>
);
}
}
hasBusinessPlan() {
if ( ! this.props.selectedSite ) {
return false;
}
return (
isBusiness( this.props.selectedSite.plan ) || isEnterprise( this.props.selectedSite.plan )
);
}
getPlan() {
if ( ! this.props.selectedSite ) {
return false;
}
return this.props.selectedSite.plan();
}
isWpcomPreinstalled = () => {
const installedPlugins = [ 'Jetpack by WordPress.com', 'Akismet', 'VaultPress' ];
if ( ! this.props.selectedSite ) {
return false;
}
return (
! this.props.selectedSite.jetpack && includes( installedPlugins, this.props.plugin.name )
);
};
renderActions() {
if ( ! this.props.selectedSite ) {
/* eslint-disable wpcalypso/jsx-classname-namespace */
return (
<div className="plugin-meta__actions">
<div className="plugin-item__count">
{ this.props.translate( 'Sites {{count/}}', {
components: {
count: <Count count={ this.props.sites.length } />,
},
} ) }
</div>
</div>
);
/* eslint-enable wpcalypso/jsx-classname-namespace */
}
if ( this.props.isPlaceholder ) {
return;
}
if ( this.props.isInstalledOnSite === null && this.props.selectedSite.jetpack ) {
return;
}
if ( this.isWpcomPreinstalled() ) {
return (
<div className="plugin-meta__actions">
<Button className="plugin-meta__active" compact borderless>
<Gridicon icon="checkmark" />
{ this.props.translate( 'Active' ) }
</Button>
</div>
);
}
if ( this.props.isInstalledOnSite === false || ! this.props.selectedSite.jetpack ) {
return <div className="plugin-meta__actions"> { this.getInstallButton() } </div>;
}
const {
autoupdate: canToggleAutoupdate,
activation: canToggleActivation,
remove: canRemove,
} = this.props.allowedActions;
return (
<div className="plugin-meta__actions">
{ canToggleActivation && (
<PluginActivateToggle
plugin={ this.props.plugin }
site={ this.props.selectedSite }
isMock={ this.props.isMock }
/>
) }
{ canToggleAutoupdate && (
<PluginAutoupdateToggle
plugin={ this.props.plugin }
site={ this.props.selectedSite }
wporg={ this.props.plugin.wporg }
isMock={ this.props.isMock }
/>
) }
{ canRemove && (
<PluginRemoveButton
plugin={ this.props.plugin }
site={ this.props.selectedSite }
isMock={ this.props.isMock }
/>
) }
</div>
);
}
renderName() {
if ( ! this.props.plugin || ! this.props.plugin.name ) {
return;
}
return <div className="plugin-meta__name">{ this.props.plugin.name }</div>;
}
renderAuthorUrl() {
if (
! this.props.plugin ||
! ( this.props.plugin.author_url && this.props.plugin.author_name )
) {
return;
}
const linkToAuthor = (
<ExternalLink
className="plugin-meta__author"
href={ safeProtocolUrl( this.props.plugin.author_url ) }
target="_blank"
>
{ this.props.plugin.author_name }
</ExternalLink>
);
return this.props.translate( 'By {{linkToAuthor/}}', {
components: {
linkToAuthor,
},
} );
}
isUnsupportedPluginForAT() {
const { plugin } = this.props;
// Pressable prevents installation of some plugins, so we need to disable AT for them.
// More info here: https://kb.pressable.com/faq/does-pressable-restrict-any-plugins/
const unsupportedPlugins = [
// "reset" - break/interfere with provided functionality
'advanced-database-cleaner',
'advanced-reset-wp',
'advanced-wp-reset',
'armember-membership',
'autoptimize',
'better-wp-security',
'cf7-pipedrive-integration',
'duplicator',
'extended-wp-reset',
'google-captcha',
'file-manager-advanced',
'file-manager',
'reset-wp',
'wd-youtube',
'wordpress-database-reset',
'wordpress-reset',
'wp-automatic',
'wp-clone-by-wp-academy',
'wp-file-manager',
'wp-prefix-changer',
'wp-reset',
'wpmu-database-reset',
'z-inventory-manager',
// backup
'backup-wd',
'backupwordpress',
'backwpup',
'updraftplus',
'wp-db-backup',
// caching
'comet-cache',
'hyper-cache',
'quick-cache',
'w3-total-cache',
'wp-cache',
'wp-fastest-cache',
'wp-rocket',
'wp-super-cache',
// sql heavy
'another-wordpress-classifieds-plugin',
'leads',
'native-ads-adnow',
'ol_scrapes',
'page-visit-counter',
'post-views-counter',
'tokenad',
'top-10',
'wordpress-popular-posts',
'wp-cerber',
'wp-inject',
'wp-postviews',
'wp-rss-aggregator',
'wp-rss-feed-to-post',
'wp-rss-wordai',
'wp-statistics',
'wp-ulike',
'WPRobot5',
// security
'wordfence',
// spam
'e-mail-broadcasting',
'mailit',
'send-email-from-admin',
// cloning/staging
'wp-staging',
// misc
'automatic-video-posts',
'bwp-minify',
'nginx-helper',
'patron-button-and-widgets-by-codebard',
'porn-embed',
'video-importer',
'woozone',
'wp-cleanfix',
];
return includes( unsupportedPlugins, plugin.slug );
}
isWpcomInstallDisabled() {
const { isTransfering } = this.props;
return ! this.hasBusinessPlan() || this.isUnsupportedPluginForAT() || isTransfering;
}
isJetpackInstallDisabled() {
const { automatedTransferSite } = this.props;
return automatedTransferSite && this.isUnsupportedPluginForAT();
}
getInstallButton() {
const { selectedSite } = this.props;
if ( selectedSite && selectedSite.jetpack && this.hasOrgInstallButton() ) {
return <PluginInstallButton disabled={ this.isJetpackInstallDisabled() } { ...this.props } />;
}
if ( selectedSite && ! selectedSite.jetpack ) {
return (
<WpcomPluginInstallButton
disabled={ this.isWpcomInstallDisabled() }
plugin={ this.props.plugin }
/>
);
}
}
maybeDisplayUnsupportedNotice() {
const { selectedSite } = this.props;
if ( selectedSite && this.isUnsupportedPluginForAT() ) {
return (
<Notice
text={ this.props.translate(
'Incompatible plugin: This plugin is not supported on WordPress.com.'
) }
status="is-warning"
showDismiss={ false }
>
<NoticeAction href="https://support.wordpress.com/incompatible-plugins/">
{ this.props.translate( 'More info' ) }
</NoticeAction>
</Notice>
);
}
}
isOutOfDate() {
if ( this.props.plugin && this.props.plugin.last_updated ) {
const lastUpdated = moment( this.props.plugin.last_updated, 'YYYY-MM-DD' );
return moment().diff( lastUpdated, 'years' ) >= this.OUT_OF_DATE_YEARS;
}
return false;
}
getVersionWarning() {
const newVersions = this.getAvailableNewVersions();
if ( this.isOutOfDate() && newVersions.length === 0 ) {
return (
<Notice
className="plugin-meta__version-notice"
text={ this.props.translate(
"This plugin hasn't been updated in over 2 years. It may no longer be maintained or " +
'supported and may have compatibility issues when used with more recent versions of WordPress'
) }
status="is-warning"
showDismiss={ false }
/>
);
} else if (
config.isEnabled( 'manage/plugins/compatibility-warning' ) &&
! this.isVersionCompatible()
) {
return (
<Notice
className="plugin-meta__version-notice"
text={ i18n.translate(
'The new version of this plugin may not be compatible with your version of WordPress'
) }
status="is-warning"
showDismiss={ false }
/>
);
}
}
getUpdateWarning() {
const newVersions = this.getAvailableNewVersions();
if ( newVersions.length > 0 ) {
if ( this.props.selectedSite ) {
return (
<Notice
status="is-warning"
className="plugin-meta__version-notice"
showDismiss={ false }
icon="sync"
text={ i18n.translate( 'Version %(newPluginVersion)s is available', {
args: { newPluginVersion: newVersions[ 0 ].newVersion },
} ) }
>
<NoticeAction onClick={ this.handlePluginUpdatesSingleSite }>
{ i18n.translate( 'Update' ) }
</NoticeAction>
</Notice>
);
}
const noticeMessage =
newVersions.length > 1
? i18n.translate(
'Version %(newPluginVersion)s is available for %(numberOfSites)s sites',
{
args: {
numberOfSites: newVersions.length,
newPluginVersion: this.props.plugin.version,
},
}
)
: i18n.translate( 'Version %(newPluginVersion)s is available for %(siteName)s', {
args: {
siteName: newVersions[ 0 ].title,
newPluginVersion: this.props.plugin.version,
},
} );
const noticeActionMessage =
newVersions.length > 1 ? i18n.translate( 'Update all' ) : i18n.translate( 'Update' );
return (
<Notice
status="is-warning"
className="plugin-meta__version-notice"
showDismiss={ false }
icon="sync"
text={ noticeMessage }
>
<NoticeAction onClick={ this.handlePluginUpdatesMultiSite }>
{ noticeActionMessage }
</NoticeAction>
</Notice>
);
}
}
isVersionCompatible() {
if ( ! this.props.selectedSite ) {
return true;
}
// still not fetched
if ( ! this.props.plugin.compatibility ) {
return true;
}
if ( ! this.props.plugin.compatibility || this.props.plugin.compatibility.length === 0 ) {
return false;
}
const siteVersion = this.props.selectedSite.options.software_version.split( '-' )[ 0 ];
return some( this.props.plugin.compatibility, compatibleVersion => {
return compatibleVersion.indexOf( siteVersion ) === 0;
} );
}
hasOrgInstallButton() {
if ( this.props.selectedSite ) {
return (
! this.props.isInstalledOnSite &&
userCan( 'manage_options', this.props.selectedSite ) &&
this.props.selectedSite.jetpack
);
}
}
getAvailableNewVersions() {
return this.props.sites
.map( site => {
if ( ! site.canUpdateFiles ) {
return null;
}
if ( site.plugin && site.plugin.update ) {
if ( 'error' !== site.plugin.update && site.plugin.update.new_version ) {
return {
title: site.title,
newVersion: site.plugin.update.new_version,
};
}
}
} )
.filter( newVersions => newVersions );
}
handlePluginUpdatesSingleSite = event => {
event.preventDefault();
PluginsActions.updatePlugin( this.props.sites[ 0 ], this.props.sites[ 0 ].plugin );
analytics.ga.recordEvent(
'Plugins',
'Clicked Update Selected Site Plugin',
'Plugin Name',
this.props.pluginSlug
);
analytics.tracks.recordEvent( 'calypso_plugins_actions_update_plugin', {
site: this.props.sites[ 0 ].ID,
plugin: this.props.sites[ 0 ].plugin.slug,
selected_site: this.props.sites[ 0 ].ID,
} );
};
handlePluginUpdatesMultiSite = event => {
event.preventDefault();
this.props.sites.forEach( site => {
const { plugin } = site;
if (
site.canUpdateFiles &&
plugin.update &&
'error' !== plugin.update &&
plugin.update.new_version
) {
PluginsActions.updatePlugin( site, plugin );
PluginsActions.removePluginsNotices( 'completed', 'error' );
analytics.tracks.recordEvent( 'calypso_plugins_actions_update_plugin_all_sites', {
site: site,
plugin: plugin.slug,
} );
}
} );
analytics.ga.recordEvent(
'Plugins',
'Clicked Update All Sites Plugin',
'Plugin Name',
this.props.pluginSlug
);
};
renderUpsell() {
const { slug, translate } = this.props;
const plan = findFirstSimilarPlanKey( this.props.selectedSite.plan.product_slug, {
type: TYPE_BUSINESS,
} );
const title = translate( 'Upgrade to the Business plan to install plugins.' );
const href = '/feature/plugins/' + slug;
/* eslint-disable wpcalypso/jsx-classname-namespace */
if (
config.isEnabled( 'upsell/nudge-a-palooza' ) &&
abtest( 'nudgeAPalooza' ) === 'pluginUpsells'
) {
return (
<div className="plugin-meta__upgrade_nudge">
<Banner
event="calypso_plugin_detail_page_upgrade_nudge_upsell"
href={ href }
plan={ plan }
title={ title }
/>
</div>
);
}
return (
<div className="plugin-meta__upgrade_nudge">
<Banner
feature={ FEATURE_UPLOAD_PLUGINS }
event="calypso_plugin_detail_page_upgrade_nudge"
plan={ plan }
title={ title }
/>
</div>
);
/* eslint-enable wpcalypso/jsx-classname-namespace */
}
render() {
const cardClasses = classNames( 'plugin-meta__information', {
'has-button': this.hasOrgInstallButton(),
'has-site': !! this.props.selectedSite,
'is-placeholder': !! this.props.isPlaceholder,
} );
const plugin =
this.props.selectedSite && this.props.sites[ 0 ] && this.props.sites[ 0 ].plugin
? this.props.sites[ 0 ].plugin
: this.props.plugin;
const path =
( ! this.props.selectedSite || plugin.active ) && getExtensionSettingsPath( plugin );
return (
<div className="plugin-meta">
{ this.props.atEnabled &&
this.props.selectedSite && <QueryEligibility siteId={ this.props.selectedSite.ID } /> }
<Card>
{ this.displayBanner() }
<div className={ cardClasses }>
<div className="plugin-meta__detail">
<PluginIcon
image={ this.props.plugin && this.props.plugin.icon }
isPlaceholder={ this.props.isPlaceholder }
/>
{ this.renderName() }
<div className="plugin-meta__meta">{ this.renderAuthorUrl() }</div>
</div>
{ ! this.props.calypsoify && this.renderActions() }
</div>
</Card>
{ path && (
<CompactCard
className="plugin-meta__settings-link"
href={ addSiteFragment( path, this.props.slug ) }
>
{ this.props.translate( 'Edit plugin settings' ) }
</CompactCard>
) }
{ ! this.props.isMock &&
get( this.props.selectedSite, 'jetpack' ) && (
<PluginInformation
plugin={ this.props.plugin }
isPlaceholder={ this.props.isPlaceholder }
site={ this.props.selectedSite }
pluginVersion={ plugin && plugin.version }
siteVersion={
this.props.selectedSite && this.props.selectedSite.options.software_version
}
hasUpdate={ this.getAvailableNewVersions().length > 0 }
calypsoify={ this.props.calypsoify }
/>
) }
{ this.props.atEnabled && this.maybeDisplayUnsupportedNotice() }
{ this.props.atEnabled &&
this.hasBusinessPlan() &&
! get( this.props.selectedSite, 'jetpack' ) && (
<PluginAutomatedTransfer plugin={ this.props.plugin } />
) }
{ ( ( this.props.selectedSite && get( this.props.selectedSite, 'jetpack' ) ) ||
this.hasBusinessPlan() ||
this.isWpcomPreinstalled() ) && <div style={ { marginBottom: 16 } } /> }
{ this.props.selectedSite &&
this.props.selectedSite.plan &&
! get( this.props.selectedSite, 'jetpack' ) &&
! this.hasBusinessPlan() &&
! this.isWpcomPreinstalled() &&
( this.maybeDisplayUnsupportedNotice() || this.renderUpsell() ) }
{ this.getVersionWarning() }
{ this.getUpdateWarning() }
</div>
);
}
}
const mapStateToProps = state => {
const siteId = getSelectedSiteId( state );
const selectedSite = getSelectedSite( state );
return {
atEnabled: isATEnabled( selectedSite ),
isTransferring: isAutomatedTransferActive( state, siteId ),
automatedTransferSite: isSiteAutomatedTransfer( state, siteId ),
slug: getSiteSlug( state, siteId ),
};
};
export default connect( mapStateToProps )( localize( PluginMeta ) );