Skip to content

Commit 6c426e7

Browse files
committed
fix: Force Distributor to not override bylines
1 parent 47f0e22 commit 6c426e7

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

includes/class-distributor-customizations.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ public static function init() {
2727
Distributor_Customizations\Author_Ingestion::init();
2828
Distributor_Customizations\Authorship_Filters::init();
2929
Distributor_Customizations\Comment_Status::init();
30+
Distributor_Customizations\Force_Author_Byline::init();
3031
}
3132
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Newspack Distributor Force Author byline option.
4+
*
5+
* @package Newspack
6+
*/
7+
8+
namespace Newspack_Network\Distributor_Customizations;
9+
10+
/**
11+
* Class to enforce that the "Override Author Byline" option is always disabled.
12+
*/
13+
class Force_Author_Byline {
14+
15+
/**
16+
* Initialize hooks
17+
*/
18+
public static function init() {
19+
add_filter( 'option_dt_settings', [ __CLASS__, 'filter_dt_settings' ] );
20+
add_filter( 'default_option_dt_settings', [ __CLASS__, 'filter_dt_settings' ] );
21+
add_action( 'admin_init', [ __CLASS__, 'remove_setting' ], 11 );
22+
}
23+
24+
/**
25+
* Filter the Distributor settings to ensure that the "Override Author Byline" option is always disabled.
26+
*
27+
* @param array $settings The Distributor settings.
28+
*/
29+
public static function filter_dt_settings( $settings ) {
30+
if ( ! is_array( $settings ) ) {
31+
$settings = [];
32+
}
33+
$settings['override_author_byline'] = false;
34+
return $settings;
35+
}
36+
37+
/**
38+
* Remove the "Override Author Byline" setting from the Distributor settings page.
39+
*/
40+
public static function remove_setting() {
41+
global $wp_settings_fields;
42+
43+
if (
44+
isset( $wp_settings_fields['distributor'] ) &&
45+
isset( $wp_settings_fields['distributor']['dt-section-1'] ) &&
46+
isset( $wp_settings_fields['distributor']['dt-section-1']['override_author_byline'] )
47+
) {
48+
unset( $wp_settings_fields['distributor']['dt-section-1']['override_author_byline'] );
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)