Skip to content

Commit 2a96d66

Browse files
authored
Lock settings based on constants (#1430)
* Lock settings based on constants This locks the Actor settings based on the `ACTIVITYPUB_SINGLE_USER_MODE`, `ACTIVITYPUB_BLOG_MODE` or `ACTIVITYPUB_ACTOR_MODE` constants. * add changelog * hook into `get_option` * fix phpcs * fix implementation * fix phpcs * added changelog * simplify lock * changes based on feedacks
1 parent 0093e7a commit 2a96d66

File tree

3 files changed

+82
-41
lines changed

3 files changed

+82
-41
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: changed
3+
4+
Restricted modifications to settings if they are predefined as constants.

includes/class-activitypub.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public static function init() {
4949

5050
\add_action( 'updated_postmeta', array( self::class, 'updated_postmeta' ), 10, 4 );
5151
\add_action( 'added_post_meta', array( self::class, 'updated_postmeta' ), 10, 4 );
52+
\add_filter( 'pre_option_activitypub_actor_mode', array( self::class, 'pre_get_option' ) );
53+
5254
\add_action( 'init', array( self::class, 'register_user_meta' ), 11 );
5355

5456
// Register several post_types.
@@ -383,6 +385,29 @@ public static function pre_get_avatar_data( $args, $id_or_email ) {
383385
return $args;
384386
}
385387

388+
/**
389+
* Pre-get option filter for the Actor-Mode.
390+
*
391+
* @param string|false $pre The pre-get option value.
392+
*
393+
* @return string|false The actor mode or false if it should not be filtered.
394+
*/
395+
public static function pre_get_option( $pre ) {
396+
if ( \defined( 'ACTIVITYPUB_SINGLE_USER_MODE' ) && ACTIVITYPUB_SINGLE_USER_MODE ) {
397+
return ACTIVITYPUB_BLOG_MODE;
398+
}
399+
400+
if ( \defined( 'ACTIVITYPUB_DISABLE_USER' ) && ACTIVITYPUB_DISABLE_USER ) {
401+
return ACTIVITYPUB_BLOG_MODE;
402+
}
403+
404+
if ( \defined( 'ACTIVITYPUB_DISABLE_BLOG_USER' ) && ACTIVITYPUB_DISABLE_BLOG_USER ) {
405+
return ACTIVITYPUB_ACTOR_MODE;
406+
}
407+
408+
return $pre;
409+
}
410+
386411
/**
387412
* Function to retrieve Avatar URL if stored in meta.
388413
*

includes/wp-admin/class-settings-fields.php

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -223,51 +223,63 @@ public static function render_notifications_section() {
223223
* Render actor mode field.
224224
*/
225225
public static function render_actor_mode_field() {
226+
$disabled = ( \defined( 'ACTIVITYPUB_SINGLE_USER_MODE' ) && ACTIVITYPUB_SINGLE_USER_MODE ) ||
227+
( \defined( 'ACTIVITYPUB_DISABLE_USER' ) && ACTIVITYPUB_DISABLE_USER ) ||
228+
( \defined( 'ACTIVITYPUB_DISABLE_BLOG_USER' ) && ACTIVITYPUB_DISABLE_BLOG_USER );
229+
230+
if ( $disabled ) :
231+
?>
232+
<p class="description">
233+
<?php esc_html_e( '⚠ This setting is defined through server configuration by your blog&#8217;s administrator.', 'activitypub' ); ?>
234+
</p>
235+
<?php
236+
return;
237+
endif;
238+
226239
$value = get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE );
227240
?>
228-
<fieldset class="actor-mode-selection">
229-
<div class="row">
230-
<input type="radio" id="actor-mode" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_ACTOR_MODE ); ?>" <?php checked( ACTIVITYPUB_ACTOR_MODE, $value ); ?> />
231-
<div>
232-
<label for="actor-mode"><strong><?php esc_html_e( 'Author Profiles Only', 'activitypub' ); ?></strong></label>
233-
<p class="description">
234-
<?php echo wp_kses( __( 'Every author on this blog (with the <code>activitypub</code> capability) gets their own ActivityPub profile.', 'activitypub' ), array( 'code' => array() ) ); ?>
235-
<strong>
236-
<?php
237-
echo wp_kses(
238-
sprintf(
239-
// translators: %s is a URL.
240-
__( 'You can add/remove the capability in the <a href="%s">user settings.</a>', 'activitypub' ),
241-
admin_url( '/users.php' )
242-
),
243-
array( 'a' => array( 'href' => array() ) )
244-
);
245-
?>
246-
</strong>
247-
<?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() ) ); ?>
248-
</p>
249-
</div>
250-
</div>
251-
<div class="row">
252-
<input type="radio" id="blog-mode" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_BLOG_MODE ); ?>" <?php checked( ACTIVITYPUB_BLOG_MODE, $value ); ?> />
253-
<div>
254-
<label for="blog-mode"><strong><?php esc_html_e( 'Blog profile only', 'activitypub' ); ?></strong></label>
255-
<p class="description">
256-
<?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' ); ?>
257-
</p>
258-
</div>
241+
<fieldset class="actor-mode-selection">
242+
<div class="row">
243+
<input type="radio" id="actor-mode" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_ACTOR_MODE ); ?>" <?php checked( ACTIVITYPUB_ACTOR_MODE, $value ); ?> />
244+
<div>
245+
<label for="actor-mode"><strong><?php esc_html_e( 'Author Profiles Only', 'activitypub' ); ?></strong></label>
246+
<p class="description">
247+
<?php echo wp_kses( __( 'Every author on this blog (with the <code>activitypub</code> capability) gets their own ActivityPub profile.', 'activitypub' ), array( 'code' => array() ) ); ?>
248+
<strong>
249+
<?php
250+
echo wp_kses(
251+
sprintf(
252+
// translators: %s is a URL.
253+
__( 'You can add/remove the capability in the <a href="%s">user settings.</a>', 'activitypub' ),
254+
admin_url( '/users.php' )
255+
),
256+
array( 'a' => array( 'href' => array() ) )
257+
);
258+
?>
259+
</strong>
260+
<?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() ) ); ?>
261+
</p>
259262
</div>
260-
<div class="row">
261-
<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 ); ?> />
262-
<div>
263-
<label for="actor-blog-mode"><strong><?php esc_html_e( 'Both author and blog profiles', 'activitypub' ); ?></strong></label>
264-
<p class="description">
265-
<?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' ); ?>
266-
</p>
267-
</div>
263+
</div>
264+
<div class="row">
265+
<input type="radio" id="blog-mode" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_BLOG_MODE ); ?>" <?php checked( ACTIVITYPUB_BLOG_MODE, $value ); ?> />
266+
<div>
267+
<label for="blog-mode"><strong><?php esc_html_e( 'Blog profile only', 'activitypub' ); ?></strong></label>
268+
<p class="description">
269+
<?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' ); ?>
270+
</p>
268271
</div>
269-
</fieldset>
270-
272+
</div>
273+
<div class="row">
274+
<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 ); ?> />
275+
<div>
276+
<label for="actor-blog-mode"><strong><?php esc_html_e( 'Both author and blog profiles', 'activitypub' ); ?></strong></label>
277+
<p class="description">
278+
<?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' ); ?>
279+
</p>
280+
</div>
281+
</div>
282+
</fieldset>
271283
<?php
272284
}
273285

0 commit comments

Comments
 (0)