Skip to content

Lock settings based on constants #1430

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

Merged
merged 23 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
725f190
Lock settings based on constants
pfefferle Mar 7, 2025
535f0a1
add changelog
pfefferle Mar 7, 2025
a44e80c
hook into `get_option`
pfefferle Mar 7, 2025
93d40ef
fix phpcs
pfefferle Mar 7, 2025
65c5e7e
fix implementation
pfefferle Mar 7, 2025
4c981d6
fix phpcs
pfefferle Mar 7, 2025
c2e982f
Merge branch 'trunk' into change/setting-constants
pfefferle Mar 10, 2025
d8f14d9
Merge branch 'trunk' into change/setting-constants
pfefferle Mar 10, 2025
58a541e
Merge branch 'trunk' into change/setting-constants
pfefferle Mar 11, 2025
eb91d08
Merge branch 'trunk' into change/setting-constants
pfefferle Mar 11, 2025
a5f230e
Merge branch 'trunk' into change/setting-constants
pfefferle Mar 11, 2025
fb24370
Merge branch 'trunk' into change/setting-constants
pfefferle Mar 12, 2025
6a12882
Merge branch 'trunk' into change/setting-constants
pfefferle Mar 14, 2025
c68db1f
added changelog
pfefferle Mar 14, 2025
37a60ad
Merge branch 'trunk' into change/setting-constants
pfefferle Mar 14, 2025
078f8c1
Merge branch 'trunk' into change/setting-constants
pfefferle Mar 16, 2025
f45945e
Merge branch 'trunk' into change/setting-constants
pfefferle Mar 17, 2025
7f17424
Merge branch 'trunk' into change/setting-constants
pfefferle Mar 18, 2025
3747f27
Merge branch 'trunk' into change/setting-constants
pfefferle Mar 18, 2025
91d8034
Merge branch 'trunk' into change/setting-constants
pfefferle Mar 18, 2025
610a0b0
simplify lock
pfefferle Mar 18, 2025
bcb3d84
Merge branch 'trunk' into change/setting-constants
pfefferle Mar 18, 2025
6763fe1
changes based on feedacks
pfefferle Mar 19, 2025
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
4 changes: 4 additions & 0 deletions .github/changelog/change-setting-constants
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Restricted modifications to settings if they are predefined as constants.
25 changes: 25 additions & 0 deletions includes/class-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,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 @@ -383,6 +385,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
94 changes: 53 additions & 41 deletions includes/wp-admin/class-settings-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,51 +223,63 @@ public static function render_notifications_section() {
* Render actor mode field.
*/
public static function render_actor_mode_field() {
$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 );

if ( $disabled ) :
?>
<p class="description">
<?php esc_html_e( '⚠ This setting is defined through server configuration by your blog&#8217;s administrator.', 'activitypub' ); ?>
</p>
<?php
return;
endif;

$value = get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE );
?>
<fieldset class="actor-mode-selection">
<div class="row">
<input type="radio" id="actor-mode" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_ACTOR_MODE ); ?>" <?php checked( ACTIVITYPUB_ACTOR_MODE, $value ); ?> />
<div>
<label for="actor-mode"><strong><?php esc_html_e( 'Author Profiles Only', 'activitypub' ); ?></strong></label>
<p class="description">
<?php echo wp_kses( __( 'Every author on this blog (with the <code>activitypub</code> capability) gets their own ActivityPub profile.', 'activitypub' ), array( 'code' => array() ) ); ?>
<strong>
<?php
echo wp_kses(
sprintf(
// translators: %s is a URL.
__( 'You can add/remove the capability in the <a href="%s">user settings.</a>', 'activitypub' ),
admin_url( '/users.php' )
),
array( 'a' => array( 'href' => array() ) )
);
?>
</strong>
<?php echo wp_kses( __( 'Select all the users you want to update, choose the method from the drop-down list and click on the "Apply" button.', 'activitypub' ), array( 'code' => array() ) ); ?>
</p>
</div>
</div>
<div class="row">
<input type="radio" id="blog-mode" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_BLOG_MODE ); ?>" <?php checked( ACTIVITYPUB_BLOG_MODE, $value ); ?> />
<div>
<label for="blog-mode"><strong><?php esc_html_e( 'Blog profile only', 'activitypub' ); ?></strong></label>
<p class="description">
<?php esc_html_e( 'Your blog becomes a single ActivityPub profile and every post will be published under this profile instead of the individual author profiles.', 'activitypub' ); ?>
</p>
</div>
<fieldset class="actor-mode-selection">
<div class="row">
<input type="radio" id="actor-mode" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_ACTOR_MODE ); ?>" <?php checked( ACTIVITYPUB_ACTOR_MODE, $value ); ?> />
<div>
<label for="actor-mode"><strong><?php esc_html_e( 'Author Profiles Only', 'activitypub' ); ?></strong></label>
<p class="description">
<?php echo wp_kses( __( 'Every author on this blog (with the <code>activitypub</code> capability) gets their own ActivityPub profile.', 'activitypub' ), array( 'code' => array() ) ); ?>
<strong>
<?php
echo wp_kses(
sprintf(
// translators: %s is a URL.
__( 'You can add/remove the capability in the <a href="%s">user settings.</a>', 'activitypub' ),
admin_url( '/users.php' )
),
array( 'a' => array( 'href' => array() ) )
);
?>
</strong>
<?php echo wp_kses( __( 'Select all the users you want to update, choose the method from the drop-down list and click on the "Apply" button.', 'activitypub' ), array( 'code' => array() ) ); ?>
</p>
</div>
<div class="row">
<input type="radio" id="actor-blog-mode" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_ACTOR_AND_BLOG_MODE ); ?>" <?php checked( ACTIVITYPUB_ACTOR_AND_BLOG_MODE, $value ); ?> />
<div>
<label for="actor-blog-mode"><strong><?php esc_html_e( 'Both author and blog profiles', 'activitypub' ); ?></strong></label>
<p class="description">
<?php esc_html_e( "This combines both modes. Users can be followed individually, while following the blog will show boosts of individual user's posts.", 'activitypub' ); ?>
</p>
</div>
</div>
<div class="row">
<input type="radio" id="blog-mode" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_BLOG_MODE ); ?>" <?php checked( ACTIVITYPUB_BLOG_MODE, $value ); ?> />
<div>
<label for="blog-mode"><strong><?php esc_html_e( 'Blog profile only', 'activitypub' ); ?></strong></label>
<p class="description">
<?php esc_html_e( 'Your blog becomes a single ActivityPub profile and every post will be published under this profile instead of the individual author profiles.', 'activitypub' ); ?>
</p>
</div>
</fieldset>

</div>
<div class="row">
<input type="radio" id="actor-blog-mode" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_ACTOR_AND_BLOG_MODE ); ?>" <?php checked( ACTIVITYPUB_ACTOR_AND_BLOG_MODE, $value ); ?> />
<div>
<label for="actor-blog-mode"><strong><?php esc_html_e( 'Both author and blog profiles', 'activitypub' ); ?></strong></label>
<p class="description">
<?php esc_html_e( "This combines both modes. Users can be followed individually, while following the blog will show boosts of individual user's posts.", 'activitypub' ); ?>
</p>
</div>
</div>
</fieldset>
<?php
}

Expand Down
Loading