Skip to content

Commit

Permalink
fix: Force Distributor to not override bylines
Browse files Browse the repository at this point in the history
  • Loading branch information
leogermani committed Dec 18, 2024
1 parent 47f0e22 commit 6c426e7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions includes/class-distributor-customizations.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ public static function init() {
Distributor_Customizations\Author_Ingestion::init();
Distributor_Customizations\Authorship_Filters::init();
Distributor_Customizations\Comment_Status::init();
Distributor_Customizations\Force_Author_Byline::init();
}
}
51 changes: 51 additions & 0 deletions includes/distributor-customizations/class-force-author-byline.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Newspack Distributor Force Author byline option.
*
* @package Newspack
*/

namespace Newspack_Network\Distributor_Customizations;

/**
* Class to enforce that the "Override Author Byline" option is always disabled.
*/
class Force_Author_Byline {

/**
* Initialize hooks
*/
public static function init() {
add_filter( 'option_dt_settings', [ __CLASS__, 'filter_dt_settings' ] );
add_filter( 'default_option_dt_settings', [ __CLASS__, 'filter_dt_settings' ] );
add_action( 'admin_init', [ __CLASS__, 'remove_setting' ], 11 );
}

/**
* Filter the Distributor settings to ensure that the "Override Author Byline" option is always disabled.
*
* @param array $settings The Distributor settings.
*/
public static function filter_dt_settings( $settings ) {
if ( ! is_array( $settings ) ) {
$settings = [];
}
$settings['override_author_byline'] = false;
return $settings;
}

/**
* Remove the "Override Author Byline" setting from the Distributor settings page.
*/
public static function remove_setting() {
global $wp_settings_fields;

if (
isset( $wp_settings_fields['distributor'] ) &&
isset( $wp_settings_fields['distributor']['dt-section-1'] ) &&
isset( $wp_settings_fields['distributor']['dt-section-1']['override_author_byline'] )
) {
unset( $wp_settings_fields['distributor']['dt-section-1']['override_author_byline'] );
}
}
}

0 comments on commit 6c426e7

Please sign in to comment.