Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Premium Content Block: Move to Jetpack #17907

Merged
merged 52 commits into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
9b06c58
First pass at moving over the premium content block from editing tool…
apeatling Nov 25, 2020
dd87975
Fix include paths.
apeatling Nov 25, 2020
d5807f1
Add premium content plan requirement, and allow the block to skip the…
apeatling Nov 26, 2020
1f2b626
Correctly register child blocks.
apeatling Nov 26, 2020
7142a82
Add Premium content child blocks to the paid plan check.
apeatling Nov 26, 2020
19d103a
Move the container block to the root, and register the child blocks v…
apeatling Nov 30, 2020
31d8fce
Add the editor css styles.
apeatling Nov 30, 2020
008c24c
Include the server side render functions for child blocks.
apeatling Dec 1, 2020
d3b70f5
Add fix for https://github.com/Automattic/wp-calypso/pull/47944
apeatling Dec 2, 2020
a3313a9
Allow login and buttons blocks to appear in the inserter and be inser…
apeatling Dec 3, 2020
08019ce
Update the default template content for the subscriber view.
apeatling Dec 3, 2020
642a0df
Fix icon.js lint errors
aaronrobertshaw Dec 4, 2020
df29c54
First pass at fixing PHP linting errors.
apeatling Dec 7, 2020
62b4f0f
Replace all full-site-editing textdomain usage.
apeatling Dec 7, 2020
eb30d07
Second pass at PHP lint errors.
apeatling Dec 7, 2020
85cd777
Third pass at PHP lint errors.
apeatling Dec 7, 2020
be64e4d
Final pass at php lint issues.
apeatling Dec 7, 2020
56f18a4
Remove references to Dashicon component.
apeatling Dec 8, 2020
bb7f609
Keep deprectated setup consistent across blocks.
apeatling Dec 8, 2020
86021dd
Incorporate changes from @stacimc's PR https://github.com/Automattic/…
apeatling Dec 9, 2020
0147493
Fix phpcs issues.
apeatling Dec 9, 2020
f9e3406
Remove upgrade nudges
stacimc Jan 5, 2021
deb7438
Use prefix instead of noPrefix for remvoing the Jetpack prefix.
apeatling Jan 7, 2021
08c7bd1
Better block descriptions.
apeatling Jan 7, 2021
50dadcf
Add missing translation.
apeatling Jan 7, 2021
55002d6
Move to shared icon store.
apeatling Jan 7, 2021
c3a43c5
Prepend action with jetpack_ and document.
apeatling Jan 7, 2021
a98c409
Convert all indentation to tabs.
apeatling Jan 7, 2021
77078d6
Plan checks for premium content buttons and login button.
apeatling Jan 7, 2021
33d321f
Remove tabs.js since it's no longer used.
apeatling Jan 7, 2021
fc26905
Remove log2logstash because this is not available outside of WordPres…
apeatling Jan 7, 2021
d80d3d9
Only load the premium content blocks on WordPress.com.
apeatling Jan 11, 2021
4eab5db
Use shared supported currencies data.
apeatling Jan 11, 2021
dfcc1e7
Remove plan check from buttons blocks and instead hide from inserter.…
apeatling Jan 11, 2021
c39578a
Make sure the block loads on Atomic sites that do not use IS_WPCOM
apeatling Jan 13, 2021
58c46ce
Add get_current_user() call.
apeatling Jan 13, 2021
7f3e017
Fix phpcs issues.
apeatling Jan 13, 2021
2cadf6a
[not verified] Merge remote-tracking branch 'origin/master' into add/…
jeherve Jan 19, 2021
3d9f7d0
Consolidate currency functions
jeherve Jan 19, 2021
93e777d
Switch to Gutenberg colors
jeherve Jan 19, 2021
ef611ba
Add missing translations
jeherve Jan 19, 2021
299c668
Ensure CSS gets enqueued on the frontend
jeherve Jan 19, 2021
f200fa1
Add inline docs for filters
jeherve Jan 19, 2021
c8b40c0
Fix reference to Subscription_Service
jeherve Jan 19, 2021
3ef927c
Add missing arguments when rendering legacy buttons
jeherve Jan 19, 2021
0777f36
Merge in fix for block transformations menu, to ensure the block prev…
andrewserong Jan 20, 2021
375d1b5
Try fixing linting issues
jeherve Jan 20, 2021
9c4eb65
Merge remote-tracking branch 'origin/master' into add/premium-content…
jeherve Jan 20, 2021
f1498e9
Add our new js files to the lint exclude list for now
jeherve Jan 20, 2021
cabe1b4
Revert "Add our new js files to the lint exclude list for now"
jeherve Jan 20, 2021
a3cddc1
Try to address all linting warnings in new files
jeherve Jan 20, 2021
6770974
Remove file from excludelist now that it is free of linting errors
jeherve Jan 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
mocha: true,
node: true,
jquery: true,
jest: true
jest: true,
},
parserOptions: {
ecmaVersion: 2019,
Expand Down
4 changes: 2 additions & 2 deletions projects/plugins/jetpack/_inc/client/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module.exports = {
'@wordpress/i18n-text-domain': [
'error',
{
'allowedTextDomain': 'jetpack',
}
allowedTextDomain: 'jetpack',
},
],
},
};
3 changes: 2 additions & 1 deletion projects/plugins/jetpack/_inc/client/traffic/site-stats.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ class SiteStatsComponent extends React.Component {
>
<span className="jp-form-toggle-explanation">
{ __(
'Include a small chart in your admin bar with a 48-hour traffic snapshot', 'jetpack'
'Include a small chart in your admin bar with a 48-hour traffic snapshot',
'jetpack'
) }
</span>
</CompactFormToggle>
Expand Down
7 changes: 6 additions & 1 deletion projects/plugins/jetpack/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ const config = {
},
{
// Transpile ES Modules syntax (`import`) in config files (but not elsewhere)
test: [ './dangerfile.js', './gulpfile.babel.js', './tools/webpack.config.js', './tools/builder/' ],
test: [
'./dangerfile.js',
'./gulpfile.babel.js',
'./tools/webpack.config.js',
'./tools/builder/',
],
presets: [
[ require.resolve( '@automattic/calypso-build/babel/default' ), { modules: 'commonjs' } ],
],
Expand Down
1 change: 1 addition & 0 deletions projects/plugins/jetpack/class.jetpack-plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Jetpack_Plan {
'supports' => array(
'akismet',
'recurring-payments',
'premium-content/container',
),
),
'premium' => array(
Expand Down
10 changes: 3 additions & 7 deletions projects/plugins/jetpack/extensions/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
module.exports = {
extends: [
'../.eslintrc.js',
'plugin:@wordpress/eslint-plugin/i18n',
'plugin:jest/recommended',
],
extends: [ '../.eslintrc.js', 'plugin:@wordpress/eslint-plugin/i18n', 'plugin:jest/recommended' ],
env: { jest: true },
rules: {
'react/forbid-elements': [
Expand Down Expand Up @@ -39,8 +35,8 @@ module.exports = {
'@wordpress/i18n-text-domain': [
'error',
{
'allowedTextDomain': 'jetpack',
}
allowedTextDomain: 'jetpack',
},
],
'jsdoc/check-tag-names': [
1, // Recommended
Expand Down
17 changes: 4 additions & 13 deletions projects/plugins/jetpack/extensions/blocks/conversation/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/

import { __ } from '@wordpress/i18n';
import { __ } from '@wordpress/i18n';

const participants = [
{
Expand Down Expand Up @@ -42,32 +42,23 @@ const template = [
name: 'jetpack/dialogue',
attributes: {
...participants[ 1 ],
content: __(
'It is my arm.',
'jetpack'
),
content: __( 'It is my arm.', 'jetpack' ),
timestamp: '00:15',
},
},
{
name: 'jetpack/dialogue',
attributes: {
...participants[ 0 ],
content: __(
'I thought thy heart had been wounded with the claws of a lion.',
'jetpack'
),
content: __( 'I thought thy heart had been wounded with the claws of a lion.', 'jetpack' ),
timestamp: '00:32',
},
},
{
name: 'jetpack/dialogue',
attributes: {
...participants[ 1 ],
content: __(
'Wounded it is, but with the eyes of a lady.',
'jetpack'
),
content: __( 'Wounded it is, but with the eyes of a lady.', 'jetpack' ),
timestamp: '00:37',
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/**
* WordPress dependencies
*/
import {
Dropdown,
Button,
} from '@wordpress/components';
import { Dropdown, Button } from '@wordpress/components';
import { __, _x } from '@wordpress/i18n';

/**
Expand Down
9 changes: 7 additions & 2 deletions projects/plugins/jetpack/extensions/blocks/opentable/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import {
withNotices,
} from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { getBlockDefaultClassName, registerBlockStyle, unregisterBlockStyle } from '@wordpress/blocks';
import {
getBlockDefaultClassName,
registerBlockStyle,
unregisterBlockStyle,
} from '@wordpress/blocks';
import { useEffect } from '@wordpress/element';

/**
Expand Down Expand Up @@ -249,7 +253,8 @@ function OpenTableEdit( {
);

const editClasses = classnames( className, {
[ `is-style-${ style }` ]: ! isPlaceholder && styleValues.includes( style ) && className.indexOf( 'is-style' ) === -1,
[ `is-style-${ style }` ]:
! isPlaceholder && styleValues.includes( style ) && className.indexOf( 'is-style' ) === -1,
'is-placeholder': isPlaceholder,
'is-multi': 'multi' === getTypeAndTheme( style )[ 0 ],
[ `align${ align }` ]: align,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ import { withDispatch, withSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import {
STATE_ERROR,
STATE_PAUSED,
STORE_ID,
} from '../../../store/media-source/constants';
import { STATE_ERROR, STATE_PAUSED, STORE_ID } from '../../../store/media-source/constants';
import AudioPlayer from '../../../shared/components/audio-player';
import Playlist from './playlist';
import Header from './header';
Expand Down Expand Up @@ -171,17 +167,11 @@ export class PodcastPlayer extends Component {
};

handleJump = () => {
this.props.setMediaSourceCurrentTime(
this.props.playerId,
this.props.currentTime - 5
);
this.props.setMediaSourceCurrentTime( this.props.playerId, this.props.currentTime - 5 );
};

handleSkip = () => {
this.props.setMediaSourceCurrentTime(
this.props.playerId,
this.props.currentTime + 30
);
this.props.setMediaSourceCurrentTime( this.props.playerId, this.props.currentTime + 30 );
};

componentDidMount() {
Expand Down Expand Up @@ -212,7 +202,16 @@ export class PodcastPlayer extends Component {
}

render() {
const { playerId, title, link, cover, tracks, attributes, currentTime, playerState } = this.props;
const {
playerId,
title,
link,
cover,
tracks,
attributes,
currentTime,
playerState,
} = this.props;
const {
itemsToShow,
primaryColor,
Expand Down Expand Up @@ -294,7 +293,7 @@ export class PodcastPlayer extends Component {
onPause={ this.handlePause }
onError={ this.handleError }
playStatus={ playerState }
currentTime ={ currentTime }
currentTime={ currentTime }
onTimeChange={ this.handleTimeChange }
/>
</Header>
Expand Down Expand Up @@ -354,14 +353,11 @@ export default compose( [
withErrorBoundary,
withSelect( ( select, props ) => {
const { playerId } = props;
const {
getMediaSourceCurrentTime,
getMediaPlayerState,
} = select( STORE_ID );
const { getMediaSourceCurrentTime, getMediaPlayerState } = select( STORE_ID );

return {
currentTime: getMediaSourceCurrentTime( playerId ),
playerState: getMediaPlayerState( playerId )
playerState: getMediaPlayerState( playerId ),
};
} ),
withDispatch( dispatch => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/**
* External dependencies
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* Determine access to premium content.
*
* @package Automattic\Jetpack\Extensions\Premium_Content
*/

namespace Automattic\Jetpack\Extensions\Premium_Content;

require __DIR__ . '/subscription-service/include.php';

/**
* Determines if the memberships module is set up.
*
* @return bool Whether the memberships module is set up.
*/
function pre_render_checks() {
// If Jetpack is not yet configured, don't show anything ...
if ( ! class_exists( '\Jetpack_Memberships' ) ) {
return false;
}
// if stripe not connected don't show anything...
if ( empty( \Jetpack_Memberships::get_connected_account_id() ) ) {
return false;
}
return true;
}

/**
* Determines if the current user can view the protected content of the given block.
*
* @param array $attributes Block attributes.
* @param object $block Block to check.
*
* @return bool Whether the use can view the content.
*/
function current_visitor_can_access( $attributes, $block ) {
$user = wp_get_current_user();

/**
* If the current WordPress install has as signed in user
* they can see the content.
*/
if ( 0 !== $user->ID && current_user_can( 'edit_post', get_the_ID() ) ) {
return true;
}

$selected_plan_id = null;

if ( isset( $attributes['selectedPlanId'] ) ) {
$selected_plan_id = (int) $attributes['selectedPlanId'];
}

if ( isset( $block ) && isset( $block->context['premium-content/planId'] ) ) {
$selected_plan_id = (int) $block->context['premium-content/planId'];
}

if ( empty( $selected_plan_id ) ) {
return false;
}

$paywall = subscription_service();
$can_view = $paywall->visitor_can_view_content( array( $selected_plan_id ) );

if ( $can_view ) {
/**
* Fires when a visitor can view protected content on a site.
*
* @since 9.4.0
*/
do_action( 'jetpack_earn_remove_cache_headers' );
}

return $can_view;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* WordPress dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';

export default function Blocks() {
return (
<div className="premium-content-wrapper">
<InnerBlocks
allowedBlocks={ [ 'premium-content/subscriber-view', 'premium-content/logged-out-view' ] }
templateLock={ 'all' }
template={ [
[ 'premium-content/subscriber-view' ],
[ 'premium-content/logged-out-view' ],
] }
__experimentalCaptureToolbars={ true }
templateInsertUpdatesSelection={ false }
/>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* WordPress dependencies
*/
import { createContext } from '@wordpress/element';

/**
* @typedef { import('react').ReactElement } ReactElement
* @typedef { import('./tab').Tab } Tab
* @typedef { (isSelected: boolean) => void } Callback
* @typedef { {selectedTab: Tab, stripeNudge: ?ReactElement } } TabbedInterface
*/

/**
* @type { TabbedInterface }
*/
const defaultContext = {
selectedTab: { id: '', className: '', label: <></> },
stripeNudge: null,
};

/**
* @typedef { import('react').Context<TabbedInterface> } TabContext
* @type { TabContext }
*/
const Context = createContext( defaultContext );

export default Context;
Loading