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

Add private sites module #10333

Merged
merged 90 commits into from
May 27, 2019
Merged
Show file tree
Hide file tree
Changes from 88 commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
c782642
add private sites module
scruffian Oct 16, 2018
7230928
remove unneccessary code
scruffian Nov 20, 2018
e14410e
fix linting issues
scruffian Nov 21, 2018
b35b7a9
move fuctions to a class
scruffian Nov 23, 2018
100cf0f
Disable sharing, publicize and subcription modules on private sites
scruffian Nov 26, 2018
7da8a69
prevent site visibility change when the private site module is enbabled
scruffian Nov 26, 2018
8530238
only show an error when the error function exists
scruffian Nov 27, 2018
d7516b4
make a site private when the module is enabled
scruffian Nov 27, 2018
680e1cb
Update the message when changing blog_public
scruffian Nov 27, 2018
398af3a
fixes based on feedback
scruffian Nov 29, 2018
3967891
changes based on feedback
scruffian Nov 30, 2018
5841302
copy update
scruffian Nov 30, 2018
9235b44
hide visibility settings
scruffian Nov 30, 2018
7290403
copy update
scruffian Nov 30, 2018
9096358
remove extra text
scruffian Dec 4, 2018
e346397
Add an error code to the REST API blocking code
scruffian Dec 7, 2018
b37e6fd
Update wording
scruffian Dec 7, 2018
e84985f
Move to the security section
scruffian Dec 7, 2018
c529cf1
Rename function for consistency
scruffian Jan 21, 2019
286c678
update release number
scruffian Jan 21, 2019
85abde5
remove unnecessary file check
scruffian Jan 21, 2019
e089302
remove unused variable
scruffian Jan 21, 2019
464aefd
rebsase from master
scruffian Jan 23, 2019
079ba48
remove bloginfo filter when syncing
scruffian Jan 23, 2019
2337047
Update blog_public option when private module activates or deactivates.
niranjan-uma-shankar Feb 14, 2019
c764e55
Removing a stray debug line
niranjan-uma-shankar Feb 14, 2019
e861d94
Hide OPML for private sites
niranjan-uma-shankar Feb 15, 2019
4af2421
prevent all ajax requests on private sites
niranjan-uma-shankar Feb 27, 2019
9875776
Replacing global with WP functions
niranjan-uma-shankar Feb 27, 2019
528a040
Prevent requests to admin-post.php for private sites
niranjan-uma-shankar Feb 28, 2019
3365cba
removing inadvertently introduced stray spaces
niranjan-uma-shankar Mar 2, 2019
882966c
Move blog_public update_option out of init
niranjan-uma-shankar Mar 11, 2019
4c0749d
Replace /traffic links with /security
niranjan-uma-shankar Mar 11, 2019
e22f1d4
1. Add 403 response code 2. For OPML, exit with 403 and don't display…
niranjan-uma-shankar Mar 11, 2019
a61df9a
403 response code for OPML
niranjan-uma-shankar Mar 11, 2019
b742d35
Remove inadvertent log line
niranjan-uma-shankar Mar 11, 2019
436b0b8
Replace get_blog_info() with get_blog_details(), since the former onl…
niranjan-uma-shankar Mar 11, 2019
79d7993
Add private sites message to Site Visibility option in Reading settings
niranjan-uma-shankar Mar 11, 2019
75779c3
Replacing hide_opml() with static function
niranjan-uma-shankar Mar 11, 2019
52247c6
1. Remove blog_public modifications 2. Hide sitemap for private sites…
niranjan-uma-shankar Mar 19, 2019
ab0e1aa
Disable sitemap for private sites (refactored)
niranjan-uma-shankar Mar 19, 2019
cd282dd
Bump priority for preprocess_comment so that it runs before Akismet
niranjan-uma-shankar Mar 21, 2019
3975e10
add an explanation for this line
scruffian Mar 26, 2019
7692d20
Removed the jetpack_get_available_modules filter since it doesn't sav…
niranjan-uma-shankar Mar 29, 2019
0f314de
fixing merge conflict
niranjan-uma-shankar Apr 15, 2019
93f0377
1. Removed global wpdb 2. Copy change 3. Using set_url_scheme() for t…
niranjan-uma-shankar Apr 15, 2019
708d2a9
Remove is_super_admin() checks and instead utilize the check for read…
niranjan-uma-shankar Apr 16, 2019
236c736
Fixing lint errors
niranjan-uma-shankar Apr 16, 2019
4754c06
1. Stricter checking for type 2. Updated versions
niranjan-uma-shankar Apr 16, 2019
d4d745d
1. Bug fix (missing parenthesis) 2. For is_private_blog_user(), remov…
niranjan-uma-shankar Apr 16, 2019
671298e
Now using current_user_can_for_blog(), a core function which would be…
niranjan-uma-shankar Apr 16, 2019
f5a2769
Changing milestone
niranjan-uma-shankar Apr 16, 2019
c74c725
Adding the p2 reference in comment
niranjan-uma-shankar Apr 16, 2019
246be87
Reverted the change to printf that removes wp_kses. Reinstated wp_kse…
niranjan-uma-shankar Apr 16, 2019
af2fa54
1. Copy change 2. Added jetpack_ prefix to priv_notice_privacy_select…
niranjan-uma-shankar Apr 16, 2019
4caf5f2
1. Copy change 2. Added jetpack_ prefix to priv_notice_privacy_select…
niranjan-uma-shankar Apr 16, 2019
b6fb351
Lint fixes, and merged back changes lost in b2913ad
niranjan-uma-shankar Apr 16, 2019
58d5579
The last attemp at fixing yarn.lock conflict didn't work, trying agai…
niranjan-uma-shankar Apr 22, 2019
1a7acb8
rebuilding yarn.lock
niranjan-uma-shankar Apr 22, 2019
b0c6ad2
Update modules/private/class-jetpack-private.php
jeherve Apr 24, 2019
7e573b5
Adding error messages
niranjan-uma-shankar Apr 24, 2019
6193ff0
Fixes issue of module states not being restored
niranjan-uma-shankar May 3, 2019
1fc9611
1. Removing stray whitespace as a result of bad merge 2. Rebuild yarn…
niranjan-uma-shankar May 20, 2019
c75f665
Undo changes to deactivate_module(). This change has no effect and is…
niranjan-uma-shankar May 20, 2019
de6a656
Renamed variable for better clarity
niranjan-uma-shankar May 20, 2019
ee20819
Copy change
niranjan-uma-shankar May 20, 2019
d80cc20
Add private/public status to the At a glance widget
niranjan-uma-shankar May 20, 2019
95ec371
Added learn more link
niranjan-uma-shankar May 21, 2019
6cf77f7
Revised the target milestone
niranjan-uma-shankar May 21, 2019
161fa34
Minor change in doc block
niranjan-uma-shankar May 21, 2019
3bca8c1
Styling changes: adding font color
niranjan-uma-shankar May 21, 2019
4c7ba85
Update _inc/client/security/private.jsx
niranjan-uma-shankar May 21, 2019
c667924
Update _inc/client/security/private.jsx
niranjan-uma-shankar May 21, 2019
70581ea
Update class.jetpack.php
niranjan-uma-shankar May 21, 2019
4fcf64a
Update class.jetpack.php
niranjan-uma-shankar May 21, 2019
b97c591
Update modules/module-extras.php
niranjan-uma-shankar May 21, 2019
e3825fb
Update modules/private/class-jetpack-private.php
niranjan-uma-shankar May 21, 2019
fe72ab6
Update modules/private/class-jetpack-private.php
niranjan-uma-shankar May 21, 2019
b3f1680
Update modules/private/class-jetpack-private.php
niranjan-uma-shankar May 21, 2019
36bba52
Update modules/private/class-jetpack-private.php
niranjan-uma-shankar May 21, 2019
22e6850
1. Minor fix in milestone (7.4 to 7.4.0) 2. Added phpcs ignore for wp…
niranjan-uma-shankar May 21, 2019
270f951
1. Removed FEATURE_PRIVATE_JETPACK constant since it's only used for …
niranjan-uma-shankar May 21, 2019
702f30f
Readability change
niranjan-uma-shankar May 21, 2019
309a031
1. Moved css to file 2. Added doc block for at a glance callback
niranjan-uma-shankar May 21, 2019
65f11d3
Moved the css styling from the css file to inline style; deleted the …
niranjan-uma-shankar May 23, 2019
820c6eb
Post rebase, fixing conflicts
niranjan-uma-shankar May 23, 2019
7b6a5cf
Rebase
niranjan-uma-shankar May 24, 2019
3e9cf40
Add inline css only in the main admin page
niranjan-uma-shankar May 24, 2019
11bd70d
1. Replace esc_attr with esc_url 2. Copy change 3. Added 'status' key…
niranjan-uma-shankar May 27, 2019
ee9ac54
1. For a private site, removes the 'Search engines are discouraged' m…
niranjan-uma-shankar May 27, 2019
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
7 changes: 5 additions & 2 deletions _inc/client/security/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import BackupsScan from './backups-scan';
import Antispam from './antispam';
import { ManagePlugins } from './manage-plugins';
import { Monitor } from './monitor';
import { Private } from './private';
jeherve marked this conversation as resolved.
Show resolved Hide resolved
import { Protect } from './protect';
import { SSO } from './sso';

Expand Down Expand Up @@ -72,13 +73,14 @@ export class Security extends Component {
foundAkismet = this.isAkismetFound(),
rewindActive = 'active' === get( this.props.rewindStatus, [ 'state' ], false ),
foundBackups = this.props.isModuleFound( 'vaultpress' ) || rewindActive,
foundMonitor = this.props.isModuleFound( 'monitor' );
foundMonitor = this.props.isModuleFound( 'monitor' ),
foundPrivateSites = this.props.isModuleFound( 'private' );

if ( ! this.props.searchTerm && ! this.props.active ) {
return null;
}

if ( ! foundSso && ! foundProtect && ! foundAkismet && ! foundBackups && ! foundMonitor ) {
if ( ! foundSso && ! foundProtect && ! foundAkismet && ! foundBackups && ! foundMonitor && ! foundPrivateSites ) {
return null;
}

Expand Down Expand Up @@ -106,6 +108,7 @@ export class Security extends Component {
<ManagePlugins { ...commonProps } />
{ foundProtect && <Protect { ...commonProps } /> }
{ foundSso && <SSO { ...commonProps } /> }
{ foundPrivateSites && <Private { ...commonProps } /> }
</div>
);
}
Expand Down
52 changes: 52 additions & 0 deletions _inc/client/security/private.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* External dependencies
*/
import React, { Component } from 'react';
import { translate as __ } from 'i18n-calypso';

/**
* Internal dependencies
*/
import { ModuleToggle } from 'components/module-toggle';
import SettingsCard from 'components/settings-card';
import SettingsGroup from 'components/settings-group';
import { withModuleSettingsFormHelpers } from 'components/module-settings/with-module-settings-form-helpers';

export const Private = withModuleSettingsFormHelpers(
class extends Component {
render() {
return (
<SettingsCard { ...this.props } module="private" hideButton>
<SettingsGroup
hasChild
module={ { module: 'private' } }
support={ {
text: __(
"This option is great if you're still working on your site " +
" and aren't quite ready to show it off to the rest of the internet yet."
),
link: 'https://jetpack.com/support/private',
} }
>
<p>
{ __(
'Private sites can only be seen by you ' +
'and other users who are members of this site.'
) }
</p>

<ModuleToggle
slug="private"
compact
activated={ this.props.getOptionValue( 'private' ) }
toggling={ this.props.isSavingAnyOption( 'private' ) }
toggleModule={ this.props.toggleModuleNow }
>
{ __( 'Make your site private' ) }
</ModuleToggle>
</SettingsGroup>
</SettingsCard>
);
}
}
);
2 changes: 2 additions & 0 deletions bin/phpcs-whitelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ module.exports = [
'modules/verification-tools.php',
'modules/wpcom-block-editor/class-jetpack-wpcom-block-editor.php',
'packages',
'modules/private.php',
'modules/private/',
];
83 changes: 73 additions & 10 deletions class.jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -1809,9 +1809,66 @@ function user_role_change( $user_id ) {
}

/**
* Loads the currently active modules.
* Loads the private module if it has been activated.
* Else, updates the admin dashboard with the site's private status.
*/
public static function load_modules() {
public static function load_private() {
jeherve marked this conversation as resolved.
Show resolved Hide resolved
if ( self::is_module_active( 'private' ) ) {
self::load_modules( array( 'private' ) );
} else {
add_action( 'update_right_now_text', array( __CLASS__, 'add_public_dashboard_glance_items' ) );
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'wp_admin_glance_dashboard_style' ) );
}
}

/**
* Basic styling for the wp-admin 'At a Glance' dashboard widget.
* This is applied when the private module is inactive.
*
* @param string $hook Page Hook Suffix for the current page.
*/
public static function wp_admin_glance_dashboard_style( $hook ) {
if ( 'index.php' !== $hook ) {
return;
}

$custom_css = '
.jp-at-a-glance__site-public {
color: #46B450;
}
';
wp_add_inline_style( 'dashboard', $custom_css );
}

/**
* Adds a message to the 'At a Glance' dashboard widget.
*
* @param string $content Content of 'At A Glance' wp-admin dashboard widget.
*/
public static function add_public_dashboard_glance_items( $content ) {
jeherve marked this conversation as resolved.
Show resolved Hide resolved
return
$content .
'<br><br>' .
wp_kses(
sprintf(
/* translators: URL for Jetpack dashboard. */
__( '<span class="%1$1s">This site is set to public.</span> <a href="%2$2s">Make private</a>.', 'jetpack' ),
esc_attr( 'jp-at-a-glance__site-public' ),
esc_url( admin_url( 'admin.php?page=jetpack#/security?term=private' ) )
),
array(
'a' => array( 'href' => true ),
'span' => array( 'class' => true ),
)
);
}

/**
* Loads modules from given array, otherwise all the currently active modules.
*
* @param array $modules Specific modules to be loaded.
*/
public static function load_modules( $modules = array() ) {
if (
! self::is_active()
&& ! self::is_development_mode()
Expand All @@ -1831,9 +1888,13 @@ public static function load_modules() {
do_action( 'updating_jetpack_version', $version, false );
Jetpack_Options::update_options( compact( 'version', 'old_version' ) );
}
list( $version ) = explode( ':', $version );
list( $version ) = explode( ':', $version );
$fetched_all_active_modules = false;

$modules = array_filter( Jetpack::get_active_modules(), array( 'Jetpack', 'is_module' ) );
if ( empty( $modules ) ) {
$modules = array_filter( Jetpack::get_active_modules(), array( 'Jetpack', 'is_module' ) );
$fetched_all_active_modules = true;
}

$modules_data = array();

Expand Down Expand Up @@ -1890,12 +1951,14 @@ public static function load_modules() {
do_action( 'jetpack_module_loaded_' . $module );
}

/**
* Fires when all the modules are loaded.
*
* @since 1.1.0
*/
do_action( 'jetpack_modules_loaded' );
if ( $fetched_all_active_modules ) {
/**
* Fires when all the modules are loaded.
*
* @since 1.1.0
*/
do_action( 'jetpack_modules_loaded' );
}

// Load module-specific code that is needed even when a module isn't active. Loaded here because code contained therein may need actions such as setup_theme.
require_once( JETPACK__PLUGIN_DIR . 'modules/module-extras.php' );
Expand Down
1 change: 1 addition & 0 deletions jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ function jetpack_admin_missing_autoloader() { ?>
add_action( 'updating_jetpack_version', array( 'Jetpack', 'do_version_bump' ), 10, 2 );
add_action( 'init', array( 'Jetpack', 'init' ) );
add_action( 'plugins_loaded', array( 'Jetpack', 'plugin_textdomain' ), 99 );
add_action( 'plugins_loaded', array( 'Jetpack', 'load_private' ), 99 );
add_action( 'plugins_loaded', array( 'Jetpack', 'load_modules' ), 100 );
add_filter( 'jetpack_static_url', array( 'Jetpack', 'staticize_subdomain' ) );
add_filter( 'is_jetpack_site', '__return_true' );
Expand Down
25 changes: 25 additions & 0 deletions modules/module-extras.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,28 @@ function jetpack_widgets_add_suffix( $widget_name ) {
);
}
add_filter( 'jetpack_widget_name', 'jetpack_widgets_add_suffix' );

add_action( 'blog_privacy_selector', 'jetpack_priv_notice_privacy_selector' );

/**
kraftbj marked this conversation as resolved.
Show resolved Hide resolved
* Echos notice directing site owners to Jetpack's Private Site feature.
*/
function jetpack_priv_notice_privacy_selector() {
?>
<p>
<?php

wp_kses(
printf(
/* translators: URL to the Jetpack dashboard. */
__( 'You can also make your site completely private by allowing only registered users to see it. <a href="%s">Go to Private Site settings</a>.', 'jetpack' ),
niranjan-uma-shankar marked this conversation as resolved.
Show resolved Hide resolved
esc_url( admin_url( 'admin.php?page=jetpack#/security?term=private' ) )
),
array( 'a' => array( 'href' => true ) )
scruffian marked this conversation as resolved.
Show resolved Hide resolved
);
?>
</p>

<?php
}

9 changes: 9 additions & 0 deletions modules/module-headings.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ function jetpack_get_module_i18n( $key ) {
'description' => _x( 'Publish posts by sending an email', 'Module Description', 'jetpack' ),
),

'private' => array(
kraftbj marked this conversation as resolved.
Show resolved Hide resolved
'name' => _x( 'Private site', 'Module Name', 'jetpack' ),
'description' => _x( 'Make your site only visible to you and users you approve.', 'Module Description', 'jetpack' ),
),

'protect' => array(
'name' => _x( 'Protect', 'Module Name', 'jetpack' ),
'description' => _x( 'Protect yourself from brute force and distributed brute force attacks, which are the most common way for hackers to get into your site.', 'Module Description', 'jetpack' ),
Expand Down Expand Up @@ -328,6 +333,10 @@ function jetpack_get_module_i18n_tag( $key ) {
// - modules/minileven.php
'Mobile' =>_x( 'Mobile', 'Module Tag', 'jetpack' ),

// Modules with `Private` tag:
// - modules/private.php
'Private' =>_x( 'Private', 'Module Tag', 'jetpack' ),
scruffian marked this conversation as resolved.
Show resolved Hide resolved

// Modules with `Traffic` tag:
// - modules/sitemaps.php
// - modules/wordads.php
Expand Down
19 changes: 19 additions & 0 deletions modules/module-info.php
Original file line number Diff line number Diff line change
Expand Up @@ -912,3 +912,22 @@ function jetpack_more_info_copy_post() {
esc_html_e( 'Create a new post based on an existing post.', 'jetpack' );
}
add_action( 'jetpack_module_more_info_copy-post', 'jetpack_more_info_copy_post' );

/**
* Private sites support link.
*/
function jetpack_private_more_link() {
echo 'https://jetpack.com/support/private';
}
add_action( 'jetpack_learn_more_button_private', 'jetpack_private_more_link' );

/**
* Private sites description.
*/
function jetpack_private_more_info() {
esc_html_e(
'Make your site private. It will only be visible to registered users.',
'jetpack'
);
}
add_action( 'jetpack_module_more_info_private', 'jetpack_private_more_info' );
jeherve marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 19 additions & 0 deletions modules/private.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
kraftbj marked this conversation as resolved.
Show resolved Hide resolved
/**
* Module Name: Private site
* Module Description: Make your site only visible to you and users you approve.
* Sort Order: 9
* First Introduced: 7.4.0
* Requires Connection: No
* Auto Activate: No
* Module Tags: Private
* Feature: Security
* Additional Search Queries: private, sandbox, launch, unlaunched, maintenance, coming soon
*
* @package Jetpack
*/

/* Private Site Class */
require_once 'private/class-jetpack-private.php';

Jetpack_Private::init();
Loading