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

Lock settings based on constants #1430

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

* Outbox items only get sent to followers when there are any.
* Restrict modifications to settings if they are predefined as constants.

### Fixed

Expand Down
25 changes: 25 additions & 0 deletions includes/class-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public static function init() {

\add_action( 'updated_postmeta', array( self::class, 'updated_postmeta' ), 10, 4 );
\add_action( 'added_post_meta', array( self::class, 'updated_postmeta' ), 10, 4 );
\add_filter( 'pre_option_activitypub_actor_mode', array( self::class, 'pre_get_option' ) );

\add_action( 'init', array( self::class, 'register_user_meta' ), 11 );

// Register several post_types.
Expand Down Expand Up @@ -366,6 +368,29 @@ public static function pre_get_avatar_data( $args, $id_or_email ) {
return $args;
}

/**
* Pre-get option filter for the Actor-Mode.
*
* @param string|false $pre The pre-get option value.
*
* @return string|false The actor mode or false if it should not be filtered.
*/
public static function pre_get_option( $pre ) {
if ( \defined( 'ACTIVITYPUB_SINGLE_USER_MODE' ) && ACTIVITYPUB_SINGLE_USER_MODE ) {
return ACTIVITYPUB_BLOG_MODE;
}

if ( \defined( 'ACTIVITYPUB_DISABLE_USER' ) && ACTIVITYPUB_DISABLE_USER ) {
return ACTIVITYPUB_BLOG_MODE;
}

if ( \defined( 'ACTIVITYPUB_DISABLE_BLOG_USER' ) && ACTIVITYPUB_DISABLE_BLOG_USER ) {
return ACTIVITYPUB_ACTOR_MODE;
}

return $pre;
}

/**
* Function to retrieve Avatar URL if stored in meta.
*
Expand Down
20 changes: 15 additions & 5 deletions includes/wp-admin/class-settings-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,21 @@ public static function render_notifications_section() {
* Render actor mode field.
*/
public static function render_actor_mode_field() {
$value = get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE );
?>
$value = get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE );
$disabled = ( \defined( 'ACTIVITYPUB_SINGLE_USER_MODE' ) && ACTIVITYPUB_SINGLE_USER_MODE ) ||
( \defined( 'ACTIVITYPUB_DISABLE_USER' ) && ACTIVITYPUB_DISABLE_USER ) ||
( \defined( 'ACTIVITYPUB_DISABLE_BLOG_USER' ) && ACTIVITYPUB_DISABLE_BLOG_USER );
$disable_input = $disabled ? 'disabled' : '';

if ( $disabled ) :
?>
<p class="description">
<strong><?php esc_html_e( '⚠ This setting is defined through server configuration by your blog&#8217;s administrator and cannot be changed. Please contact them if you need different settings.', 'activitypub' ); ?></strong>
</p>
<?php endif; ?>
<p>
<label>
<input type="radio" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_ACTOR_MODE ); ?>" <?php checked( ACTIVITYPUB_ACTOR_MODE, $value ); ?> />
<input type="radio" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_ACTOR_MODE ); ?>" <?php checked( ACTIVITYPUB_ACTOR_MODE, $value ); ?> <?php echo esc_attr( $disable_input ); ?> />
<strong><?php esc_html_e( 'Author Profiles Only', 'activitypub' ); ?></strong>
</label>
</p>
Expand All @@ -233,7 +243,7 @@ public static function render_actor_mode_field() {
</p>
<p>
<label>
<input type="radio" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_BLOG_MODE ); ?>" <?php checked( ACTIVITYPUB_BLOG_MODE, $value ); ?> />
<input type="radio" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_BLOG_MODE ); ?>" <?php checked( ACTIVITYPUB_BLOG_MODE, $value ); ?> <?php echo esc_attr( $disable_input ); ?> />
<strong><?php esc_html_e( 'Blog profile only', 'activitypub' ); ?></strong>
</label>
</p>
Expand All @@ -242,7 +252,7 @@ public static function render_actor_mode_field() {
</p>
<p>
<label>
<input type="radio" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_ACTOR_AND_BLOG_MODE ); ?>" <?php checked( ACTIVITYPUB_ACTOR_AND_BLOG_MODE, $value ); ?> />
<input type="radio" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_ACTOR_AND_BLOG_MODE ); ?>" <?php checked( ACTIVITYPUB_ACTOR_AND_BLOG_MODE, $value ); ?> <?php echo esc_attr( $disable_input ); ?> />
<strong><?php esc_html_e( 'Both author and blog profiles', 'activitypub' ); ?></strong>
</label>
</p>
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ For reasons of data protection, it is not possible to see the followers of other

* Added: Documentation for migrating from a Mastodon instance to WordPress.
* Changed: Outbox items only get sent to followers when there are any.
* Changed: Restrict modifications to settings if they are predefined as constants.
* Fixed: Updates to certain user meta fields did not trigger an Update activity.
* Fixed: When viewing Reply Contexts, we'll now attribute the post to the blog user when the post author is disabled.
* Fixed: Properly re-added support for `Update` and `Delete` `Announce`ments.
Expand Down
Loading