chore: lint code

This commit is contained in:
Ben Goldsworthy 2021-08-09 11:48:58 +01:00
parent 8b2f98184d
commit 8c639a97b5
36 changed files with 715 additions and 640 deletions

View file

@ -106,20 +106,8 @@ abstract class Engine {
$this->settings->settings_sections['scope_and_priority']->get_section_slug() => $this->settings->settings_sections['scope_and_priority'], $this->settings->settings_sections['scope_and_priority']->get_section_slug() => $this->settings->settings_sections['scope_and_priority'],
$this->settings->settings_sections['custom_css']->get_section_slug() => $this->settings->settings_sections['custom_css'], $this->settings->settings_sections['custom_css']->get_section_slug() => $this->settings->settings_sections['custom_css'],
); );
/*foreach ( $this->get_sections() as $section ) {
// Append tab to the tab-array.
$this->sections[ $section['id'] ] = $section;
add_settings_section(
$section['id'],
'',
fn() => $this->description(),
'footnotes'
);
$this->add_settings_fields();
//$this->register_meta_boxes( $section['id'] );
}*/
} }
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing // phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
/** /**
* Displays the content of specific sub-page. * Displays the content of specific sub-page.
@ -129,14 +117,14 @@ abstract class Engine {
*/ */
public function display_content(): void { public function display_content(): void {
// check user capabilities // check user capabilities
if ( ! current_user_can( 'manage_options' ) ) { if ( ! current_user_can( 'manage_options' ) ) {
return; return;
} }
$active_section_id = isset( $_GET['t'] ) ? wp_unslash( $_GET['t'] ) : array_key_first( $this->sections ); $active_section_id = isset( $_GET['t'] ) ? wp_unslash( $_GET['t'] ) : array_key_first( $this->sections );
$active_section = $this->sections[ $active_section_id ]; $active_section = $this->sections[ $active_section_id ];
// Store settings. // Store settings.
$settings_updated = false; $settings_updated = false;
if ( array_key_exists( 'save-settings', $_POST ) ) { if ( array_key_exists( 'save-settings', $_POST ) ) {
if ( 'save' === $_POST['save-settings'] ) { if ( 'save' === $_POST['save-settings'] ) {
@ -146,49 +134,50 @@ abstract class Engine {
} }
} }
?> ?>
<div class="wrap"> <div class="wrap">
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1> <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
<h2 class="nav-tab-wrapper"> <h2 class="nav-tab-wrapper">
<?php foreach ( $this->sections as $section_slug => $section ): ?> <?php foreach ( $this->sections as $section_slug => $section ) : ?>
<a <a
class="nav-tab<?php echo ( $section_slug === $active_section->get_section_slug() ) ? ' nav-tab-active' : '' ?>" class="nav-tab<?php echo ( $section_slug === $active_section->get_section_slug() ) ? ' nav-tab-active' : ''; ?>"
href="?page=<?php echo Init::MAIN_MENU_SLUG ?>&t=<?php echo $section_slug ?>"> href="?page=<?php echo Init::MAIN_MENU_SLUG; ?>&t=<?php echo $section_slug; ?>">
<?php echo $section->get_title(); ?> <?php echo $section->get_title(); ?>
</a> </a>
<?php endforeach; ?> <?php endforeach; ?>
</h2> </h2>
<?php <?php
if ( $settings_updated ) { if ( $settings_updated ) {
echo sprintf( '<div id="message" class="updated">%s</div>', __( 'Settings saved', 'footnotes' ) ); echo sprintf( '<div id="message" class="updated">%s</div>', __( 'Settings saved', 'footnotes' ) );
} }
// show error/update messages // show error/update messages
settings_errors( 'footnotes_messages' ); settings_errors( 'footnotes_messages' );
?> ?>
<form action="" method="post"> <form action="" method="post">
<input type="hidden" name="save-settings" value="save" /> <input type="hidden" name="save-settings" value="save" />
<?php <?php
// output security fields for the registered setting "footnotes" // output security fields for the registered setting "footnotes"
settings_fields( 'footnotes' ); settings_fields( 'footnotes' );
// output setting sections and their fields // output setting sections and their fields
// (sections are registered for "footnotes", each field is registered to a specific section) // (sections are registered for "footnotes", each field is registered to a specific section)
do_settings_sections( 'footnotes' ); do_settings_sections( 'footnotes' );
//do_meta_boxes( $active_section['id'], 'main', null ); // do_meta_boxes( $active_section['id'], 'main', null );
// Add submit button to active section if defined. // Add submit button to active section if defined.
//if ( $l_arr_active_section['submit'] ) { // if ( $l_arr_active_section['submit'] ) {
submit_button(); submit_button();
//} // }
?> ?>
</form> </form>
</div> </div>
<?php <?php
} }
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing // phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
/** /**
* Output the description of a section. May be overwritten in any section. * Output the description of a section. May be overwritten in any section.
* *
@ -395,8 +384,8 @@ abstract class Engine {
$max_length ?? 999, $max_length ?? 999,
$style ?? '', $style ?? '',
$value, $value,
isset($readonly) ? ' readonly="readonly"' : '', isset( $readonly ) ? ' readonly="readonly"' : '',
$disabled ? ' disabled': '' $disabled ? ' disabled' : ''
) ); ) );
} }
@ -417,8 +406,8 @@ abstract class Engine {
$name, $name,
$name, $name,
$style ?? '', $style ?? '',
isset($readonly) ? ' readonly="readonly"' : '', isset( $readonly ) ? ' readonly="readonly"' : '',
$disabled ? ' disabled': '', $disabled ? ' disabled' : '',
$value, $value,
) ); ) );
} }
@ -441,12 +430,12 @@ abstract class Engine {
'<input type="number" name="%s" id="%s"%s%s value="%s"%s%s%s/>', '<input type="number" name="%s" id="%s"%s%s value="%s"%s%s%s/>',
$name, $name,
$name, $name,
isset($max) ? ' max="'.$max.'"' : '', isset( $max ) ? ' max="' . $max . '"' : '',
isset($min) ? ' min="'.$min.'"' : '', isset( $min ) ? ' min="' . $min . '"' : '',
is_float($value) ? number_format( $value, 1 ) : $value, is_float( $value ) ? number_format( $value, 1 ) : $value,
is_float($value) ? ' step="0.1"' : '', is_float( $value ) ? ' step="0.1"' : '',
isset($readonly) ? ' readonly="readonly"' : '', isset( $readonly ) ? ' readonly="readonly"' : '',
$disabled ? ' disabled': '' $disabled ? ' disabled' : ''
) ); ) );
} }
@ -463,7 +452,9 @@ abstract class Engine {
protected function add_select( array $args ): void { protected function add_select( array $args ): void {
extract( $args ); extract( $args );
if (!isset($options)) trigger_error("No options passed to 'select' element.", E_USER_ERROR); if ( ! isset( $options ) ) {
trigger_error( "No options passed to 'select' element.", E_USER_ERROR );
}
$select_options = ''; $select_options = '';
// Loop through all array keys. // Loop through all array keys.
@ -484,7 +475,7 @@ abstract class Engine {
'<select name="%s" id="%s"%s>%s</select>', '<select name="%s" id="%s"%s>%s</select>',
$name, $name,
$name, $name,
$disabled ? ' disabled': '', $disabled ? ' disabled' : '',
$select_options $select_options
) ); ) );
} }
@ -507,7 +498,7 @@ abstract class Engine {
$name, $name,
$name, $name,
$value ? ' checked="checked"' : '', $value ? ' checked="checked"' : '',
$disabled ? ' disabled': '' $disabled ? ' disabled' : ''
); );
} }
@ -528,13 +519,13 @@ abstract class Engine {
'<input type="color" name="%s" id="%s"%s/>', '<input type="color" name="%s" id="%s"%s/>',
$name, $name,
$name, $name,
$disabled ? ' disabled': '' $disabled ? ' disabled' : ''
); );
} }
/****************************** /******************************
* OLD METHODS * OLD METHODS
******************************/ ******************************/
/** /**
* Registers all Meta boxes for a sub-page. * Registers all Meta boxes for a sub-page.

View file

@ -61,8 +61,8 @@ class SettingsPage extends Engine {
* @since 2.8.0 * @since 2.8.0
*/ */
protected Settings $settings protected Settings $settings
) { ) {
} }
/** /**
* Returns a priority index. * Returns a priority index.
@ -84,52 +84,56 @@ class SettingsPage extends Engine {
$active_section_id = isset( $_GET['t'] ) ? wp_unslash( $_GET['t'] ) : array_key_first( $this->sections ); $active_section_id = isset( $_GET['t'] ) ? wp_unslash( $_GET['t'] ) : array_key_first( $this->sections );
$active_section = $this->sections[ $active_section_id ]; $active_section = $this->sections[ $active_section_id ];
switch ($active_section->get_section_slug()) { switch ( $active_section->get_section_slug() ) {
case 'footnotes-settings': case 'footnotes-settings':
$this->settings->settings_sections['general']->add_settings_fields($this); $this->settings->settings_sections['general']->add_settings_fields( $this );
break; break;
case 'footnotes-customize': case 'footnotes-customize':
$this->settings->settings_sections['referrers_and_tooltips']->add_settings_fields($this); $this->settings->settings_sections['referrers_and_tooltips']->add_settings_fields( $this );
break; break;
case 'footnotes-expert': case 'footnotes-expert':
$this->settings->settings_sections['scope_and_priority']->add_settings_fields($this); $this->settings->settings_sections['scope_and_priority']->add_settings_fields( $this );
break; break;
case 'footnotes-customcss': case 'footnotes-customcss':
$this->settings->settings_sections['custom_css']->add_settings_fields($this); $this->settings->settings_sections['custom_css']->add_settings_fields( $this );
break; break;
case 'footnotes-how-to': case 'footnotes-how-to':
print_r("Demo goes here"); print_r( 'Demo goes here' );
break; break;
default: print_r("ERR: section not found"); default:
print_r( 'ERR: section not found' );
} }
} }
public function setting_field_callback( array $args ): void { public function setting_field_callback( array $args ): void {
if (isset($args['type'])) { if ( isset( $args['type'] ) ) {
echo $args['description'] . '</td><td>'; echo $args['description'] . '</td><td>';
switch($args['type']) { switch ( $args['type'] ) {
case 'text': case 'text':
$this->add_input_text($args); $this->add_input_text( $args );
return; return;
case 'textarea': case 'textarea':
$this->add_textarea($args); $this->add_textarea( $args );
return; return;
case 'number': case 'number':
$this->add_input_number($args); $this->add_input_number( $args );
return; return;
case 'select': case 'select':
$this->add_select($args); $this->add_select( $args );
return; return;
case 'checkbox': case 'checkbox':
$this->add_input_checkbox($args); $this->add_input_checkbox( $args );
return; return;
case 'color': case 'color':
$this->add_input_color($args); $this->add_input_color( $args );
return; return;
default: trigger_error("Unknown setting type.", E_USER_ERROR); default:
trigger_error( 'Unknown setting type.', E_USER_ERROR );
} }
} else trigger_error("No setting type.", E_USER_ERROR); } else {
trigger_error( 'No setting type.', E_USER_ERROR );
}
} }
/************************************************************************** /**************************************************************************

View file

@ -55,8 +55,10 @@ class Convert {
* @since 1.0-beta * @since 1.0-beta
* @todo Replace with built-in type casting. * @todo Replace with built-in type casting.
*/ */
public static function to_bool( string|null $value ): bool { public static function to_bool( ?string $value ): bool {
if (!$value) return false; if ( ! $value ) {
return false;
}
// Convert string to lower-case to make it easier. // Convert string to lower-case to make it easier.
$value = strtolower( $value ); $value = strtolower( $value );

View file

@ -101,7 +101,7 @@ class Core {
$this->load_dependencies(); $this->load_dependencies();
$this->set_locale(); $this->set_locale();
$this->settings = new Settings(); $this->settings = new Settings();
$this->define_admin_hooks(); $this->define_admin_hooks();
$this->define_public_hooks(); $this->define_public_hooks();
} }
@ -123,9 +123,12 @@ class Core {
* *
* @since 2.8.0 * @since 2.8.0
*/ */
public function get_plugin_name(bool $html = false): string { public function get_plugin_name( bool $html = false ): string {
if ( ! $html ) return $this->plugin_name; if ( ! $html ) {
else return '<span class="footnotes_logo footnotes_logo_part1">foot</span><span class="footnotes_logo footnotes_logo_part2">notes</span>'; return $this->plugin_name;
} else {
return '<span class="footnotes_logo footnotes_logo_part1">foot</span><span class="footnotes_logo footnotes_logo_part2">notes</span>';
}
} }
/** /**

View file

@ -65,10 +65,10 @@ class Settings {
$this->load_dependencies(); $this->load_dependencies();
$this->settings_sections = array( $this->settings_sections = array(
'general' => new GeneralSettingsSection('footnotes_storage', 'footnotes-settings', 'General Settings', $this ), 'general' => new GeneralSettingsSection( 'footnotes_storage', 'footnotes-settings', 'General Settings', $this ),
'referrers_and_tooltips' => new ReferrersAndTooltipsSettingsSection('footnotes_storage_custom', 'footnotes-customize', 'Referrers and Tooltips', $this), 'referrers_and_tooltips' => new ReferrersAndTooltipsSettingsSection( 'footnotes_storage_custom', 'footnotes-customize', 'Referrers and Tooltips', $this ),
'scope_and_priority' => new ScopeAndPrioritySettingsSection('footnotes_storage_expert', 'footnotes-expert', 'Scope and Priority', $this), 'scope_and_priority' => new ScopeAndPrioritySettingsSection( 'footnotes_storage_expert', 'footnotes-expert', 'Scope and Priority', $this ),
'custom_css' => new CustomCSSSettingsSection('footnotes_storage_custom_css', 'footnotes-customcss', 'Custom CSS', $this), 'custom_css' => new CustomCSSSettingsSection( 'footnotes_storage_custom_css', 'footnotes-customcss', 'Custom CSS', $this ),
); );
} }
@ -92,20 +92,20 @@ class Settings {
* @return void * @return void
*/ */
protected function load_dependencies(): void { protected function load_dependencies(): void {
require_once plugin_dir_path( __DIR__ ) . 'includes/settings/class-settings-section.php'; require_once plugin_dir_path( __DIR__ ) . 'includes/settings/class-settingssection.php';
require_once plugin_dir_path( __DIR__ ) . 'includes/settings/class-settings-group.php'; require_once plugin_dir_path( __DIR__ ) . 'includes/settings/class-settingsgroup.php';
require_once plugin_dir_path( __DIR__ ) . 'includes/settings/class-setting.php'; require_once plugin_dir_path( __DIR__ ) . 'includes/settings/class-setting.php';
require_once plugin_dir_path( __DIR__ ) . 'includes/settings/general/class-general-settings-section.php'; require_once plugin_dir_path( __DIR__ ) . 'includes/settings/general/class-generalsettingssection.php';
require_once plugin_dir_path( __DIR__ ) . 'includes/settings/referrers-and-tooltips/class-referrers-and-tooltips-settings-section.php'; require_once plugin_dir_path( __DIR__ ) . 'includes/settings/referrers-and-tooltips/class-referrersandtooltipssettingssection.php';
require_once plugin_dir_path( __DIR__ ) . 'includes/settings/scope-and-priority/class-scope-and-priority-settings-section.php'; require_once plugin_dir_path( __DIR__ ) . 'includes/settings/scope-and-priority/class-scopeandprioritysettingssection.php';
require_once plugin_dir_path( __DIR__ ) . 'includes/settings/custom-css/class-custom-css-settings-section.php'; require_once plugin_dir_path( __DIR__ ) . 'includes/settings/custom-css/class-customcsssettingssection.php';
} }
/** /**
* Retrieve a setting by its key. * Retrieve a setting by its key.
* *
* @param string $setting_key The key of the setting to search for. * @param string $setting_key The key of the setting to search for.
* @return ?Setting Either the setting object, or `null` if none exists. * @return ?Setting Either the setting object, or `null` if none exists.
* *
* @since 2.8.0 * @since 2.8.0
@ -113,10 +113,12 @@ class Settings {
* @todo This is an _O(n)_ linear search. Explore more scaleable alternatives. * @todo This is an _O(n)_ linear search. Explore more scaleable alternatives.
*/ */
public function get_setting( string $setting_key ): ?Setting { public function get_setting( string $setting_key ): ?Setting {
foreach ($this->settings_sections as $settings_section) { foreach ( $this->settings_sections as $settings_section ) {
$setting = $settings_section->get_setting($setting_key); $setting = $settings_section->get_setting( $setting_key );
if ($setting) return $setting; if ( $setting ) {
return $setting;
}
} }
return null; return null;
@ -125,7 +127,7 @@ class Settings {
/** /**
* Retrieve a setting's value by its key. * Retrieve a setting's value by its key.
* *
* @param string $setting_key The key of the setting to search for. * @param string $setting_key The key of the setting to search for.
* @return mixed Either the setting's value, or `null` if the setting does not exist. * @return mixed Either the setting's value, or `null` if the setting does not exist.
* *
* @since 2.8.0 * @since 2.8.0
@ -134,10 +136,12 @@ class Settings {
* @todo How to handle settings with a value of `null`? * @todo How to handle settings with a value of `null`?
*/ */
public function get_setting_value( string $setting_key ): mixed { public function get_setting_value( string $setting_key ): mixed {
foreach ($this->settings_sections as $settings_section) { foreach ( $this->settings_sections as $settings_section ) {
$setting = $settings_section->get_setting($setting_key); $setting = $settings_section->get_setting( $setting_key );
if ($setting) return $setting->get_value(); if ( $setting ) {
return $setting->get_value();
}
} }
return null; return null;
@ -146,7 +150,7 @@ class Settings {
/** /**
* Retrieve a setting's default value by its key. * Retrieve a setting's default value by its key.
* *
* @param string $setting_key The key of the setting to search for. * @param string $setting_key The key of the setting to search for.
* @return mixed Either the setting's default value, or `null` if the setting does not exist. * @return mixed Either the setting's default value, or `null` if the setting does not exist.
* *
* @since 2.8.0 * @since 2.8.0
@ -155,10 +159,12 @@ class Settings {
* @todo How to handle settings with a default value of `null`? * @todo How to handle settings with a default value of `null`?
*/ */
public function get_setting_default_value( string $setting_key ): mixed { public function get_setting_default_value( string $setting_key ): mixed {
foreach ($this->settings_sections as $settings_section) { foreach ( $this->settings_sections as $settings_section ) {
$setting = $settings_section->get_setting($setting_key); $setting = $settings_section->get_setting( $setting_key );
if ($setting) return $setting->get_default_value(); if ( $setting ) {
return $setting->get_default_value();
}
} }
return null; return null;
@ -167,7 +173,7 @@ class Settings {
/** /**
* Set a setting's value by its key. * Set a setting's value by its key.
* *
* @param string $setting_key The key of the setting to search for. * @param string $setting_key The key of the setting to search for.
* @param mixed $setting_value The new value to set. * @param mixed $setting_value The new value to set.
* @return mixed 'True' if the value was successfully set. 'False' otherwise. * @return mixed 'True' if the value was successfully set. 'False' otherwise.
* *
@ -176,11 +182,13 @@ class Settings {
* @todo This is an _O(n)_ linear search. Explore more scaleable alternatives. * @todo This is an _O(n)_ linear search. Explore more scaleable alternatives.
* @todo How to handle settings with a value of `null`? * @todo How to handle settings with a value of `null`?
*/ */
public function set_setting_value( string $setting_key, mixed $setting_value ): ?bool { public function set_setting_value( string $setting_key, $setting_value ): ?bool {
foreach ($this->settings_sections as $settings_section) { foreach ( $this->settings_sections as $settings_section ) {
$setting = $settings_section->get_setting($setting_key); $setting = $settings_section->get_setting( $setting_key );
if ($setting) return $setting->set_value( $setting_value ); if ( $setting ) {
return $setting->set_value( $setting_value );
}
} }
return false; return false;
@ -202,7 +210,7 @@ class Settings {
/** /**
* Updates a whole Setting Container on save. * Updates a whole Setting Container on save.
* *
* @param string $options_group_slug Options group slug to save. * @param string $options_group_slug Options group slug to save.
* @param array $new_values The new Settings value(s). * @param array $new_values The new Settings value(s).
* *
* @since 1.5.0 * @since 1.5.0
@ -210,8 +218,8 @@ class Settings {
*/ */
public function save_options_group( string $options_group_slug, array $new_values ): bool { public function save_options_group( string $options_group_slug, array $new_values ): bool {
if ( update_option( $options_group_slug, $new_values ) ) { if ( update_option( $options_group_slug, $new_values ) ) {
foreach ($this->settings_sections as $settings_section) { foreach ( $this->settings_sections as $settings_section ) {
if ($settings_section->get_options_group_slug() === $options_group_slug) { if ( $settings_section->get_options_group_slug() === $options_group_slug ) {
$settings_section->load_options_group(); $settings_section->load_options_group();
} }
} }
@ -227,16 +235,16 @@ class Settings {
* @since 2.8.0 Renamed from `load_all()` to `load_options_groups()`. * @since 2.8.0 Renamed from `load_all()` to `load_options_groups()`.
*/ */
protected function load_options_groups(): void { protected function load_options_groups(): void {
foreach ($this->options_group_slug as $options_group_slug) { foreach ( $this->options_group_slug as $options_group_slug ) {
$options_group = get_option($options_group_slug); $options_group = get_option( $options_group_slug );
if (!! $options_group) { if ( ! ! $options_group ) {
foreach ($this->settings_sections as $settings_section) { foreach ( $this->settings_sections as $settings_section ) {
if ($settings_section->get_options_group_slug() === $options_group_slug) { if ( $settings_section->get_options_group_slug() === $options_group_slug ) {
$settings_section->load_options_group(); $settings_section->load_options_group();
} }
} }
} }
} }
} }
} }

View file

@ -42,13 +42,13 @@ class Setting {
* @since 2.8.0 * @since 2.8.0
*/ */
const FONT_SIZE_UNIT_OPTIONS = array( const FONT_SIZE_UNIT_OPTIONS = array(
'em' => 'em', 'em' => 'em',
'rem' => 'rem', 'rem' => 'rem',
'px' => 'pixels', 'px' => 'pixels',
'pt' => 'points', 'pt' => 'points',
'pc' => 'picas', 'pc' => 'picas',
'mm' => 'millimeters', 'mm' => 'millimeters',
'%' => 'per cent', '%' => 'per cent',
); );
/** /**
@ -59,12 +59,12 @@ class Setting {
* @since 2.8.0 * @since 2.8.0
*/ */
const TEXT_ELEMENT_OPTIONS = array( const TEXT_ELEMENT_OPTIONS = array(
'p' => 'paragraph', 'p' => 'paragraph',
'h2' => 'heading 2', 'h2' => 'heading 2',
'h3' => 'heading 3', 'h3' => 'heading 3',
'h4' => 'heading 4', 'h4' => 'heading 4',
'h5' => 'heading 5', 'h5' => 'heading 5',
'h6' => 'heading 6', 'h6' => 'heading 6',
); );
/** /**
@ -74,7 +74,7 @@ class Setting {
* *
* @since 2.8.0 * @since 2.8.0
*/ */
protected mixed $value; protected $value;
/** /**
* Constructs the setting. * Constructs the setting.
@ -217,7 +217,7 @@ class Setting {
) { ) {
$this->value = $this->default_value; $this->value = $this->default_value;
register_setting( $this->options_group_slug, $this->key, $this->get_setting_args()); register_setting( $this->options_group_slug, $this->key, $this->get_setting_args() );
} }
/** /**
@ -230,10 +230,10 @@ class Setting {
* @since 2.8.0 * @since 2.8.0
*/ */
public function get_setting_args(): array { public function get_setting_args(): array {
return array ( return array(
'type' => $this->type, 'type' => $this->type,
'description' => $this->description, 'description' => $this->description,
'default' => $this->default_value, 'default' => $this->default_value,
); );
} }
@ -247,16 +247,16 @@ class Setting {
* @since 2.8.0 * @since 2.8.0
*/ */
public function get_setting_field_args(): array { public function get_setting_field_args(): array {
return array ( return array(
'name' => $this->key, 'name' => $this->key,
'label_for' => $this->key, 'label_for' => $this->key,
'value' => $this->value, 'value' => $this->value,
'description' => $this->description, 'description' => $this->description,
'type' => $this->input_type, 'type' => $this->input_type,
'options' => $this->input_options, 'options' => $this->input_options,
'max' => $this->input_max, 'max' => $this->input_max,
'min' => $this->input_min, 'min' => $this->input_min,
'disabled' => $this->is_disabled_or_overridden() 'disabled' => $this->is_disabled_or_overridden(),
); );
} }
@ -270,25 +270,33 @@ class Setting {
* @since 2.8.0 * @since 2.8.0
*/ */
private function is_disabled_or_overridden(): ?bool { private function is_disabled_or_overridden(): ?bool {
if (isset($this->enabled_by)) { if ( isset( $this->enabled_by ) ) {
$enabled_by_value = $this->settings->get_setting_value($this->enabled_by); $enabled_by_value = $this->settings->get_setting_value( $this->enabled_by );
$is_enabled = (isset($enabled_by_value) || 'userdefined' === $enabled_by_value); $is_enabled = ( isset( $enabled_by_value ) || 'userdefined' === $enabled_by_value );
} }
if (isset($this->overridden_by)) { if ( isset( $this->overridden_by ) ) {
$overridden_by_value = $this->settings->get_setting_value($this->overridden_by); $overridden_by_value = $this->settings->get_setting_value( $this->overridden_by );
$is_overridden = !(null === $overridden_by_value || '' === $overridden_by_value); $is_overridden = ! ( null === $overridden_by_value || '' === $overridden_by_value );
} }
if (isset($is_enabled) || isset($is_overridden)) { if ( isset( $is_enabled ) || isset( $is_overridden ) ) {
if (isset($is_enabled) && !$is_enabled) return true; if ( isset( $is_enabled ) && ! $is_enabled ) {
return true;
}
if (isset($is_enabled) && $is_enabled && (isset($is_overridden) && !$is_overridden)) return false; if ( isset( $is_enabled ) && $is_enabled && ( isset( $is_overridden ) && ! $is_overridden ) ) {
return false;
}
if (isset($is_overridden) && $is_overridden) return true; if ( isset( $is_overridden ) && $is_overridden ) {
return true;
}
return false; return false;
} else return null; } else {
return null;
}
} }
/** /**
@ -354,7 +362,7 @@ class Setting {
* *
* @since 2.8.0 * @since 2.8.0
*/ */
public function set_value(mixed $value): bool { public function set_value( $value ): bool {
$this->value = $value; $this->value = $value;
return true; return true;
} }

View file

@ -16,6 +16,10 @@ use footnotes\admin\layout\SettingsPage;
/** /**
* Class defining a group of plugin settings within a section. * Class defining a group of plugin settings within a section.
* *
* NB: the concept of a 'settings group' is just a semantic aide for developers,
* it has no relevance within WordPress itself, which only recognises settings
* sections and options groups.
*
* @package footnotes * @package footnotes
* @since 2.8.0 * @since 2.8.0
*/ */
@ -110,22 +114,22 @@ abstract class SettingsGroup {
* Add the settings for this settings group. * Add the settings for this settings group.
* *
* @abstract * @abstract
* @param array<string,mixed>|false $options Saved values for the settings in this group. 'False' if none exist. * @param array<string,mixed>|false $options Saved values for the settings in this group. 'False' if none exist.
* @return void * @return void
* *
* @since 2.8.0 * @since 2.8.0
*/ */
protected abstract function add_settings(array|false $options): void; abstract protected function add_settings( array|false $options): void;
/** /**
* Constructs settings from the provided details. * Constructs settings from the provided details.
* *
* @param array<string,mixed> $setting The setting details. * @param array<string,mixed> $setting The setting details.
* @return Setting The constructed setting object. * @return Setting The constructed setting object.
* *
* @since 2.8.0 * @since 2.8.0
*/ */
protected function add_setting(array $setting): Setting { protected function add_setting( array $setting ): Setting {
extract( $setting ); extract( $setting );
return new Setting( return new Setting(
@ -150,35 +154,38 @@ abstract class SettingsGroup {
/** /**
* Load the values for this settings group. * Load the values for this settings group.
* *
* @param array<string,mixed>|false $options Saved values for the settings in this group. 'False' if none exist. * @param array<string,mixed>|false $options Saved values for the settings in this group. 'False' if none exist.
* @return void * @return void
* *
* @since 2.8.0 * @since 2.8.0
* @todo Remove settings from options group when not found. * @todo Remove settings from options group when not found.
*/ */
protected function load_values(array|false $options): void { protected function load_values( array|false $options ): void {
if ( ! $options ) return; if ( ! $options ) {
return;
}
foreach ( $options as $setting_key => $setting_value ) { foreach ( $options as $setting_key => $setting_value ) {
if ( array_key_exists( $setting_key, $this->settings ) ) if ( array_key_exists( $setting_key, $this->settings ) ) {
$this->settings[$setting_key]->set_value( $setting_value ); $this->settings[ $setting_key ]->set_value( $setting_value );
} }
}
} }
/** /**
* Adds all the settings fields for this group to the admin. dashboard. * Adds all the settings fields for this group to the admin. dashboard.
* *
* @param SettingsPage $component The admin. dashboard settings page. * @param SettingsPage $component The admin. dashboard settings page.
* @return void * @return void
* *
* @since 2.8.0 * @since 2.8.0
*/ */
public function add_settings_fields(SettingsPage $component): void { public function add_settings_fields( SettingsPage $component ): void {
foreach ($this->settings as $setting) { foreach ( $this->settings as $setting ) {
add_settings_field( add_settings_field(
$setting->key, $setting->key,
__( $setting->name, 'footnotes' ), __( $setting->name, 'footnotes' ),
array ($component, 'setting_field_callback'), array( $component, 'setting_field_callback' ),
'footnotes', 'footnotes',
$setting->get_section_slug(), $setting->get_section_slug(),
$setting->get_setting_field_args() $setting->get_setting_field_args()
@ -187,43 +194,56 @@ abstract class SettingsGroup {
} }
/** /**
* Retrieve a setting by its key.
*
* @see Settings::get_setting() * @see Settings::get_setting()
*/ */
public function get_setting(string $setting_key): ?Setting { public function get_setting( string $setting_key ): ?Setting {
foreach ($this->settings as $setting) { foreach ( $this->settings as $setting ) {
if ($setting->key === $setting_key) return $setting; if ( $setting->key === $setting_key ) {
return $setting;
}
} }
return null; return null;
} }
/** /**
* Creates an options group from the values of the settings in this section.
*
* @see SettingsSection::get_options() * @see SettingsSection::get_options()
*/ */
public function get_options(): array { public function get_options(): array {
$options = array(); $options = array();
foreach ($this->settings as $setting) { foreach ( $this->settings as $setting ) {
$options[$setting->key] = $setting->get_value(); $options[ $setting->key ] = $setting->get_value();
} }
return $options; return $options;
} }
/** /**
* Get a setting's value by its key.
*
* @see Settings::get_setting_value() * @see Settings::get_setting_value()
*/ */
public function get_setting_value(string $setting_key) { public function get_setting_value( string $setting_key ) {
$setting = $this->get_setting($setting_key); $setting = $this->get_setting( $setting_key );
if (! $setting) return null; if ( ! $setting ) {
else return $setting->value ?? $setting->default_value; return null;
} else {
return $setting->value ?? $setting->default_value;
}
} }
/** /**
* Set a setting's value by its key.
*
* @see Settings::set_setting_value() * @see Settings::set_setting_value()
*/ */
public function set_setting_value(string $setting_key, $value): bool { public function set_setting_value( string $setting_key, $value ): bool {
return $this->get_setting($setting_key)->set_value($value); return $this->get_setting( $setting_key )->set_value( $value );
} }
} }

View file

@ -72,11 +72,11 @@ abstract class SettingsSection {
} }
public function load_options_group(): void { public function load_options_group(): void {
$options_group = get_option($this->options_group_slug); $options_group = get_option( $this->options_group_slug );
if (!! $options_group) { if ( ! ! $options_group ) {
foreach ($options_group as $setting_key => $setting_value) { foreach ( $options_group as $setting_key => $setting_value ) {
$this->set_setting_value($setting_key, $setting_value); $this->set_setting_value( $setting_key, $setting_value );
} }
} }
} }
@ -84,20 +84,20 @@ abstract class SettingsSection {
public function add_settings_section(): void { public function add_settings_section(): void {
add_settings_section( add_settings_section(
$this->section_slug, $this->section_slug,
__( $this->title, 'footnotes'), __( $this->title, 'footnotes' ),
array($this, 'setting_section_callback'), array( $this, 'setting_section_callback' ),
'footnotes' 'footnotes'
); );
} }
public function add_settings_fields($component): void { public function add_settings_fields( $component ): void {
foreach($this->settings_groups as $settings_group) { foreach ( $this->settings_groups as $settings_group ) {
$settings_group->add_settings_fields($component); $settings_group->add_settings_fields( $component );
} }
} }
public function setting_section_callback(): void { public function setting_section_callback(): void {
echo "<hr>"; echo '<hr>';
} }
/** /**
@ -108,7 +108,7 @@ abstract class SettingsSection {
* *
* @since 2.8.0 * @since 2.8.0
*/ */
protected abstract function add_settings_groups(): void; abstract protected function add_settings_groups(): void;
public function get_options_group_slug(): string { public function get_options_group_slug(): string {
return $this->options_group_slug; return $this->options_group_slug;
@ -139,23 +139,27 @@ abstract class SettingsSection {
/** /**
* Gets a settings groups from this section by its ID. * Gets a settings groups from this section by its ID.
* *
* @param string group_id The ID of the settings group. * @param string $group_id The ID of the settings group.
* @return ?SettingsGroup The section group. 'None' if none found. * @return ?SettingsGroup The section group. 'None' if none found.
* *
* @since 2.8.0 * @since 2.8.0
*/ */
public function get_settings_group(string $group_id): ?SettingsGroup { public function get_settings_group( string $group_id ): ?SettingsGroup {
return $this->settings_groups[$group_id] ?? null; return $this->settings_groups[ $group_id ] ?? null;
} }
/** /**
* Retrieve a setting by its key.
*
* @see Settings::get_setting() * @see Settings::get_setting()
*/ */
public function get_setting(string $setting_key): ?Setting { public function get_setting( string $setting_key ): ?Setting {
foreach ($this->settings_groups as $settings_group) { foreach ( $this->settings_groups as $settings_group ) {
$setting = $settings_group->get_setting($setting_key); $setting = $settings_group->get_setting( $setting_key );
if ($setting) return $setting; if ( $setting ) {
return $setting;
}
} }
return null; return null;
@ -171,30 +175,40 @@ abstract class SettingsSection {
public function get_options(): array { public function get_options(): array {
$options = array(); $options = array();
foreach ($this->settings_groups as $settings_group) { foreach ( $this->settings_groups as $settings_group ) {
$options = array_merge($options, $settings_group->get_options()); $options = array_merge( $options, $settings_group->get_options() );
} }
return $options; return $options;
} }
/** /**
* Retrieve a setting's default value by its key.
*
* @see Settings::get_setting_value() * @see Settings::get_setting_value()
*/ */
public function get_setting_value(string $setting_key) { public function get_setting_value( string $setting_key ) {
$setting = $this->get_setting($setting_key); $setting = $this->get_setting( $setting_key );
if (! $setting) return null; if ( ! $setting ) {
else return $setting->value ?? $setting->default_value ?? trigger_error("No default value found for ".$setting_key.".", E_USER_ERROR); return null;
} else {
return $setting->value ?? $setting->default_value ?? trigger_error( 'No default value found for ' . $setting_key . '.', E_USER_ERROR );
}
} }
/** /**
* Set a setting's value by its key.
*
* @see Settings::set_setting_value() * @see Settings::set_setting_value()
*/ */
public function set_setting_value(string $setting_key, $value): ?bool { public function set_setting_value( string $setting_key, $value ): ?bool {
$setting = $this->get_setting($setting_key); $setting = $this->get_setting( $setting_key );
if (! $setting) return null; if ( ! $setting ) {
else return $setting->set_value($value); return null;
} else {
return $setting->set_value( $value );
}
} }
} }

View file

@ -49,28 +49,15 @@ class CustomCSSSettingsGroup extends SettingsGroup {
* Convert from `string` to `array`. * Convert from `string` to `array`.
*/ */
public const CUSTOM_CSS = array( public const CUSTOM_CSS = array(
'key' => 'footnote_inputfield_custom_css_new', 'key' => 'footnote_inputfield_custom_css_new',
'name' => 'Your Existing Custom CSS Code', 'name' => 'Your Existing Custom CSS Code',
'type' => 'string', 'type' => 'string',
'input_type' => 'textarea', 'input_type' => 'textarea',
); );
/** /**
* Load the required dependencies. * Add the settings for this settings group.
* *
* Include the following files that provide the settings for this plugin:
*
* - {@see SettingsGroup}: defines a group of settings.
*
* @see SettingsGroup::load_dependencies()
*/
protected function load_dependencies(): void {
parent::load_dependencies();
require_once plugin_dir_path( __DIR__ ) . 'class-settings-group.php';
}
/**
* @see SettingsGroup::add_settings() * @see SettingsGroup::add_settings()
*/ */
protected function add_settings( array|false $options ): void { protected function add_settings( array|false $options ): void {

View file

@ -35,9 +35,9 @@ class CustomCSSSettingsSection extends SettingsSection {
/** /**
* Constructs the settings section. * Constructs the settings section.
* *
* @param string options_group_slug The slug of the settings section's options group. * @param string $options_group_slug The slug of the settings section's options group.
* @param string section_slug The slug of the settings section. * @param string $section_slug The slug of the settings section.
* @param string title The name of the settings section. * @param string $title The name of the settings section.
* *
* @since 2.8.0 * @since 2.8.0
*/ */
@ -55,12 +55,12 @@ class CustomCSSSettingsSection extends SettingsSection {
private Settings $settings private Settings $settings
) { ) {
$this->options_group_slug = $options_group_slug; $this->options_group_slug = $options_group_slug;
$this->section_slug = $section_slug; $this->section_slug = $section_slug;
$this->title = $title; $this->title = $title;
$this->load_dependencies(); $this->load_dependencies();
$this->add_settings_groups(get_option( $this->options_group_slug )); $this->add_settings_groups( get_option( $this->options_group_slug ) );
$this->load_options_group(); $this->load_options_group();
} }
@ -76,19 +76,19 @@ class CustomCSSSettingsSection extends SettingsSection {
* @see SettingsSection::load_dependencies() * @see SettingsSection::load_dependencies()
*/ */
protected function load_dependencies(): void { protected function load_dependencies(): void {
parent::load_dependencies(); parent::load_dependencies();
require_once plugin_dir_path( __DIR__ ) . 'class-settings-section.php'; require_once plugin_dir_path( __DIR__ ) . 'custom-css/class-customcsssettingsgroup.php';
require_once plugin_dir_path( __DIR__ ) . 'custom-css/class-custom-css-settings-group.php';
} }
/** /**
* Add the settings groups for this settings section.
*
* @see SettingsSection::add_settings_groups() * @see SettingsSection::add_settings_groups()
*/ */
protected function add_settings_groups(): void { protected function add_settings_groups(): void {
$this->settings_groups = array ( $this->settings_groups = array(
CustomCSSSettingsGroup::GROUP_ID => new CustomCSSSettingsGroup($this->options_group_slug, $this->section_slug, $this->settings ), CustomCSSSettingsGroup::GROUP_ID => new CustomCSSSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ),
); );
} }
} }

View file

@ -62,6 +62,8 @@ class AMPCompatSettingsGroup extends SettingsGroup {
); );
/** /**
* Add the settings for this settings group.
*
* @see SettingsGroup::add_settings() * @see SettingsGroup::add_settings()
*/ */
protected function add_settings( array|false $options ): void { protected function add_settings( array|false $options ): void {

View file

@ -22,7 +22,7 @@ use footnotes\includes\settings\SettingsGroup;
* @since 2.8.0 * @since 2.8.0
*/ */
class ExcerptsSettingsGroup extends SettingsGroup { class ExcerptsSettingsGroup extends SettingsGroup {
/** /**
* Setting group ID. * Setting group ID.
* *
* @var string * @var string
@ -59,11 +59,13 @@ class ExcerptsSettingsGroup extends SettingsGroup {
'input_options' => array( 'input_options' => array(
'yes' => 'Yes, generate excerpts from posts with effectively processed footnotes and other markup', 'yes' => 'Yes, generate excerpts from posts with effectively processed footnotes and other markup',
'no' => 'No, generate excerpts from posts but remove all footnotes and output plain text', 'no' => 'No, generate excerpts from posts but remove all footnotes and output plain text',
'manual' => 'Yes but run the process only to display tooltips in manual excerpts with footnote short codes' 'manual' => 'Yes but run the process only to display tooltips in manual excerpts with footnote short codes',
), ),
); );
/** /**
* Add the settings for this settings group.
*
* @see SettingsGroup::add_settings() * @see SettingsGroup::add_settings()
*/ */
protected function add_settings( array|false $options ): void { protected function add_settings( array|false $options ): void {

View file

@ -41,9 +41,9 @@ class GeneralSettingsSection extends SettingsSection {
/** /**
* Constructs the settings section. * Constructs the settings section.
* *
* @param string options_group_slug The slug of the settings section's options group. * @param string $options_group_slug The slug of the settings section's options group.
* @param string section_slug The slug of the settings section. * @param string $section_slug The slug of the settings section.
* @param string title The name of the settings section. * @param string $title The name of the settings section.
* *
* @since 2.8.0 * @since 2.8.0
*/ */
@ -91,17 +91,19 @@ class GeneralSettingsSection extends SettingsSection {
protected function load_dependencies(): void { protected function load_dependencies(): void {
parent::load_dependencies(); parent::load_dependencies();
require_once plugin_dir_path( __DIR__ ) . 'general/class-reference-container-settings-group.php'; require_once plugin_dir_path( __DIR__ ) . 'general/class-referencecontainersettingsgroup.php';
require_once plugin_dir_path( __DIR__ ) . 'general/class-scrolling-settings-group.php'; require_once plugin_dir_path( __DIR__ ) . 'general/class-scrollingsettingsgroup.php';
require_once plugin_dir_path( __DIR__ ) . 'general/class-shortcode-settings-group.php'; require_once plugin_dir_path( __DIR__ ) . 'general/class-shortcodesettingsgroup.php';
require_once plugin_dir_path( __DIR__ ) . 'general/class-numbering-settings-group.php'; require_once plugin_dir_path( __DIR__ ) . 'general/class-numberingsettingsgroup.php';
require_once plugin_dir_path( __DIR__ ) . 'general/class-hard-links-settings-group.php'; require_once plugin_dir_path( __DIR__ ) . 'general/class-hardlinkssettingsgroup.php';
require_once plugin_dir_path( __DIR__ ) . 'general/class-love-settings-group.php'; require_once plugin_dir_path( __DIR__ ) . 'general/class-lovesettingsgroup.php';
require_once plugin_dir_path( __DIR__ ) . 'general/class-excerpts-settings-group.php'; require_once plugin_dir_path( __DIR__ ) . 'general/class-excerptssettingsgroup.php';
require_once plugin_dir_path( __DIR__ ) . 'general/class-amp-compat-settings-group.php'; require_once plugin_dir_path( __DIR__ ) . 'general/class-ampcompatsettingsgroup.php';
} }
/** /**
* Add the settings groups for this settings section.
*
* @see SettingsSection::add_settings_groups() * @see SettingsSection::add_settings_groups()
*/ */
protected function add_settings_groups(): void { protected function add_settings_groups(): void {

View file

@ -159,16 +159,18 @@ class HardLinksSettingsGroup extends SettingsGroup {
); );
/** /**
* Add the settings for this settings group.
*
* @see SettingsGroup::add_settings() * @see SettingsGroup::add_settings()
*/ */
protected function add_settings( array|false $options ): void { protected function add_settings( array|false $options ): void {
$this->settings = array( $this->settings = array(
self::FOOTNOTES_HARD_LINKS_ENABLE['key'] => $this->add_setting( self::FOOTNOTES_HARD_LINKS_ENABLE ), self::FOOTNOTES_HARD_LINKS_ENABLE['key'] => $this->add_setting( self::FOOTNOTES_HARD_LINKS_ENABLE ),
self::REFERRER_FRAGMENT_ID_SLUG['key'] => $this->add_setting( self::REFERRER_FRAGMENT_ID_SLUG ), self::REFERRER_FRAGMENT_ID_SLUG['key'] => $this->add_setting( self::REFERRER_FRAGMENT_ID_SLUG ),
self::FOOTNOTE_FRAGMENT_ID_SLUG['key'] => $this->add_setting( self::FOOTNOTE_FRAGMENT_ID_SLUG ), self::FOOTNOTE_FRAGMENT_ID_SLUG['key'] => $this->add_setting( self::FOOTNOTE_FRAGMENT_ID_SLUG ),
self::HARD_LINK_IDS_SEPARATOR['key'] => $this->add_setting( self::HARD_LINK_IDS_SEPARATOR ), self::HARD_LINK_IDS_SEPARATOR['key'] => $this->add_setting( self::HARD_LINK_IDS_SEPARATOR ),
self::FOOTNOTES_BACKLINK_TOOLTIP_ENABLE['key'] => $this->add_setting( self::FOOTNOTES_BACKLINK_TOOLTIP_ENABLE ), self::FOOTNOTES_BACKLINK_TOOLTIP_ENABLE['key'] => $this->add_setting( self::FOOTNOTES_BACKLINK_TOOLTIP_ENABLE ),
self::FOOTNOTES_BACKLINK_TOOLTIP_TEXT['key'] => $this->add_setting( self::FOOTNOTES_BACKLINK_TOOLTIP_TEXT ), self::FOOTNOTES_BACKLINK_TOOLTIP_TEXT['key'] => $this->add_setting( self::FOOTNOTES_BACKLINK_TOOLTIP_TEXT ),
); );
$this->load_values( $options ); $this->load_values( $options );

View file

@ -74,7 +74,7 @@ class LoveSettingsGroup extends SettingsGroup {
'type' => 'string', 'type' => 'string',
'input_type' => 'select', 'input_type' => 'select',
'input_options' => array( 'input_options' => array(
// Logo only. // Logo only.
'text-3' => self::PLUGIN_SYMBOL, 'text-3' => self::PLUGIN_SYMBOL,
// Logo followed by heart symbol. // Logo followed by heart symbol.
'text-4' => self::PLUGIN_SYMBOL . ' ' . self::LOVE_SYMBOL, 'text-4' => self::PLUGIN_SYMBOL . ' ' . self::LOVE_SYMBOL,
@ -114,11 +114,13 @@ class LoveSettingsGroup extends SettingsGroup {
); );
/** /**
* Add the settings for this settings group.
*
* @see SettingsGroup::add_settings() * @see SettingsGroup::add_settings()
*/ */
protected function add_settings( array|false $options ): void { protected function add_settings( array|false $options ): void {
$this->settings = array( $this->settings = array(
self::FOOTNOTES_LOVE['key'] => $this->add_setting( self::FOOTNOTES_LOVE ), self::FOOTNOTES_LOVE['key'] => $this->add_setting( self::FOOTNOTES_LOVE ),
self::FOOTNOTES_NO_LOVE_SLUG['key'] => $this->add_setting( self::FOOTNOTES_NO_LOVE_SLUG ), self::FOOTNOTES_NO_LOVE_SLUG['key'] => $this->add_setting( self::FOOTNOTES_NO_LOVE_SLUG ),
); );

View file

@ -77,7 +77,7 @@ class NumberingSettingsGroup extends SettingsGroup {
'type' => 'string', 'type' => 'string',
'input_type' => 'select', 'input_type' => 'select',
'input_options' => array( 'input_options' => array(
'arabic_plain' => 'plain Arabic numbers (1, 2, 3, 4, 5, &hellip;)', 'arabic_plain' => 'plain Arabic numbers (1, 2, 3, 4, 5, &hellip;)',
'arabic_leading' => 'zero-padded Arabic numbers (01, 02, 03, 04, 05, &hellip;)', 'arabic_leading' => 'zero-padded Arabic numbers (01, 02, 03, 04, 05, &hellip;)',
'latin_low' => 'lowercase Latin letters (a, b, c, d, e, &hellip;)', 'latin_low' => 'lowercase Latin letters (a, b, c, d, e, &hellip;)',
'latin_high' => 'uppercase Latin letters (A, B, C, D, E, &hellip;)', 'latin_high' => 'uppercase Latin letters (A, B, C, D, E, &hellip;)',
@ -87,12 +87,14 @@ class NumberingSettingsGroup extends SettingsGroup {
); );
/** /**
* Add the settings for this settings group.
*
* @see SettingsGroup::add_settings() * @see SettingsGroup::add_settings()
*/ */
protected function add_settings( array|false $options ): void { protected function add_settings( array|false $options ): void {
$this->settings = array( $this->settings = array(
self::COMBINE_IDENTICAL_FOOTNOTES['key'] => $this->add_setting( self::COMBINE_IDENTICAL_FOOTNOTES ), self::COMBINE_IDENTICAL_FOOTNOTES['key'] => $this->add_setting( self::COMBINE_IDENTICAL_FOOTNOTES ),
self::FOOTNOTES_COUNTER_STYLE['key'] => $this->add_setting( self::FOOTNOTES_COUNTER_STYLE ), self::FOOTNOTES_COUNTER_STYLE['key'] => $this->add_setting( self::FOOTNOTES_COUNTER_STYLE ),
); );
$this->load_values( $options ); $this->load_values( $options );

View file

@ -71,7 +71,7 @@ class ReferenceContainerSettingsGroup extends SettingsGroup {
'default_value' => 'p', 'default_value' => 'p',
'type' => 'string', 'type' => 'string',
'input_type' => 'select', 'input_type' => 'select',
'input_options' => Setting::TEXT_ELEMENT_OPTIONS 'input_options' => Setting::TEXT_ELEMENT_OPTIONS,
); );
/** /**
@ -689,6 +689,8 @@ class ReferenceContainerSettingsGroup extends SettingsGroup {
); );
/** /**
* Add the settings for this settings group.
*
* @see SettingsGroup::add_settings() * @see SettingsGroup::add_settings()
*/ */
protected function add_settings( array|false $options ): void { protected function add_settings( array|false $options ): void {

View file

@ -181,6 +181,8 @@ class ScrollingSettingsGroup extends SettingsGroup {
); );
/** /**
* Add the settings for this settings group.
*
* @see SettingsGroup::add_settings() * @see SettingsGroup::add_settings()
*/ */
protected function add_settings( array|false $options ): void { protected function add_settings( array|false $options ): void {

View file

@ -150,6 +150,8 @@ class ShortcodeSettingsGroup extends SettingsGroup {
); );
/** /**
* Add the settings for this settings group.
*
* @see SettingsGroup::add_settings() * @see SettingsGroup::add_settings()
*/ */
protected function add_settings( array|false $options ): void { protected function add_settings( array|false $options ): void {

View file

@ -56,18 +56,18 @@ class BacklinkSymbolSettingsGroup extends SettingsGroup {
'default_value' => 0, 'default_value' => 0,
'type' => 'number', 'type' => 'number',
'input_type' => 'select', 'input_type' => 'select',
'input_options' => array( 'input_options' => array(
'&#8593;', '&#8593;',
'&#8613;', '&#8613;',
'&#8607;', '&#8607;',
'&#8617;', '&#8617;',
'&#8626;', '&#8626;',
'&#8629;', '&#8629;',
'&#8657;', '&#8657;',
'&#8673;', '&#8673;',
'&#8679;', '&#8679;',
'&#65514;' '&#65514;',
), ),
'overridden_by' => self::HYPERLINK_ARROW_USER_DEFINED, 'overridden_by' => self::HYPERLINK_ARROW_USER_DEFINED,
); );
@ -81,19 +81,21 @@ class BacklinkSymbolSettingsGroup extends SettingsGroup {
* Convert from `string` to `array`. * Convert from `string` to `array`.
*/ */
const HYPERLINK_ARROW_USER_DEFINED = array( const HYPERLINK_ARROW_USER_DEFINED = array(
'key' => 'footnote_inputfield_custom_hyperlink_symbol_user', 'key' => 'footnote_inputfield_custom_hyperlink_symbol_user',
'name' => 'Input the Backlink Symbol', 'name' => 'Input the Backlink Symbol',
'description' => 'Your input overrides the selection.', 'description' => 'Your input overrides the selection.',
'type' => 'string', 'type' => 'string',
'input_type' => 'text', 'input_type' => 'text',
); );
/** /**
* Add the settings for this settings group.
*
* @see SettingsGroup::add_settings() * @see SettingsGroup::add_settings()
*/ */
protected function add_settings( array|false $options ): void { protected function add_settings( array|false $options ): void {
$this->settings = array( $this->settings = array(
self::HYPERLINK_ARROW['key'] => $this->add_setting( self::HYPERLINK_ARROW ), self::HYPERLINK_ARROW['key'] => $this->add_setting( self::HYPERLINK_ARROW ),
self::HYPERLINK_ARROW_USER_DEFINED['key'] => $this->add_setting( self::HYPERLINK_ARROW_USER_DEFINED ), self::HYPERLINK_ARROW_USER_DEFINED['key'] => $this->add_setting( self::HYPERLINK_ARROW_USER_DEFINED ),
); );

View file

@ -32,9 +32,9 @@ class ReferrersAndTooltipsSettingsSection extends SettingsSection {
/** /**
* Constructs the settings section. * Constructs the settings section.
* *
* @param string options_group_slug The slug of the settings section's options group. * @param string $options_group_slug The slug of the settings section's options group.
* @param string section_slug The slug of the settings section. * @param string $section_slug The slug of the settings section.
* @param string title The name of the settings section. * @param string $title The name of the settings section.
* *
* @since 2.8.0 * @since 2.8.0
*/ */
@ -52,12 +52,12 @@ class ReferrersAndTooltipsSettingsSection extends SettingsSection {
private Settings $settings private Settings $settings
) { ) {
$this->options_group_slug = $options_group_slug; $this->options_group_slug = $options_group_slug;
$this->section_slug = $section_slug; $this->section_slug = $section_slug;
$this->title = $title; $this->title = $title;
$this->load_dependencies(); $this->load_dependencies();
$this->add_settings_groups(get_option( $this->options_group_slug )); $this->add_settings_groups( get_option( $this->options_group_slug ) );
$this->load_options_group(); $this->load_options_group();
} }
@ -82,34 +82,36 @@ class ReferrersAndTooltipsSettingsSection extends SettingsSection {
* @see SettingsSection::load_dependencies() * @see SettingsSection::load_dependencies()
*/ */
protected function load_dependencies(): void { protected function load_dependencies(): void {
parent::load_dependencies(); parent::load_dependencies();
require_once plugin_dir_path( __DIR__ ) . 'referrers-and-tooltips/class-backlink-symbol-settings-group.php'; require_once plugin_dir_path( __DIR__ ) . 'referrers-and-tooltips/class-backlinksymbolsettingsgroup.php';
require_once plugin_dir_path( __DIR__ ) . 'referrers-and-tooltips/class-referrers-settings-group.php'; require_once plugin_dir_path( __DIR__ ) . 'referrers-and-tooltips/class-referrerssettingsgroup.php';
require_once plugin_dir_path( __DIR__ ) . 'referrers-and-tooltips/class-referrers-in-labels-settings-group.php'; require_once plugin_dir_path( __DIR__ ) . 'referrers-and-tooltips/class-referrersinlabelssettingsgroup.php';
require_once plugin_dir_path( __DIR__ ) . 'referrers-and-tooltips/class-tooltips-settings-group.php'; require_once plugin_dir_path( __DIR__ ) . 'referrers-and-tooltips/class-tooltipssettingsgroup.php';
require_once plugin_dir_path( __DIR__ ) . 'referrers-and-tooltips/class-tooltip-appearance-settings-group.php'; require_once plugin_dir_path( __DIR__ ) . 'referrers-and-tooltips/class-tooltipappearancesettingsgroup.php';
require_once plugin_dir_path( __DIR__ ) . 'referrers-and-tooltips/class-tooltip-dimensions-settings-group.php'; require_once plugin_dir_path( __DIR__ ) . 'referrers-and-tooltips/class-tooltipdimensionssettingsgroup.php';
require_once plugin_dir_path( __DIR__ ) . 'referrers-and-tooltips/class-tooltip-position-settings-group.php'; require_once plugin_dir_path( __DIR__ ) . 'referrers-and-tooltips/class-tooltippositionsettingsgroup.php';
require_once plugin_dir_path( __DIR__ ) . 'referrers-and-tooltips/class-tooltip-text-settings-group.php'; require_once plugin_dir_path( __DIR__ ) . 'referrers-and-tooltips/class-tooltiptextsettingsgroup.php';
require_once plugin_dir_path( __DIR__ ) . 'referrers-and-tooltips/class-tooltip-timing-settings-group.php'; require_once plugin_dir_path( __DIR__ ) . 'referrers-and-tooltips/class-tooltiptimingsettingsgroup.php';
require_once plugin_dir_path( __DIR__ ) . 'referrers-and-tooltips/class-tooltip-truncation-settings-group.php'; require_once plugin_dir_path( __DIR__ ) . 'referrers-and-tooltips/class-tooltiptruncationsettingsgroup.php';
} }
/** /**
* Add the settings groups for this settings section.
*
* @see SettingsSection::add_settings_groups() * @see SettingsSection::add_settings_groups()
*/ */
protected function add_settings_groups(): void { protected function add_settings_groups(): void {
$this->settings_groups = array ( $this->settings_groups = array(
BacklinkSymbolSettingsGroup::GROUP_ID => new BacklinkSymbolSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ), BacklinkSymbolSettingsGroup::GROUP_ID => new BacklinkSymbolSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ),
ReferrersSettingsGroup::GROUP_ID => new ReferrersSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ), ReferrersSettingsGroup::GROUP_ID => new ReferrersSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ),
ReferrersInLabelsSettingsGroup::GROUP_ID => new ReferrersInLabelsSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ), ReferrersInLabelsSettingsGroup::GROUP_ID => new ReferrersInLabelsSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ),
TooltipsSettingsGroup::GROUP_ID => new TooltipsSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ), TooltipsSettingsGroup::GROUP_ID => new TooltipsSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ),
TooltipAppearanceSettingsGroup::GROUP_ID => new TooltipAppearanceSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ), TooltipAppearanceSettingsGroup::GROUP_ID => new TooltipAppearanceSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ),
TooltipDimensionsSettingsGroup::GROUP_ID => new TooltipDimensionsSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ), TooltipDimensionsSettingsGroup::GROUP_ID => new TooltipDimensionsSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ),
TooltipPositionSettingsGroup::GROUP_ID => new TooltipPositionSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ), TooltipPositionSettingsGroup::GROUP_ID => new TooltipPositionSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ),
TooltipTextSettingsGroup::GROUP_ID => new TooltipTextSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ), TooltipTextSettingsGroup::GROUP_ID => new TooltipTextSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ),
TooltipTimingSettingsGroup::GROUP_ID => new TooltipTimingSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ), TooltipTimingSettingsGroup::GROUP_ID => new TooltipTimingSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ),
TooltipTruncationSettingsGroup::GROUP_ID => new TooltipTruncationSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ), TooltipTruncationSettingsGroup::GROUP_ID => new TooltipTruncationSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ),
); );
} }

View file

@ -64,13 +64,15 @@ class ReferrersInLabelsSettingsGroup extends SettingsGroup {
'type' => 'string', 'type' => 'string',
'input_type' => 'select', 'input_type' => 'select',
'input_options' => array( 'input_options' => array(
'none' => '0. No problem or solved otherwise', 'none' => '0. No problem or solved otherwise',
'move' => 'A. Footnotes are moved out and appended after the label\'s end (recommended)', 'move' => 'A. Footnotes are moved out and appended after the label\'s end (recommended)',
'disconnect' => 'B. Labels with footnotes are disconnected from input element (discouraged)' 'disconnect' => 'B. Labels with footnotes are disconnected from input element (discouraged)',
), ),
); );
/** /**
* Add the settings for this settings group.
*
* @see SettingsGroup::add_settings() * @see SettingsGroup::add_settings()
*/ */
protected function add_settings( array|false $options ): void { protected function add_settings( array|false $options ): void {

View file

@ -74,9 +74,9 @@ class ReferrersSettingsGroup extends SettingsGroup {
'type' => 'string', 'type' => 'string',
'input_type' => 'select', 'input_type' => 'select',
'input_options' => array( 'input_options' => array(
'no' => 'No', 'no' => 'No',
'referrers' => 'Footnote referrers', 'referrers' => 'Footnote referrers',
'all' => 'All superscript elements' 'all' => 'All superscript elements',
), ),
); );
@ -139,6 +139,8 @@ class ReferrersSettingsGroup extends SettingsGroup {
); );
/** /**
* Add the settings for this settings group.
*
* @see SettingsGroup::add_settings() * @see SettingsGroup::add_settings()
*/ */
protected function add_settings( array|false $options ): void { protected function add_settings( array|false $options ): void {
@ -146,8 +148,8 @@ class ReferrersSettingsGroup extends SettingsGroup {
self::FOOTNOTES_REFERRER_SUPERSCRIPT_TAGS['key'] => $this->add_setting( self::FOOTNOTES_REFERRER_SUPERSCRIPT_TAGS ), self::FOOTNOTES_REFERRER_SUPERSCRIPT_TAGS['key'] => $this->add_setting( self::FOOTNOTES_REFERRER_SUPERSCRIPT_TAGS ),
self::FOOTNOTE_REFERRERS_NORMAL_SUPERSCRIPT['key'] => $this->add_setting( self::FOOTNOTE_REFERRERS_NORMAL_SUPERSCRIPT ), self::FOOTNOTE_REFERRERS_NORMAL_SUPERSCRIPT['key'] => $this->add_setting( self::FOOTNOTE_REFERRERS_NORMAL_SUPERSCRIPT ),
self::FOOTNOTES_STYLING_BEFORE['key'] => $this->add_setting( self::FOOTNOTES_STYLING_BEFORE ), self::FOOTNOTES_STYLING_BEFORE['key'] => $this->add_setting( self::FOOTNOTES_STYLING_BEFORE ),
self::FOOTNOTES_STYLING_AFTER['key'] => $this->add_setting( self::FOOTNOTES_STYLING_AFTER ), self::FOOTNOTES_STYLING_AFTER['key'] => $this->add_setting( self::FOOTNOTES_STYLING_AFTER ),
self::LINK_ELEMENT_ENABLED['key'] => $this->add_setting( self::LINK_ELEMENT_ENABLED ), self::LINK_ELEMENT_ENABLED['key'] => $this->add_setting( self::LINK_ELEMENT_ENABLED ),
); );
$this->load_values( $options ); $this->load_values( $options );

View file

@ -79,7 +79,7 @@ class TooltipAppearanceSettingsGroup extends SettingsGroup {
'type' => 'number', 'type' => 'number',
'input_type' => 'number', 'input_type' => 'number',
'input_max' => 50.0, 'input_max' => 50.0,
'input_min' => 0.0 'input_min' => 0.0,
); );
/** /**
@ -97,7 +97,7 @@ class TooltipAppearanceSettingsGroup extends SettingsGroup {
'default_value' => 'px', 'default_value' => 'px',
'type' => 'string', 'type' => 'string',
'input_type' => 'select', 'input_type' => 'select',
'input_options' => Setting::FONT_SIZE_UNIT_OPTIONS 'input_options' => Setting::FONT_SIZE_UNIT_OPTIONS,
); );
/** /**
@ -157,8 +157,8 @@ class TooltipAppearanceSettingsGroup extends SettingsGroup {
'default_value' => 1.0, 'default_value' => 1.0,
'type' => 'number', 'type' => 'number',
'input_type' => 'number', 'input_type' => 'number',
'input_max' => 4.0, 'input_max' => 4.0,
'input_min' => 0.0, 'input_min' => 0.0,
); );
/** /**
@ -195,8 +195,8 @@ class TooltipAppearanceSettingsGroup extends SettingsGroup {
'default_value' => 0, 'default_value' => 0,
'type' => 'number', 'type' => 'number',
'input_type' => 'number', 'input_type' => 'number',
'input_max' => 500, 'input_max' => 500,
'input_min' => 0, 'input_min' => 0,
); );
/** /**
@ -218,14 +218,16 @@ class TooltipAppearanceSettingsGroup extends SettingsGroup {
); );
/** /**
* Add the settings for this settings group.
*
* @see SettingsGroup::add_settings() * @see SettingsGroup::add_settings()
*/ */
protected function add_settings( array|false $options ): void { protected function add_settings( array|false $options ): void {
$this->settings = array( $this->settings = array(
self::MOUSE_OVER_BOX_FONT_SIZE_ENABLED['key'] => $this->add_setting( self::MOUSE_OVER_BOX_FONT_SIZE_ENABLED ), self::MOUSE_OVER_BOX_FONT_SIZE_ENABLED['key'] => $this->add_setting( self::MOUSE_OVER_BOX_FONT_SIZE_ENABLED ),
self::MOUSE_OVER_BOX_FONT_SIZE_SCALAR['key'] => $this->add_setting( self::MOUSE_OVER_BOX_FONT_SIZE_SCALAR ), self::MOUSE_OVER_BOX_FONT_SIZE_SCALAR['key'] => $this->add_setting( self::MOUSE_OVER_BOX_FONT_SIZE_SCALAR ),
self::MOUSE_OVER_BOX_FONT_SIZE_UNIT['key'] => $this->add_setting( self::MOUSE_OVER_BOX_FONT_SIZE_UNIT ), self::MOUSE_OVER_BOX_FONT_SIZE_UNIT['key'] => $this->add_setting( self::MOUSE_OVER_BOX_FONT_SIZE_UNIT ),
self::FOOTNOTES_MOUSE_OVER_BOX_COLOR['key'] => $this->add_setting( self::FOOTNOTES_MOUSE_OVER_BOX_COLOR ), self::FOOTNOTES_MOUSE_OVER_BOX_COLOR['key'] => $this->add_setting( self::FOOTNOTES_MOUSE_OVER_BOX_COLOR ),
self::FOOTNOTES_MOUSE_OVER_BOX_BACKGROUND['key'] => $this->add_setting( self::FOOTNOTES_MOUSE_OVER_BOX_BACKGROUND ), self::FOOTNOTES_MOUSE_OVER_BOX_BACKGROUND['key'] => $this->add_setting( self::FOOTNOTES_MOUSE_OVER_BOX_BACKGROUND ),
self::FOOTNOTES_MOUSE_OVER_BOX_BORDER_WIDTH['key'] => $this->add_setting( self::FOOTNOTES_MOUSE_OVER_BOX_BORDER_WIDTH ), self::FOOTNOTES_MOUSE_OVER_BOX_BORDER_WIDTH['key'] => $this->add_setting( self::FOOTNOTES_MOUSE_OVER_BOX_BORDER_WIDTH ),
self::FOOTNOTES_MOUSE_OVER_BOX_BORDER_COLOR['key'] => $this->add_setting( self::FOOTNOTES_MOUSE_OVER_BOX_BORDER_COLOR ), self::FOOTNOTES_MOUSE_OVER_BOX_BORDER_COLOR['key'] => $this->add_setting( self::FOOTNOTES_MOUSE_OVER_BOX_BORDER_COLOR ),

View file

@ -78,6 +78,8 @@ class TooltipDimensionsSettingsGroup extends SettingsGroup {
); );
/** /**
* Add the settings for this settings group.
*
* @see SettingsGroup::add_settings() * @see SettingsGroup::add_settings()
*/ */
protected function add_settings( array|false $options ): void { protected function add_settings( array|false $options ): void {

View file

@ -89,10 +89,10 @@ class TooltipPositionSettingsGroup extends SettingsGroup {
'type' => 'string', 'type' => 'string',
'input_type' => 'select', 'input_type' => 'select',
'input_options' => array( 'input_options' => array(
'top left' => 'top left', 'top left' => 'top left',
'top right' => 'top right', 'top right' => 'top right',
'bottom right' => 'bottom right', 'bottom right' => 'bottom right',
'bottom left' => 'bottom left', 'bottom left' => 'bottom left',
), ),
); );
@ -172,6 +172,8 @@ class TooltipPositionSettingsGroup extends SettingsGroup {
); );
/** /**
* Add the settings for this settings group.
*
* @see SettingsGroup::add_settings() * @see SettingsGroup::add_settings()
*/ */
protected function add_settings( array|false $options ): void { protected function add_settings( array|false $options ): void {

View file

@ -83,6 +83,8 @@ class TooltipsSettingsGroup extends SettingsGroup {
); );
/** /**
* Add the settings for this settings group.
*
* @see SettingsGroup::add_settings() * @see SettingsGroup::add_settings()
*/ */
protected function add_settings( array|false $options ): void { protected function add_settings( array|false $options ): void {

View file

@ -111,6 +111,8 @@ class TooltipTextSettingsGroup extends SettingsGroup {
); );
/** /**
* Add the settings for this settings group.
*
* @see SettingsGroup::add_settings() * @see SettingsGroup::add_settings()
*/ */
protected function add_settings( array|false $options ): void { protected function add_settings( array|false $options ): void {

View file

@ -120,13 +120,15 @@ class TooltipTimingSettingsGroup extends SettingsGroup {
); );
/** /**
* Add the settings for this settings group.
*
* @see SettingsGroup::add_settings() * @see SettingsGroup::add_settings()
*/ */
protected function add_settings( array|false $options ): void { protected function add_settings( array|false $options ): void {
$this->settings = array( $this->settings = array(
self::MOUSE_OVER_BOX_FADE_IN_DELAY['key'] => $this->add_setting( self::MOUSE_OVER_BOX_FADE_IN_DELAY ), self::MOUSE_OVER_BOX_FADE_IN_DELAY['key'] => $this->add_setting( self::MOUSE_OVER_BOX_FADE_IN_DELAY ),
self::MOUSE_OVER_BOX_FADE_IN_DURATION['key'] => $this->add_setting( self::MOUSE_OVER_BOX_FADE_IN_DURATION ), self::MOUSE_OVER_BOX_FADE_IN_DURATION['key'] => $this->add_setting( self::MOUSE_OVER_BOX_FADE_IN_DURATION ),
self::MOUSE_OVER_BOX_FADE_OUT_DELAY['key'] => $this->add_setting( self::MOUSE_OVER_BOX_FADE_OUT_DELAY ), self::MOUSE_OVER_BOX_FADE_OUT_DELAY['key'] => $this->add_setting( self::MOUSE_OVER_BOX_FADE_OUT_DELAY ),
self::MOUSE_OVER_BOX_FADE_OUT_DURATION['key'] => $this->add_setting( self::MOUSE_OVER_BOX_FADE_OUT_DURATION ), self::MOUSE_OVER_BOX_FADE_OUT_DURATION['key'] => $this->add_setting( self::MOUSE_OVER_BOX_FADE_OUT_DURATION ),
); );

View file

@ -101,6 +101,8 @@ class TooltipTruncationSettingsGroup extends SettingsGroup {
); );
/** /**
* Add the settings for this settings group.
*
* @see SettingsGroup::add_settings() * @see SettingsGroup::add_settings()
*/ */
protected function add_settings( array|false $options ): void { protected function add_settings( array|false $options ): void {

View file

@ -34,9 +34,9 @@ class ScopeAndPrioritySettingsSection extends SettingsSection {
/** /**
* Constructs the settings section. * Constructs the settings section.
* *
* @param string options_group_slug The slug of the settings section's options group. * @param string $options_group_slug The slug of the settings section's options group.
* @param string section_slug The slug of the settings section. * @param string $section_slug The slug of the settings section.
* @param string title The name of the settings section. * @param string $title The name of the settings section.
* *
* @since 2.8.0 * @since 2.8.0
*/ */
@ -54,12 +54,12 @@ class ScopeAndPrioritySettingsSection extends SettingsSection {
private Settings $settings private Settings $settings
) { ) {
$this->options_group_slug = $options_group_slug; $this->options_group_slug = $options_group_slug;
$this->section_slug = $section_slug; $this->section_slug = $section_slug;
$this->title = $title; $this->title = $title;
$this->load_dependencies(); $this->load_dependencies();
$this->add_settings_groups(get_option( $this->options_group_slug )); $this->add_settings_groups( get_option( $this->options_group_slug ) );
$this->load_options_group(); $this->load_options_group();
} }
@ -75,17 +75,19 @@ class ScopeAndPrioritySettingsSection extends SettingsSection {
* @see SettingsSection::load_dependencies() * @see SettingsSection::load_dependencies()
*/ */
protected function load_dependencies(): void { protected function load_dependencies(): void {
parent::load_dependencies(); parent::load_dependencies();
require_once plugin_dir_path( __DIR__ ) . 'scope-and-priority/class-wordpress-hooks-settings-group.php'; require_once plugin_dir_path( __DIR__ ) . 'scope-and-priority/class-wordpresshookssettingsgroup.php';
} }
/** /**
* Add the settings groups for this settings section.
*
* @see SettingsSection::add_settings_groups() * @see SettingsSection::add_settings_groups()
*/ */
protected function add_settings_groups(): void { protected function add_settings_groups(): void {
$this->settings_groups = array ( $this->settings_groups = array(
WordPressHooksSettingsGroup::GROUP_ID => new WordPressHooksSettingsGroup($this->options_group_slug, $this->section_slug, $this->settings ), WordPressHooksSettingsGroup::GROUP_ID => new WordPressHooksSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ),
); );
} }
} }

View file

@ -268,19 +268,21 @@ class WordPressHooksSettingsGroup extends SettingsGroup {
); );
/** /**
* Add the settings for this settings group.
*
* @see SettingsGroup::add_settings() * @see SettingsGroup::add_settings()
*/ */
protected function add_settings( array|false $options ): void { protected function add_settings( array|false $options ): void {
$this->settings = array( $this->settings = array(
self::EXPERT_LOOKUP_THE_TITLE['key'] => $this->add_setting( self::EXPERT_LOOKUP_THE_TITLE ), self::EXPERT_LOOKUP_THE_TITLE['key'] => $this->add_setting( self::EXPERT_LOOKUP_THE_TITLE ),
self::EXPERT_LOOKUP_THE_TITLE_PRIORITY_LEVEL['key'] => $this->add_setting( self::EXPERT_LOOKUP_THE_TITLE_PRIORITY_LEVEL ), self::EXPERT_LOOKUP_THE_TITLE_PRIORITY_LEVEL['key'] => $this->add_setting( self::EXPERT_LOOKUP_THE_TITLE_PRIORITY_LEVEL ),
self::EXPERT_LOOKUP_THE_CONTENT['key'] => $this->add_setting( self::EXPERT_LOOKUP_THE_CONTENT ), self::EXPERT_LOOKUP_THE_CONTENT['key'] => $this->add_setting( self::EXPERT_LOOKUP_THE_CONTENT ),
self::EXPERT_LOOKUP_THE_CONTENT_PRIORITY_LEVEL['key'] => $this->add_setting( self::EXPERT_LOOKUP_THE_CONTENT_PRIORITY_LEVEL ), self::EXPERT_LOOKUP_THE_CONTENT_PRIORITY_LEVEL['key'] => $this->add_setting( self::EXPERT_LOOKUP_THE_CONTENT_PRIORITY_LEVEL ),
self::EXPERT_LOOKUP_THE_EXCERPT['key'] => $this->add_setting( self::EXPERT_LOOKUP_THE_EXCERPT ), self::EXPERT_LOOKUP_THE_EXCERPT['key'] => $this->add_setting( self::EXPERT_LOOKUP_THE_EXCERPT ),
self::EXPERT_LOOKUP_THE_EXCERPT_PRIORITY_LEVEL['key'] => $this->add_setting( self::EXPERT_LOOKUP_THE_EXCERPT_PRIORITY_LEVEL ), self::EXPERT_LOOKUP_THE_EXCERPT_PRIORITY_LEVEL['key'] => $this->add_setting( self::EXPERT_LOOKUP_THE_EXCERPT_PRIORITY_LEVEL ),
self::EXPERT_LOOKUP_WIDGET_TITLE['key'] => $this->add_setting( self::EXPERT_LOOKUP_WIDGET_TITLE ), self::EXPERT_LOOKUP_WIDGET_TITLE['key'] => $this->add_setting( self::EXPERT_LOOKUP_WIDGET_TITLE ),
self::EXPERT_LOOKUP_WIDGET_TITLE_PRIORITY_LEVEL['key'] => $this->add_setting( self::EXPERT_LOOKUP_WIDGET_TITLE_PRIORITY_LEVEL ), self::EXPERT_LOOKUP_WIDGET_TITLE_PRIORITY_LEVEL['key'] => $this->add_setting( self::EXPERT_LOOKUP_WIDGET_TITLE_PRIORITY_LEVEL ),
self::EXPERT_LOOKUP_WIDGET_TEXT['key'] => $this->add_setting( self::EXPERT_LOOKUP_WIDGET_TEXT ), self::EXPERT_LOOKUP_WIDGET_TEXT['key'] => $this->add_setting( self::EXPERT_LOOKUP_WIDGET_TEXT ),
self::EXPERT_LOOKUP_WIDGET_TEXT_PRIORITY_LEVEL['key'] => $this->add_setting( self::EXPERT_LOOKUP_WIDGET_TEXT_PRIORITY_LEVEL ), self::EXPERT_LOOKUP_WIDGET_TEXT_PRIORITY_LEVEL['key'] => $this->add_setting( self::EXPERT_LOOKUP_WIDGET_TEXT_PRIORITY_LEVEL ),
); );

View file

@ -12,9 +12,7 @@ namespace footnotes\general;
use footnotes\includes\{Footnotes, Convert, Settings}; use footnotes\includes\{Footnotes, Convert, Settings};
/** /* TODO Replace with constant imports. */
* @todo Replace with constant imports.
*/
use footnotes\includes\settings\general\ReferenceContainerSettingsGroup; use footnotes\includes\settings\general\ReferenceContainerSettingsGroup;
use footnotes\includes\settings\general\AMPCompatSettingsGroup; use footnotes\includes\settings\general\AMPCompatSettingsGroup;
use footnotes\includes\settings\referrersandtooltips\TooltipsSettingsGroup; use footnotes\includes\settings\referrersandtooltips\TooltipsSettingsGroup;
@ -123,7 +121,7 @@ class General {
* @since 2.8.0 * @since 2.8.0
*/ */
private Settings $settings private Settings $settings
) { ) {
$this->load_dependencies(); $this->load_dependencies();
@ -156,7 +154,7 @@ class General {
$this->reference_container_widget = new Widget\Reference_Container( $this->plugin_name ); $this->reference_container_widget = new Widget\Reference_Container( $this->plugin_name );
$this->task = new Parser($this->settings); $this->task = new Parser( $this->settings );
} }
/** /**

View file

@ -15,29 +15,27 @@ namespace footnotes\general;
use footnotes\includes\{Settings, Config, Convert, Template}; use footnotes\includes\{Settings, Config, Convert, Template};
/** /* TODO Replace with constant imports. */
* @todo Replace with constant imports.
*/
use footnotes\includes\settings\general\{ use footnotes\includes\settings\general\{
ExcerptsSettingsGroup, ExcerptsSettingsGroup,
HardLinksSettingsGroup, HardLinksSettingsGroup,
LoveSettingsGroup, LoveSettingsGroup,
NumberingSettingsGroup, NumberingSettingsGroup,
ReferenceContainerSettingsGroup, ReferenceContainerSettingsGroup,
ScrollingSettingsGroup, ScrollingSettingsGroup,
ShortcodeSettingsGroup, ShortcodeSettingsGroup,
}; };
use footnotes\includes\settings\referrersandtooltips\{ use footnotes\includes\settings\referrersandtooltips\{
BacklinkSymbolSettingsGroup, BacklinkSymbolSettingsGroup,
ReferrersSettingsGroup, ReferrersSettingsGroup,
ReferrersInLabelsSettingsGroup, ReferrersInLabelsSettingsGroup,
TooltipsSettingsGroup, TooltipsSettingsGroup,
TooltipAppearanceSettingsGroup, TooltipAppearanceSettingsGroup,
TooltipDimensionsSettingsGroup, TooltipDimensionsSettingsGroup,
TooltipPositionSettingsGroup, TooltipPositionSettingsGroup,
TooltipTextSettingsGroup, TooltipTextSettingsGroup,
TooltipTimingSettingsGroup, TooltipTimingSettingsGroup,
TooltipTruncationSettingsGroup TooltipTruncationSettingsGroup
}; };
use footnotes\includes\settings\scopeandpriority\WordPressHooksSettingsGroup; use footnotes\includes\settings\scopeandpriority\WordPressHooksSettingsGroup;
use footnotes\includes\settings\customcss\CustomCSSSettingsGroup; use footnotes\includes\settings\customcss\CustomCSSSettingsGroup;
@ -284,7 +282,7 @@ class Parser {
* @since 2.8.0 * @since 2.8.0
*/ */
private Settings $settings private Settings $settings
) { ) {
// TODO: Reorg dependencies. // TODO: Reorg dependencies.
require_once plugin_dir_path( __DIR__ ) . 'includes/class-config.php'; require_once plugin_dir_path( __DIR__ ) . 'includes/class-config.php';
require_once plugin_dir_path( __DIR__ ) . 'includes/class-convert.php'; require_once plugin_dir_path( __DIR__ ) . 'includes/class-convert.php';
@ -481,7 +479,7 @@ class Parser {
// Reference container label bottom border. // Reference container label bottom border.
if ( ( $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_LABEL_BOTTOM_BORDER['key'] ) ) ) { if ( ( $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_LABEL_BOTTOM_BORDER['key'] ) ) ) {
echo '.footnote_container_prepare > '; echo '.footnote_container_prepare > ';
echo $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_LABEL_ELEMENT['key'] ) ; echo $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_LABEL_ELEMENT['key'] );
echo " {border-bottom: 1px solid #aaaaaa !important;}\r\n"; echo " {border-bottom: 1px solid #aaaaaa !important;}\r\n";
} }
@ -545,7 +543,7 @@ class Parser {
} }
// Hard links scroll offset. // Hard links scroll offset.
// TODO: remove cast // TODO: remove cast.
self::$hard_links_enabled = (bool) $this->settings->get_setting_value( HardLinksSettingsGroup::FOOTNOTES_HARD_LINKS_ENABLE['key'] ); self::$hard_links_enabled = (bool) $this->settings->get_setting_value( HardLinksSettingsGroup::FOOTNOTES_HARD_LINKS_ENABLE['key'] );
// Correct hard links enabled status depending on AMP-compatible or alternative reference container enabled status. // Correct hard links enabled status depending on AMP-compatible or alternative reference container enabled status.
@ -721,7 +719,7 @@ class Parser {
* for transparency. It isnt indented though (the PHP open tag neither). * for transparency. It isnt indented though (the PHP open tag neither).
*/ */
if ( General::$alternative_tooltips_enabled ) { if ( General::$alternative_tooltips_enabled ) {
echo (' echo ( '
<script content="text/javascript"> <script content="text/javascript">
function footnote_tooltip_show(footnote_tooltip_id) { function footnote_tooltip_show(footnote_tooltip_id) {
document.getElementById(footnote_tooltip_id).classList.remove("hidden"); document.getElementById(footnote_tooltip_id).classList.remove("hidden");
@ -732,7 +730,7 @@ class Parser {
document.getElementById(footnote_tooltip_id).classList.add("hidden"); document.getElementById(footnote_tooltip_id).classList.add("hidden");
} }
</script> </script>
'); ' );
}; };
} }
@ -820,7 +818,7 @@ class Parser {
$footnote_section_shortcode_length = strlen( $footnote_section_shortcode ); $footnote_section_shortcode_length = strlen( $footnote_section_shortcode );
// TODO: Replace with `str_contains()`, but currently breaks Rector downgrade. // TODO: Replace with `str_contains()`, but currently breaks Rector downgrade.
// https://github.com/rectorphp/rector/issues/6315 // <https://github.com/rectorphp/rector/issues/6315>.
if ( ! strpos( $content, (string) $footnote_section_shortcode ) ) { if ( ! strpos( $content, (string) $footnote_section_shortcode ) ) {
// phpcs:disable WordPress.PHP.YodaConditions.NotYoda // phpcs:disable WordPress.PHP.YodaConditions.NotYoda
@ -838,8 +836,8 @@ class Parser {
$section_end = strpos( $rest_content, (string) $footnote_section_shortcode ); $section_end = strpos( $rest_content, (string) $footnote_section_shortcode );
$sections_raw[] = substr( $rest_content, 0, $section_end ); $sections_raw[] = substr( $rest_content, 0, $section_end );
$rest_content = substr( $rest_content, $section_end + $footnote_section_shortcode_length ); $rest_content = substr( $rest_content, $section_end + $footnote_section_shortcode_length );
// TODO: Replace with `str_contains()`, but currently breaks Rector downgrade. // TODO: Replace with `str_contains()`, but currently breaks Rector downgrade.
// https://github.com/rectorphp/rector/issues/6315 // <https://github.com/rectorphp/rector/issues/6315>.
} while ( strpos( $rest_content, (string) $footnote_section_shortcode ) ); } while ( strpos( $rest_content, (string) $footnote_section_shortcode ) );
$sections_raw[] = $rest_content; $sections_raw[] = $rest_content;
@ -1199,7 +1197,7 @@ class Parser {
*/ */
// If enabled. // If enabled.
if ( $this->settings->get_setting( ShortcodeSettingsGroup::FOOTNOTE_SHORTCODE_SYNTAX_VALIDATION_ENABLE['key']) ->get_value() ) { if ( $this->settings->get_setting( ShortcodeSettingsGroup::FOOTNOTE_SHORTCODE_SYNTAX_VALIDATION_ENABLE['key'] )->get_value() ) {
// Apply different regex depending on whether start shortcode is double/triple opening parenthesis. // Apply different regex depending on whether start shortcode is double/triple opening parenthesis.
if ( '((' === self::$start_tag || '(((' === self::$start_tag ) { if ( '((' === self::$start_tag || '(((' === self::$start_tag ) {
@ -1709,11 +1707,11 @@ class Parser {
*/ */
// If the backlink symbol is enabled. // If the backlink symbol is enabled.
if ( $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_BACKLINK_SYMBOL_ENABLE['key'] )) { if ( $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_BACKLINK_SYMBOL_ENABLE['key'] ) ) {
$arrow_setting = $this->settings->get_setting( BacklinkSymbolSettingsGroup::HYPERLINK_ARROW['key']); $arrow_setting = $this->settings->get_setting( BacklinkSymbolSettingsGroup::HYPERLINK_ARROW['key'] );
// Get html arrow. // Get html arrow.
$arrow = $arrow_setting->get_input_options()[$arrow_setting->get_value() || 0]; $arrow = $arrow_setting->get_input_options()[ $arrow_setting->get_value() || 0 ];
// Get user defined arrow. // Get user defined arrow.
$arrow_user_defined = $this->settings->get_setting_value( BacklinkSymbolSettingsGroup::HYPERLINK_ARROW_USER_DEFINED['key'] ); $arrow_user_defined = $this->settings->get_setting_value( BacklinkSymbolSettingsGroup::HYPERLINK_ARROW_USER_DEFINED['key'] );
@ -1745,10 +1743,9 @@ class Parser {
// If it is not, check which option is on. // If it is not, check which option is on.
$separator_option = $this->settings->get_setting_value( ReferenceContainerSettingsGroup::BACKLINKS_SEPARATOR_OPTION['key'] ); $separator_option = $this->settings->get_setting_value( ReferenceContainerSettingsGroup::BACKLINKS_SEPARATOR_OPTION['key'] );
// TODO: replace with `match` (but currently it breaks the Rector // TODO: replace with `match` (but currently it breaks the Rector downgrade to PHP 7.4.
// downgrade to PHP 7.4. // <https://github.com/rectorphp/rector/issues/6315>.
// https://github.com/rectorphp/rector/issues/6315 switch ( $separator_option ) {
switch ($separator_option) {
case 'comma': case 'comma':
$separator = ','; $separator = ',';
break; break;
@ -1779,10 +1776,9 @@ class Parser {
// If it is not, check which option is on. // If it is not, check which option is on.
$terminator_option = $this->settings->get_setting_value( ReferenceContainerSettingsGroup::BACKLINKS_TERMINATOR_OPTION['key'] ); $terminator_option = $this->settings->get_setting_value( ReferenceContainerSettingsGroup::BACKLINKS_TERMINATOR_OPTION['key'] );
// TODO: replace with `match` (but currently it breaks the Rector // TODO: replace with `match` (but currently it breaks the Rector downgrade to PHP 7.4.
// downgrade to PHP 7.4. // <https://github.com/rectorphp/rector/issues/6315>.
// https://github.com/rectorphp/rector/issues/6315 switch ( $terminator_option ) {
switch ($terminator_option) {
case 'period': case 'period':
$terminator = '.'; $terminator = '.';
break; break;
@ -2138,7 +2134,7 @@ class Parser {
} }
// Call again for robustness when priority levels don't match any longer. // Call again for robustness when priority levels don't match any longer.
// TODO: remove cast // TODO: remove cast.
self::$scroll_offset = (int) $this->settings->get_setting_value( ScrollingSettingsGroup::FOOTNOTES_SCROLL_OFFSET['key'] ); self::$scroll_offset = (int) $this->settings->get_setting_value( ScrollingSettingsGroup::FOOTNOTES_SCROLL_OFFSET['key'] );
// Streamline. // Streamline.