Skip to content

Feature/network site options#15

Merged
tlovett1 merged 11 commits into10up:developfrom
ivankristianto:feature/network-site-options
Apr 3, 2017
Merged

Feature/network site options#15
tlovett1 merged 11 commits into10up:developfrom
ivankristianto:feature/network-site-options

Conversation

@ivankristianto
Copy link
Copy Markdown
Contributor

This PR is to add the Network Options.
What it does:

  1. Add the network settings UI
  2. Network option: rsa_mode (default and enforce), default for new site settings option. enforce will override every site settings to network settings ( but it won't change the local settings )
  3. Change the process of restricted_access to allow network enforce mode
  4. Change set_option_defaults to allow network get_site_options

@tlovett1
Copy link
Copy Markdown
Contributor

This doesn't seem to be working. I set the default to be restrict, created a new site, and navigated to that site in incognito mode. I was shown the site and not the access denied message I created.

@ivankristianto
Copy link
Copy Markdown
Contributor Author

I couldn't replicate the error you mention.
But let me just do a fresh install and do more checking.

@ivankristianto
Copy link
Copy Markdown
Contributor Author

@tlovett1
I couldn't replicate the issue.
Here is what I do:
https://youtu.be/4mxicQOXnl0

Cache.page_field = $( document.getElementById( 'rsa_page' ) ).closest( 'tr' );

if ( ! document.getElementById( 'blog-restricted' ).checked ) {
if ( document.getElementById( 'blog-restricted' ) != null && ! document.getElementById( 'blog-restricted' ).checked ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use identical operators !==

<input id="blog-public" type="radio" name="blog_public" value="1" <?php checked( $blog_public, '1') ?>>
<label for="blog-public">Allow search engines to index this site</label><br>
<input id="blog-norobots" type="radio" name="blog_public" value="0" <?php checked( $blog_public, '0') ?>>
<label for="blog-norobots">Discourage search engines from indexing this site</label>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need localization

if( 'rsa_options' === $option_name ){
$value = self::sanitize_options( $_POST[$option_name] );
}else{
$value = wp_unslash( $_POST[$option_name] );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do?

@tlovett1
Copy link
Copy Markdown
Contributor

@ivankristianto seems to be working for me now. Not sure why I had an issue before. I left comments on the code.

@ivankristianto
Copy link
Copy Markdown
Contributor Author

@tlovett1 I fixed and tidy up the code. Can you please check again?

<th scope="row"><?php _e( 'Handle restricted visitors', 'restricted-site-access' ) ?></th>
<td>
<?php
self::settings_field_handling( [] );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[] array notation is PHP 5.4+. We need to support PHP 5.2.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok got it

<tr>
<th scope="row"><?php _e( 'Site Visibility', 'restricted-site-access' ) ?></th>
<?php
if ( FALSE === get_site_option( 'blog_public' ) ){
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is FALSE capitalized?

@tlovett1 tlovett1 merged commit b53ccd7 into 10up:develop Apr 3, 2017
// If we have network activated and rsa_mode = default, and rsa_options is not exist, we set it
if( 'default' === self::$rsa_network_mode && defined( 'RSA_IS_NETWORK' ) && RSA_IS_NETWORK && empty( self::$rsa_options ) ){
self::$rsa_options = (array) get_site_option( 'rsa_options' );
update_option( 'rsa_options', self::$rsa_options );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be update_site_option?


$network_activated = Restricted_Site_Access::is_network( plugin_basename( __FILE__ ) );

if ( $network_activated ) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just define RSA_IS_NETWORK to false otherwise then you simplify the IF check throughout the code

}

if ( defined( 'RSA_IS_NETWORK' ) && RSA_IS_NETWORK ){
self::$rsa_network_mode = get_site_option( 'rsa_mode' );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are checking this variable elsewhere which might not be defined. This will throw a notice.

//If rsa_mode==enforce we override the rsa_options
if( 'enforce' === self::$rsa_network_mode && RSA_IS_NETWORK ){
$blog_public = get_site_option( 'blog_public', 2 );
self::$rsa_options = get_site_option( 'rsa_options' );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already set this in set_option_defaults

@ktorktor ktorktor mentioned this pull request Oct 28, 2025
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:enhancement New feature or request.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants