diff --git a/src/admin/class-admin.php b/src/admin/class-admin.php
index dca4f23..e4e01ce 100644
--- a/src/admin/class-admin.php
+++ b/src/admin/class-admin.php
@@ -15,7 +15,8 @@ declare(strict_types=1);
namespace footnotes\admin;
-use footnotes\includes\Footnotes;
+use footnotes\admin\layout\Init as SettingsPageInit;
+use footnotes\includes\{Footnotes, Settings};
/**
* Class provide all admin-specific functionality of the plugin.
@@ -58,7 +59,15 @@ class Admin {
* @since 2.8.0
* @see Footnotes::$version
*/
- private string $version
+ private string $version,
+
+ /**
+ * The plugin settings object.
+ *
+ * @access private
+ * @since 2.8.0
+ */
+ private Settings $settings
) {
$this->load_dependencies();
@@ -151,7 +160,7 @@ class Admin {
*/
require_once plugin_dir_path( __DIR__ ) . 'admin/layout/class-init.php';
- new layout\Init( $this->plugin_name );
+ new SettingsPageInit( $this->plugin_name, $this->settings );
}
}
diff --git a/src/admin/layout/class-engine.php b/src/admin/layout/class-engine.php
index 68abfc6..946ac3b 100644
--- a/src/admin/layout/class-engine.php
+++ b/src/admin/layout/class-engine.php
@@ -101,10 +101,10 @@ abstract class Engine {
*/
public function add_settings_sections(): void {
$this->sections = array(
- Settings::instance()->settings_sections['general']->get_section_slug() => Settings::instance()->settings_sections['general'],
- Settings::instance()->settings_sections['referrers_and_tooltips']->get_section_slug() => Settings::instance()->settings_sections['referrers_and_tooltips'],
- Settings::instance()->settings_sections['scope_and_priority']->get_section_slug() => Settings::instance()->settings_sections['scope_and_priority'],
- Settings::instance()->settings_sections['custom_css']->get_section_slug() => Settings::instance()->settings_sections['custom_css'],
+ $this->settings->settings_sections['general']->get_section_slug() => $this->settings->settings_sections['general'],
+ $this->settings->settings_sections['referrers_and_tooltips']->get_section_slug() => $this->settings->settings_sections['referrers_and_tooltips'],
+ $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'],
);
/*foreach ( $this->get_sections() as $section ) {
@@ -325,7 +325,7 @@ abstract class Engine {
$return = array();
$return['id'] = $setting_key_name;
$return['name'] = $setting_key_name;
- $return['value'] = esc_attr( Settings::instance()->get( $setting_key_name ) );
+ $return['value'] = esc_attr( $this->settings->get( $setting_key_name ) );
return $return;
}
@@ -370,39 +370,21 @@ abstract class Engine {
*/
return sprintf( '', $setting_name, $caption );
}
-
- /**
- * Constructs the HTML for a text 'input' element.
- *
- * @access protected
- * @param string $setting_name Setting key.
- * @param int $max_length Maximum length of the input. Default length 999 chars.
- * @param bool $readonly Set the input to be read only. Default `false`.
- * @param bool $hidden Set the input to be hidden. Default `false`.
- *
- * @since 1.5.0
- * @todo Refactor HTML generation.
- */
- protected function add_text_box( string $setting_name, int $max_length = 999, bool $readonly = false, bool $hidden = false ): string {
- $style = '';
- if ( $hidden ) {
- $style .= 'display:none;';
- }
- return sprintf(
- '',
- $setting_name,
- $setting_name,
- $max_length,
- $style,
- get_option($setting_name),
- $readonly ? 'readonly="readonly"' : ''
- );
- }
/**************************************************************************
* NEW METHODS
**************************************************************************/
+ /**
+ * Constructs the HTML for a text 'input' element.
+ *
+ * @access protected
+ * @param array $args Input arguments. @see {Setting::get_setting_field_args()}.
+ *
+ * @since 1.5.0
+ * @since 2.8.0 Rename function from 'add_text_box' to 'add_input_text'.
+ * Replace multiple arguments with single 'args' array.
+ */
protected function add_input_text( array $args ): void {
extract( $args );
@@ -418,7 +400,16 @@ abstract class Engine {
) );
}
- protected function add_input_textarea( array $args ): void {
+ /**
+ * Constructs the HTML for a 'textarea' element.
+ *
+ * @access protected
+ * @param array $args Input arguments. @see {Setting::get_setting_field_args()}.
+ *
+ * @since 1.5.0
+ * @since 2.8.0 Replace 'p_str_setting_name' argument with 'args' array.
+ */
+ protected function add_textarea( array $args ): void {
extract( $args );
echo ( sprintf(
@@ -432,22 +423,44 @@ abstract class Engine {
) );
}
+ /**
+ * Constructs the HTML for a numeric 'input' element.
+ *
+ * @access protected
+ * @param array $args Input arguments. @see {Setting::get_setting_field_args()}.
+ *
+ * @since 1.5.0
+ * @since 2.1.4 Add step argument and 'number_format()' to allow decimals
+ * @since 2.8.0 Rename function from 'add_num_box' to 'add_input_number'.
+ * Replace multiple arguments with single 'args' array.
+ */
protected function add_input_number( array $args ): void {
extract( $args );
echo ( sprintf(
- '',
+ '',
$name,
$name,
isset($max) ? ' max="'.$max.'"' : '',
isset($min) ? ' min="'.$min.'"' : '',
- $value,
+ is_float($value) ? number_format( $value, 1 ) : $value,
+ is_float($value) ? ' step="0.1"' : '',
isset($readonly) ? ' readonly="readonly"' : '',
$disabled ? ' disabled': ''
) );
}
-
- protected function add_input_select( array $args ): void {
+
+ /**
+ * Constructs the HTML for a 'select' element.
+ *
+ * @access protected
+ * @param array $args Input arguments. @see {Setting::get_setting_field_args()}.
+ *
+ * @since 1.5.0
+ * @since 2.8.0 Rename function from 'add_select_box' to 'add_select'.
+ * Replace multiple arguments with single 'args' array.
+ */
+ protected function add_select( array $args ): void {
extract( $args );
if (!isset($options)) trigger_error("No options passed to 'select' element.", E_USER_ERROR);
@@ -459,8 +472,9 @@ abstract class Engine {
'',
$option_value,
// Only check for equality, not identity, WRT backlink symbol arrows.
+ // TODO convert to strict comparison
// phpcs:disable WordPress.PHP.StrictComparisons.LooseComparison
- $option_value == $value ? ' selected' : '',
+ $value == $option_value ? ' selected' : '',
// phpcs:enable WordPress.PHP.StrictComparisons.LooseComparison
$option_text
);
@@ -475,6 +489,16 @@ abstract class Engine {
) );
}
+ /**
+ * Constructs the HTML for a checkbox 'input' element.
+ *
+ * @access protected
+ * @param array $args Input arguments. @see {Setting::get_setting_field_args()}.
+ *
+ * @since 1.5.0
+ * @since 2.8.0 Rename function from 'add_checkbox' to 'add_input_checkbox'.
+ * Replace 'p_str_setting_name' argument with 'args' array.
+ */
protected function add_input_checkbox( array $args ): void {
extract( $args );
@@ -487,6 +511,16 @@ abstract class Engine {
);
}
+ /**
+ * Constructs the HTML for a color 'input' element.
+ *
+ * @access protected
+ * @param array $args Input arguments. @see {Setting::get_setting_field_args()}.
+ *
+ * @since 1.5.6
+ * @since 2.8.0 Rename function from 'add_color_selection' to 'add_input_color'.
+ * Replace 'p_str_setting_name' argument with 'args' array.
+ */
protected function add_input_color( array $args ): void {
extract( $args );
@@ -498,143 +532,10 @@ abstract class Engine {
);
}
- /**************************************************************************
- * NEW METHODS END
- **************************************************************************/
-
- /**
- * Constructs the HTML for a checkbox 'input' element.
- *
- * @access protected
- * @param string $setting_name Setting key.
- *
- * @since 1.5.0
- * @todo Refactor HTML generation.
- */
- protected function add_checkbox( string $setting_name ): string {
- // Collect data for given settings field.
- $data = $this->load_setting( $setting_name );
- return sprintf(
- '',
- $data['name'],
- $data['id'],
- Convert::to_bool( $data['value'] ) ? 'checked="checked"' : ''
- );
- }
-
- /**
- * Constructs the HTML for a 'select' element.
- *
- * @access protected
- * @param string $setting_name Setting key.
- * @param array $options Possible options.
- *
- * @since 1.5.0
- * @todo Refactor HTML generation.
- */
- protected function add_select_box( string $setting_name, array $options ): string {
- // Collect data for given settings field.
- $data = $this->load_setting( $setting_name );
- $select_options = '';
-
- // Loop through all array keys.
- foreach ( $options as $value => $caption ) {
- $select_options .= sprintf(
- '',
- $value,
- // Only check for equality, not identity, WRT backlink symbol arrows.
- // phpcs:disable WordPress.PHP.StrictComparisons.LooseComparison
- $value == $data['value'] ? 'selected' : '',
- // phpcs:enable WordPress.PHP.StrictComparisons.LooseComparison
- $caption
- );
- }
- return sprintf(
- '',
- $data['name'],
- $data['id'],
- $select_options
- );
- }
-
- /**
- * Constructs the HTML for a 'textarea' element.
- *
- * @access protected
- * @param string $setting_name Setting key.
- *
- * @since 1.5.0
- * @todo Refactor HTML generation.
- */
- protected function add_textarea( $setting_name ): string {
- // Collect data for given settings field.
- $data = $this->load_setting( $setting_name );
- return sprintf(
- '',
- $data['name'],
- $data['id'],
- $data['value']
- );
- }
-
- /**
- * Constructs the HTML for a text 'input' element with the colour selection
- * class.
- *
- * @access protected
- * @param string $setting_name Setting key.
- *
- * @since 1.5.6
- * @todo Refactor HTML generation.
- * @todo Use proper colorpicker element.
- */
- protected function add_color_selection( string $setting_name ): string {
- // Collect data for given settings field.
- $data = $this->load_setting( $setting_name );
- return sprintf(
- '',
- $data['name'],
- $data['id'],
- $data['value']
- );
- }
-
- /**
- * Constructs the HTML for numeric 'input' element.
- *
- * @access protected
- * @param string $setting_name Setting key.
- * @param int $p_in_min Minimum value.
- * @param int $max Maximum value.
- * @param bool $deci `true` if float, `false` if integer. Default `false`.
- *
- * @since 1.5.0
- * @todo Refactor HTML generation.
- */
- protected function add_num_box( string $setting_name, int $p_in_min, int $max, bool $deci = false ): string {
- // Collect data for given settings field.
- $data = $this->load_setting( $setting_name );
-
- if ( $deci ) {
- $value = number_format( floatval( $data['value'] ), 1 );
- return sprintf(
- '',
- $data['name'],
- $data['id'],
- $value,
- $p_in_min,
- $max
- );
- }
- return sprintf(
- '',
- $data['name'],
- $data['id'],
- $data['value'],
- $p_in_min,
- $max
- );
- }
+ /******************************
+ * OLD METHODS
+ ******************************/
+
/**
* Registers all Meta boxes for a sub-page.
*
@@ -674,14 +575,16 @@ abstract class Engine {
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
+
/**
- * Save all plugin settings.
+ * Save plugin settings.
*
* @access private
* @return bool `true` on save success, else `false`.
*
* @since 1.5.0
* @todo Review nonce verification.
+ * @todo New settings require a page refresh to render correctly. Fix.
*/
private function save_settings(): bool {
$new_settings = array();
@@ -693,7 +596,7 @@ abstract class Engine {
}
// Update settings.
- return Settings::instance()->save_options( $active_section->get_options_group_slug(), $new_settings );
+ return $this->settings->save_options_group( $active_section->get_options_group_slug(), $new_settings );
}
}
diff --git a/src/admin/layout/class-init.php b/src/admin/layout/class-init.php
index bdaf216..22fb22f 100644
--- a/src/admin/layout/class-init.php
+++ b/src/admin/layout/class-init.php
@@ -43,7 +43,7 @@ class Init {
*
* @since 1.5.0
*/
- private SettingsPage $settings;
+ private SettingsPage $settings_page;
/**
* Initializes all WordPress hooks for the Plugin Settings.
@@ -60,11 +60,19 @@ class Init {
*
* @since 2.8.0
*/
- private string $plugin_name
+ private string $plugin_name,
+
+ /**
+ * The plugin settings object.
+ *
+ * @access private
+ * @since 2.8.0
+ */
+ private Settings $settings
) {
$this->load_dependencies();
- $this->settings = new SettingsPage( $this->plugin_name );
+ $this->settings_page = new SettingsPage( $this->plugin_name, $this->settings );
// Register hooks/actions.
add_action(
@@ -92,13 +100,13 @@ class Init {
* @since 1.5.0
*/
public function initialize_settings(): void {
- Settings::instance()->settings_sections['general']->add_settings_section();
- Settings::instance()->settings_sections['referrers_and_tooltips']->add_settings_section();
- Settings::instance()->settings_sections['scope_and_priority']->add_settings_section();
- Settings::instance()->settings_sections['custom_css']->add_settings_section();
+ $this->settings->settings_sections['general']->add_settings_section();
+ $this->settings->settings_sections['referrers_and_tooltips']->add_settings_section();
+ $this->settings->settings_sections['scope_and_priority']->add_settings_section();
+ $this->settings->settings_sections['custom_css']->add_settings_section();
- $this->settings->add_settings_sections();
- $this->settings->add_settings_fields();
+ $this->settings_page->add_settings_sections();
+ $this->settings_page->add_settings_fields();
}
/**
@@ -113,9 +121,9 @@ class Init {
Config::PLUGIN_PUBLIC_NAME,
'manage_options',
self::MAIN_MENU_SLUG,
- fn() => $this->settings->display_content()
+ fn() => $this->settings_page->display_content()
);
- $this->settings->register_sub_page();
+ $this->settings_page->register_sub_page();
}
// phpcs:disable WordPress.Security.NonceVerification.Missing
diff --git a/src/admin/layout/class-settings-page.php b/src/admin/layout/class-settings-page.php
index 8073e98..7d9fec1 100644
--- a/src/admin/layout/class-settings-page.php
+++ b/src/admin/layout/class-settings-page.php
@@ -43,11 +43,27 @@ class SettingsPage extends Engine {
* Initialize the class and set its properties.
*
* @since 2.8.0
- * @param string $plugin_name The name of this plugin.
*/
- public function __construct( string $plugin_name ) {
- $this->plugin_name = $plugin_name;
- }
+ public function __construct(
+ /**
+ * The ID of this plugin.
+ *
+ * @access private
+ * @var string $plugin_name The ID of this plugin.
+ *
+ * @since 2.8.0
+ */
+ protected string $plugin_name,
+
+ /**
+ * The plugin settings object.
+ *
+ * @access private
+ * @since 2.8.0
+ */
+ protected Settings $settings
+ ) {
+ }
/**
* Returns a priority index.
@@ -71,16 +87,16 @@ class SettingsPage extends Engine {
switch ($active_section->get_section_slug()) {
case 'footnotes-settings':
- Settings::instance()->settings_sections['general']->add_settings_fields($this);
+ $this->settings->settings_sections['general']->add_settings_fields($this);
break;
case 'footnotes-customize':
- Settings::instance()->settings_sections['referrers_and_tooltips']->add_settings_fields($this);
+ $this->settings->settings_sections['referrers_and_tooltips']->add_settings_fields($this);
break;
case 'footnotes-expert':
- Settings::instance()->settings_sections['scope_and_priority']->add_settings_fields($this);
+ $this->settings->settings_sections['scope_and_priority']->add_settings_fields($this);
break;
case 'footnotes-customcss':
- Settings::instance()->settings_sections['custom_css']->add_settings_fields($this);
+ $this->settings->settings_sections['custom_css']->add_settings_fields($this);
break;
case 'footnotes-how-to':
print_r("Demo goes here");
@@ -98,13 +114,13 @@ class SettingsPage extends Engine {
$this->add_input_text($args);
return;
case 'textarea':
- $this->add_input_textarea($args);
+ $this->add_textarea($args);
return;
case 'number':
$this->add_input_number($args);
return;
case 'select':
- $this->add_input_select($args);
+ $this->add_select($args);
return;
case 'checkbox':
$this->add_input_checkbox($args);
diff --git a/src/includes/class-convert.php b/src/includes/class-convert.php
index 684851a..e3a7b3f 100644
--- a/src/includes/class-convert.php
+++ b/src/includes/class-convert.php
@@ -86,10 +86,7 @@ class Convert {
public static function get_arrow( int $index = -1 ): string|array {
// Define all possible arrows.
$arrows = array( '↑', '↥', '↟', '↩', '↲', '↵', '⇑', '⇡', '⇧', '↑' );
- // Convert index to an integer.
- if ( ! is_int( $index ) ) {
- $index = (int) $index;
- }
+
// Return the whole arrow array.
if ( $index < 0 ) {
return $arrows;
diff --git a/src/includes/class-core.php b/src/includes/class-core.php
index f1dcc04..7da8aa1 100644
--- a/src/includes/class-core.php
+++ b/src/includes/class-core.php
@@ -74,6 +74,14 @@ class Core {
* @var string $version The current version of the plugin.
*/
protected string $version;
+
+ /**
+ * The plugin settings object.
+ *
+ * @access private
+ * @since 2.8.0
+ */
+ public Settings $settings;
/**
* Builds the core of the plugin.
@@ -93,6 +101,7 @@ class Core {
$this->load_dependencies();
$this->set_locale();
+ $this->settings = new Settings();
$this->define_admin_hooks();
$this->define_public_hooks();
}
@@ -223,7 +232,7 @@ class Core {
*/
private function define_admin_hooks() {
- $admin = new Admin( $this->get_plugin_name(), $this->get_version() );
+ $admin = new Admin( $this->get_plugin_name(), $this->get_version(), $this->settings );
$this->loader->add_action( 'admin_enqueue_scripts', $admin, 'enqueue_styles' );
$this->loader->add_action( 'admin_enqueue_scripts', $admin, 'enqueue_scripts' );
@@ -253,7 +262,7 @@ class Core {
*/
private function define_public_hooks() {
- $general = new General( $this->get_plugin_name(), $this->get_version() );
+ $general = new General( $this->get_plugin_name(), $this->get_version(), $this->settings );
$this->loader->add_action( 'wp_enqueue_scripts', $general, 'enqueue_styles' );
$this->loader->add_action( 'wp_enqueue_scripts', $general, 'enqueue_scripts' );
diff --git a/src/includes/class-settings.php b/src/includes/class-settings.php
index cefa64c..7c7b1ea 100644
--- a/src/includes/class-settings.php
+++ b/src/includes/class-settings.php
@@ -12,6 +12,7 @@ declare(strict_types=1);
namespace footnotes\includes;
+use footnotes\includes\Settings;
use footnotes\includes\settings\Setting;
/**
@@ -32,7 +33,7 @@ use footnotes\includes\settings\customcss\CustomCSSSettingsSection;
* @package footnotes
* @since 1.5.0
* @since 2.8.0 Renamed class from `Footnotes_Settings` to `Settings`.
- * Moved under `footnotes\includes` namespace.
+ * Moved under `footnotes\includes` namespace.
*/
class Settings {
@@ -65,15 +66,6 @@ class Settings {
/**********************************************************************
* SETTINGS STORAGE.
**********************************************************************/
-
- /**
- * Stores a singleton reference of this class.
- *
- * @since 1.5.0
- *
- * @todo Still needed?
- */
- private static ?Settings $instance = null;
/**
* Loads all Settings from each WordPress Settings Container.
@@ -84,10 +76,10 @@ class Settings {
$this->load_dependencies();
$this->settings_sections = array(
- 'general' => new GeneralSettingsSection('footnotes_storage', 'footnotes-settings', 'General Settings'),
- 'referrers_and_tooltips' => new ReferrersAndTooltipsSettingsSection('footnotes_storage_custom', 'footnotes-customize', 'Referrers and Tooltips'),
- 'scope_and_priority' => new ScopeAndPrioritySettingsSection('footnotes_storage_expert', 'footnotes-expert', 'Scope and Priority'),
- 'custom_css' => new CustomCSSSettingsSection('footnotes_storage_custom_css', 'footnotes-customcss', 'Custom CSS'),
+ 'general' => new GeneralSettingsSection('footnotes_storage', 'footnotes-settings', 'General Settings', $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),
+ 'custom_css' => new CustomCSSSettingsSection('footnotes_storage_custom_css', 'footnotes-customcss', 'Custom CSS', $this),
);
}
@@ -118,7 +110,7 @@ class Settings {
* Retrieve a setting by its key.
*
* @param string $setting_key The key of the setting to search for.
- * @return ?Setting Either the setting object, or `null` if non exists.
+ * @return ?Setting Either the setting object, or `null` if none exists.
*
* @since 2.8.0
*
@@ -133,6 +125,48 @@ class Settings {
return null;
}
+
+ /**
+ * Retrieve a setting's value by its key.
+ *
+ * @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.
+ *
+ * @since 2.8.0
+ *
+ * @todo This is an _O(n)_ linear search. Explore more scaleable alternatives.
+ * @todo How to handle settings with a value of `null`?
+ */
+ public function get_setting_value( string $setting_key ): mixed {
+ foreach ($this->settings_sections as $settings_section) {
+ $setting = $settings_section->get_setting($setting_key);
+
+ if ($setting) return $setting->get_value();
+ }
+
+ return null;
+ }
+
+ /**
+ * Retrieve a setting's defaultvalue by its key.
+ *
+ * @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.
+ *
+ * @since 2.8.0
+ *
+ * @todo This is an _O(n)_ linear search. Explore more scaleable alternatives.
+ * @todo How to handle settings with a default value of `null`?
+ */
+ public function get_setting_default_value( string $setting_key ): mixed {
+ foreach ($this->settings_sections as $settings_section) {
+ $setting = $settings_section->get_setting($setting_key);
+
+ if ($setting) return $setting->get_default_value();
+ }
+
+ return null;
+ }
/**
* Returns the name of a specified Settings Container.
@@ -147,19 +181,6 @@ class Settings {
return $this->options_group_slugs[ $index ];
}
- /**
- * Returns the default value(s) of a specific Settings Container.
- *
- * @param int $index Settings Container index.
- * @return (string|int)[] Settings Container default value(s).
- *
- * @since 1.5.6
- * @deprecated
- */
- public function get_defaults( int $index ): array {
- return $this->default_settings[ $this->get_options_group_slug[ $index ] ];
- }
-
/**
* Updates a whole Setting Container on save.
*
@@ -169,7 +190,7 @@ class Settings {
* @since 1.5.0
* @since 2.8.0 Change first parameter type from `int` to `string`.
*/
- public function save_options( 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 ) ) {
foreach ($this->settings_sections as $settings_section) {
if ($settings_section->get_options_group_slug() === $options_group_slug) {
@@ -181,86 +202,23 @@ class Settings {
return false;
}
- protected function load_options_group(): void {
- $options_group = get_option($this->options_group_slug);
-
- if (!! $options_group) {
- foreach ($options_group as $setting_key => $setting_value) {
- $this->set_setting_value($setting_key, $setting_value);
- }
- }
- }
-
- /**
- * Returns the value of specified Setting.
- *
- * @param string $key Setting key.
- * @return string|int|null Setting value, or `null` if setting key is invalid.
- *
- * @since 1.5.0
- * @todo Add return type.
- */
- public function get( string $key ) {
- return $this->settings[ $key ] ?? null;
- }
-
- /**
- * Returns a singleton of this class.
- *
- * @since 1.5.0
- * @todo Remove?
- */
- public static function instance(): self {
- // No instance defined yet, load it.
- if ( ! self::$instance ) {
- self::$instance = new self();
- }
- // Return a singleton of this class.
- return self::$instance;
- }
-
/**
* Loads all settings from each option group.
*
* @since 1.5.0
- * @since 2.8.0 Renamed from `load_all()` to `load_options()`.
+ * @since 2.8.0 Renamed from `load_all()` to `load_options_groups()`.
*/
- private function load_options(): void {
- // Clear current settings.
- $this->settings = array();
+ protected function load_options_groups(): void {
+ foreach ($this->options_group_slug as $options_group_slug) {
+ $options_group = get_option($options_group_slug);
- foreach ($this->options_group_slugs as $options_group_slug) {
- $this->settings[$options_group_slug] = $this->load_option( $options_group_slug );
+ if (!! $options_group) {
+ foreach ($this->settings_sections as $settings_section) {
+ if ($settings_section->get_options_group_slug() === $options_group_slug) {
+ $settings_section->load_options_group();
+ }
+ }
+ }
}
}
-
- /**
- * Loads all settings from a given option group.
- *
- * @param string $options_group Option group slug.
- * @return (string|int)[] Loaded settings (or defaults if specified option group is empty).
- *
- * @since 1.5.0
- * @since 2.8.0 Renamed from `load()` to `load_option()`.
- */
- private function load_option(string $options_group_slug): array {
- // Load all settings from option group.
- $options_group = get_option( $options_group_slug );
-
- // No settings found, set them to their default value.
- if ( empty( $options_group ) ) {
- print_r("Options group ".$options_group_slug." is empty!");
- return $this->default_settings[$options_group_slug];
- }
-
- foreach ( $this->default_settings[$options_group_slug] as $setting_name => $setting_value ) {
- // Available setting not found in the option group.
- if ( ! array_key_exists( $setting_name, $options_group ) ) {
- // Define the setting with its default value.
- $options_group[ $setting_name ] = $setting_value;
- }
- }
- // Return settings loaded from option group.
- return $options_group;
- }
}
diff --git a/src/includes/settings/class-setting.php b/src/includes/settings/class-setting.php
index 17a5f5e..6781275 100644
--- a/src/includes/settings/class-setting.php
+++ b/src/includes/settings/class-setting.php
@@ -10,7 +10,7 @@ declare(strict_types=1);
namespace footnotes\includes\settings;
-use footnotes\includes\Settings;
+use footnotes\includes\{Core, Settings};
/**
* Class defining a configurable plugin setting.
@@ -74,7 +74,7 @@ class Setting {
*
* @since 2.8.0
*/
- protected $value;
+ protected mixed $value;
public function __construct(
/**
@@ -136,7 +136,7 @@ class Setting {
*
* @since 2.8.0
*/
- private $default_value,
+ private mixed $default_value,
/**
* Setting data type.
@@ -172,7 +172,7 @@ class Setting {
*
* @since 2.8.0
*/
- private ?int $input_max,
+ private int|float|null $input_max,
/**
* Setting input field min. value (for 'number' inputs).
@@ -181,7 +181,7 @@ class Setting {
*
* @since 2.8.0
*/
- private ?int $input_min,
+ private int|float|null $input_min,
/**
* The setting for whether this setting is enabled or not.
@@ -199,7 +199,15 @@ class Setting {
*
* @since 2.8.0
*/
- private ?string $overridden_by,
+ private ?string $overridden_by,
+
+ /**
+ * The plugin settings object.
+ *
+ * @access private
+ * @since 2.8.0
+ */
+ private Settings $settings
) {
$this->value = $this->default_value;
@@ -214,6 +222,9 @@ class Setting {
);
}
+ /**
+ *
+ */
public function get_setting_field_args(): array {
return array (
'name' => $this->key,
@@ -229,13 +240,24 @@ class Setting {
}
private function is_disabled_or_overridden(): ?bool {
- if ($this->enabled_by) {
- $enabled_by_value = Settings::instance()->get_setting($this->enabled_by)->value;
- if ((!$enabled_by_value || $enabled_by_value !== 'userdefined')) return true;
-
- if (!$this->overridden_by) return false;
- else if (isset(Settings::instance()->get_setting($this->overridden_by)->value)) return true;
- else return false;
+ if (isset($this->enabled_by)) {
+ $enabled_by_value = $this->settings->get_setting_value($this->enabled_by);
+ $is_enabled = (isset($enabled_by_value) || 'userdefined' === $enabled_by_value);
+ }
+
+ if (isset($this->overridden_by)) {
+ $overridden_by_value = $this->settings->get_setting_value($this->overridden_by);
+ $is_overridden = !(null === $overridden_by_value || '' === $overridden_by_value);
+ }
+
+ if (isset($is_enabled) || isset($is_overridden)) {
+ if (isset($is_enabled) && !$is_enabled) return true;
+
+ if (isset($is_enabled) && $is_enabled && (isset($is_overridden) && !$is_overridden)) return false;
+
+ if (isset($is_overridden) && $is_overridden) return true;
+
+ return false;
} else return null;
}
@@ -248,16 +270,29 @@ class Setting {
}
/**
- * @todo Add type safety.
+ *
*/
- public function get_value() {
+ public function get_value(): mixed {
return $this->value ?? $this->default_value ?? null;
}
/**
- * @todo Add type safety.
+ *
*/
- public function set_value($value): bool {
+ public function get_default_value(): mixed {
+ return $this->default_value ?? null;
+ }
+
+ /**
+ *
+ */
+ public function get_input_options(): ?array {
+ return $this->input_options ?? null;
+ }
+
+ /**
+ */
+ public function set_value(mixed $value): bool {
$this->value = $value;
return true;
}
diff --git a/src/includes/settings/class-settings-group.php b/src/includes/settings/class-settings-group.php
index dc7b7f8..b5c9a97 100644
--- a/src/includes/settings/class-settings-group.php
+++ b/src/includes/settings/class-settings-group.php
@@ -10,6 +10,7 @@ declare(strict_types=1);
namespace footnotes\includes\settings;
+use footnotes\includes\Settings;
use footnotes\admin\layout as Layout;
/**
@@ -47,7 +48,7 @@ abstract class SettingsGroup {
protected array $setting_classes;
/**
- * The general settings.
+ * The settings in this group.
*
* @var Setting[]
*
@@ -72,7 +73,15 @@ abstract class SettingsGroup {
*
* @since 2.8.0
*/
- protected string $section_slug
+ protected string $section_slug,
+
+ /**
+ * The plugin settings object.
+ *
+ * @access private
+ * @since 2.8.0
+ */
+ protected Settings $settings_obj
) {
$this->load_dependencies();
@@ -102,7 +111,8 @@ abstract class SettingsGroup {
$input_max ?? null,
$input_min ?? null,
$enabled_by['key'] ?? null,
- $overridden_by['key'] ?? null
+ $overridden_by['key'] ?? null,
+ $this->settings_obj
);
}
@@ -111,9 +121,8 @@ abstract class SettingsGroup {
// TODO remove unfound settings from option
foreach ( $options as $setting_key => $setting_value ) {
- $setting = $this->settings[$setting_key];
- if ($setting) $setting->set_value( $setting_value );
- else trigger_error("Setting with key {$setting_key} not found, skipping...", E_USER_WARNING);
+ if ( array_key_exists( $setting_key, $this->settings ) )
+ $this->settings[$setting_key]->set_value( $setting_value );
}
}
diff --git a/src/includes/settings/custom-css/class-custom-css-settings-section.php b/src/includes/settings/custom-css/class-custom-css-settings-section.php
index 219abb6..6325798 100644
--- a/src/includes/settings/custom-css/class-custom-css-settings-section.php
+++ b/src/includes/settings/custom-css/class-custom-css-settings-section.php
@@ -12,9 +12,10 @@ namespace footnotes\includes\settings\customcss;
require_once plugin_dir_path( __DIR__ ) . 'class-settings-section.php';
+use footnotes\includes\Settings;
+
use footnotes\includes\settings\SettingsSection;
-// Import settings groups.
use footnotes\includes\settings\customcss\CustomCSSSettingsGroup;
/**
@@ -36,7 +37,15 @@ class CustomCSSSettingsSection extends SettingsSection {
public function __construct(
$options_group_slug,
$section_slug,
- $title
+ $title,
+
+ /**
+ * The plugin settings object.
+ *
+ * @access private
+ * @since 2.8.0
+ */
+ private Settings $settings
) {
$this->options_group_slug = $options_group_slug;
$this->section_slug = $section_slug;
@@ -57,7 +66,7 @@ class CustomCSSSettingsSection extends SettingsSection {
protected function add_settings_groups(): void {
$this->settings_groups = array (
- CustomCSSSettingsGroup::GROUP_ID => new CustomCSSSettingsGroup($this->options_group_slug, $this->section_slug),
+ CustomCSSSettingsGroup::GROUP_ID => new CustomCSSSettingsGroup($this->options_group_slug, $this->section_slug, $this->settings ),
);
}
}
diff --git a/src/includes/settings/general/class-general-settings-section.php b/src/includes/settings/general/class-general-settings-section.php
index 4c52fda..12775c5 100644
--- a/src/includes/settings/general/class-general-settings-section.php
+++ b/src/includes/settings/general/class-general-settings-section.php
@@ -12,7 +12,10 @@ namespace footnotes\includes\settings\general;
require_once plugin_dir_path( __DIR__ ) . 'class-settings-section.php';
+use footnotes\includes\Settings;
+
use footnotes\includes\settings\SettingsSection;
+
use footnotes\includes\settings\general\ReferenceContainerSettingsGroup;
use footnotes\includes\settings\general\ScrollingSettingsGroup;
use footnotes\includes\settings\general\ShortcodeSettingsGroup;
@@ -41,7 +44,15 @@ class GeneralSettingsSection extends SettingsSection {
public function __construct(
$options_group_slug,
$section_slug,
- $title
+ $title,
+
+ /**
+ * The plugin settings object.
+ *
+ * @access private
+ * @since 2.8.0
+ */
+ protected Settings $settings
) {
$this->options_group_slug = $options_group_slug;
$this->section_slug = $section_slug;
@@ -69,14 +80,14 @@ class GeneralSettingsSection extends SettingsSection {
protected function add_settings_groups(): void {
$this->settings_groups = array(
- AMPCompatSettingsGroup::GROUP_ID => new AMPCompatSettingsGroup( $this->options_group_slug, $this->section_slug ),
- ReferenceContainerSettingsGroup::GROUP_ID => new ReferenceContainerSettingsGroup( $this->options_group_slug, $this->section_slug ),
- ScrollingSettingsGroup::GROUP_ID => new ScrollingSettingsGroup( $this->options_group_slug, $this->section_slug ),
- ShortcodeSettingsGroup::GROUP_ID => new ShortcodeSettingsGroup( $this->options_group_slug, $this->section_slug ),
- NumberingSettingsGroup::GROUP_ID => new NumberingSettingsGroup( $this->options_group_slug, $this->section_slug ),
- HardLinksSettingsGroup::GROUP_ID => new HardLinksSettingsGroup( $this->options_group_slug, $this->section_slug ),
- ExcerptsSettingsGroup::GROUP_ID => new ExcerptsSettingsGroup( $this->options_group_slug, $this->section_slug ),
- LoveSettingsGroup::GROUP_ID => new LoveSettingsGroup( $this->options_group_slug, $this->section_slug ),
+ AMPCompatSettingsGroup::GROUP_ID => new AMPCompatSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ),
+ ReferenceContainerSettingsGroup::GROUP_ID => new ReferenceContainerSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ),
+ ScrollingSettingsGroup::GROUP_ID => new ScrollingSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ),
+ ShortcodeSettingsGroup::GROUP_ID => new ShortcodeSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ),
+ NumberingSettingsGroup::GROUP_ID => new NumberingSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ),
+ HardLinksSettingsGroup::GROUP_ID => new HardLinksSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ),
+ ExcerptsSettingsGroup::GROUP_ID => new ExcerptsSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ),
+ LoveSettingsGroup::GROUP_ID => new LoveSettingsGroup( $this->options_group_slug, $this->section_slug, $this->settings ),
);
}
}
diff --git a/src/includes/settings/general/class-scrolling-settings-group.php b/src/includes/settings/general/class-scrolling-settings-group.php
index 04dd4c3..87a0fa9 100644
--- a/src/includes/settings/general/class-scrolling-settings-group.php
+++ b/src/includes/settings/general/class-scrolling-settings-group.php
@@ -69,8 +69,8 @@ class ScrollingSettingsGroup extends SettingsGroup {
'default_value' => 0,
'type' => 'integer',
'input_type' => 'number',
- 'input_max' => 0,
- 'input_min' => 20000,
+ 'input_max' => 20000,
+ 'input_min' => 0,
);
/**
@@ -89,8 +89,8 @@ class ScrollingSettingsGroup extends SettingsGroup {
'default_value' => 0,
'type' => 'integer',
'input_type' => 'number',
- 'input_max' => 0,
- 'input_min' => 20000,
+ 'input_max' => 20000,
+ 'input_min' => 0,
);
/**
@@ -109,8 +109,8 @@ class ScrollingSettingsGroup extends SettingsGroup {
'default_value' => 20,
'type' => 'integer',
'input_type' => 'number',
- 'input_max' => 0,
- 'input_min' => 100,
+ 'input_max' => 100,
+ 'input_min' => 0,
);
/**
@@ -129,8 +129,8 @@ class ScrollingSettingsGroup extends SettingsGroup {
'default_value' => 380,
'type' => 'integer',
'input_type' => 'number',
- 'input_max' => 0,
- 'input_min' => 20000,
+ 'input_max' => 20000,
+ 'input_min' => 0,
);
/**
@@ -168,8 +168,8 @@ class ScrollingSettingsGroup extends SettingsGroup {
'default_value' => 150,
'type' => 'integer',
'input_type' => 'number',
- 'input_max' => 0,
- 'input_min' => 20000,
+ 'input_max' => 20000,
+ 'input_min' => 0,
'enabled_by' => self::FOOTNOTES_SCROLL_DURATION_ASYMMETRICITY,
);
diff --git a/src/includes/settings/referrers-and-tooltips/class-backlink-symbol-settings-group.php b/src/includes/settings/referrers-and-tooltips/class-backlink-symbol-settings-group.php
index e05a2c0..78393b2 100644
--- a/src/includes/settings/referrers-and-tooltips/class-backlink-symbol-settings-group.php
+++ b/src/includes/settings/referrers-and-tooltips/class-backlink-symbol-settings-group.php
@@ -40,27 +40,28 @@ class BacklinkSymbolSettingsGroup extends SettingsGroup {
* @since 1.5.0
* @since 2.8.0 Move from `Settings` to `ReferenceContainerSettingsGroup`.
* Convert from `string` to `array`.
+ * Convert setting data type from `string` to `int`.
*/
const HYPERLINK_ARROW = array(
'key' => 'footnote_inputfield_custom_hyperlink_symbol',
'name' => 'Select the Backlink Symbol',
'description' => 'This symbol is used in the reference container. But this setting pre-existed under this tab and cannot be moved to another one.',
'default_value' => 0,
- 'type' => 'string',
+ 'type' => 'number',
'input_type' => 'select',
- 'input_options' => array(
- '↑',
- '↥',
- '↟',
- '↩',
- '↲',
- '↵',
- '⇑',
- '⇡',
- '⇧',
- '↑'
- ),
- //'overridden_by' => self::HYPERLINK_ARROW_USER_DEFINED,
+ 'input_options' => array(
+ '↑',
+ '↥',
+ '↟',
+ '↩',
+ '↲',
+ '↵',
+ '⇑',
+ '⇡',
+ '⇧',
+ '↑'
+ ),
+ 'overridden_by' => self::HYPERLINK_ARROW_USER_DEFINED,
);
/**
@@ -78,7 +79,6 @@ class BacklinkSymbolSettingsGroup extends SettingsGroup {
'description' => 'Your input overrides the selection.',
'type' => 'string',
'input_type' => 'text',
- 'enabled_by' => self::HYPERLINK_ARROW
);
protected function add_settings( array|false $options ): void {
diff --git a/src/includes/settings/referrers-and-tooltips/class-referrers-and-tooltips-settings-section.php b/src/includes/settings/referrers-and-tooltips/class-referrers-and-tooltips-settings-section.php
index 508e792..398ef29 100644
--- a/src/includes/settings/referrers-and-tooltips/class-referrers-and-tooltips-settings-section.php
+++ b/src/includes/settings/referrers-and-tooltips/class-referrers-and-tooltips-settings-section.php
@@ -12,6 +12,8 @@ namespace footnotes\includes\settings\referrersandtooltips;
require_once plugin_dir_path( __DIR__ ) . 'class-settings-section.php';
+use footnotes\includes\Settings;
+
use footnotes\includes\settings\SettingsSection;
/**
@@ -33,7 +35,15 @@ class ReferrersAndTooltipsSettingsSection extends SettingsSection {
public function __construct(
$options_group_slug,
$section_slug,
- $title
+ $title,
+
+ /**
+ * The plugin settings object.
+ *
+ * @access private
+ * @since 2.8.0
+ */
+ private Settings $settings
) {
$this->options_group_slug = $options_group_slug;
$this->section_slug = $section_slug;
@@ -63,16 +73,16 @@ class ReferrersAndTooltipsSettingsSection extends SettingsSection {
protected function add_settings_groups(): void {
$this->settings_groups = array (
- BacklinkSymbolSettingsGroup::GROUP_ID => new BacklinkSymbolSettingsGroup( $this->options_group_slug, $this->section_slug ),
- ReferrersSettingsGroup::GROUP_ID => new ReferrersSettingsGroup( $this->options_group_slug, $this->section_slug ),
- ReferrersInLabelsSettingsGroup::GROUP_ID => new ReferrersInLabelsSettingsGroup( $this->options_group_slug, $this->section_slug ),
- TooltipsSettingsGroup::GROUP_ID => new TooltipsSettingsGroup( $this->options_group_slug, $this->section_slug ),
- TooltipAppearanceSettingsGroup::GROUP_ID => new TooltipAppearanceSettingsGroup( $this->options_group_slug, $this->section_slug ),
- TooltipDimensionsSettingsGroup::GROUP_ID => new TooltipDimensionsSettingsGroup( $this->options_group_slug, $this->section_slug ),
- TooltipPositionSettingsGroup::GROUP_ID => new TooltipPositionSettingsGroup( $this->options_group_slug, $this->section_slug ),
- TooltipTextSettingsGroup::GROUP_ID => new TooltipTextSettingsGroup( $this->options_group_slug, $this->section_slug ),
- TooltipTimingSettingsGroup::GROUP_ID => new TooltipTimingSettingsGroup( $this->options_group_slug, $this->section_slug ),
- TooltipTruncationSettingsGroup::GROUP_ID => new TooltipTruncationSettingsGroup( $this->options_group_slug, $this->section_slug ),
+ 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 ),
+ 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 ),
+ 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 ),
+ 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 ),
+ 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 ),
);
}
}
diff --git a/src/includes/settings/referrers-and-tooltips/class-tooltip-appearance-settings-group.php b/src/includes/settings/referrers-and-tooltips/class-tooltip-appearance-settings-group.php
index 1063ef9..67ddbf8 100644
--- a/src/includes/settings/referrers-and-tooltips/class-tooltip-appearance-settings-group.php
+++ b/src/includes/settings/referrers-and-tooltips/class-tooltip-appearance-settings-group.php
@@ -68,11 +68,11 @@ class TooltipAppearanceSettingsGroup extends SettingsGroup {
'key' => 'footnotes_inputfield_mouse_over_box_font_size_scalar',
'name' => 'Font Size',
'description' => 'By default, the font size is set to equal the surrounding text.',
- 'default_value' => 13,
+ 'default_value' => 13.0,
'type' => 'number',
'input_type' => 'number',
- 'input_max' => 50,
- 'input_min' => 0
+ 'input_max' => 50.0,
+ 'input_min' => 0.0
);
/**
@@ -147,11 +147,11 @@ class TooltipAppearanceSettingsGroup extends SettingsGroup {
'key' => 'footnote_inputfield_custom_mouse_over_box_border_width',
'name' => 'Border Width',
'description' => 'pixels; 0 for borderless',
- 'default_value' => 1,
+ 'default_value' => 1.0,
'type' => 'number',
'input_type' => 'number',
- 'input_max' => 4,
- 'input_min' => 0,
+ 'input_max' => 4.0,
+ 'input_min' => 0.0,
);
/**
diff --git a/src/includes/settings/scope-and-priority/class-scope-and-priority-settings-section.php b/src/includes/settings/scope-and-priority/class-scope-and-priority-settings-section.php
index 896f384..788dd03 100644
--- a/src/includes/settings/scope-and-priority/class-scope-and-priority-settings-section.php
+++ b/src/includes/settings/scope-and-priority/class-scope-and-priority-settings-section.php
@@ -12,6 +12,8 @@ namespace footnotes\includes\settings\scopeandpriority;
require_once plugin_dir_path( __DIR__ ) . 'class-settings-section.php';
+use footnotes\includes\Settings;
+
use footnotes\includes\settings\SettingsSection;
use footnotes\includes\settings\scopeandpriority\WordPressHooksSettingsGroup;
@@ -35,7 +37,15 @@ class ScopeAndPrioritySettingsSection extends SettingsSection {
public function __construct(
$options_group_slug,
$section_slug,
- $title
+ $title,
+
+ /**
+ * The plugin settings object.
+ *
+ * @access private
+ * @since 2.8.0
+ */
+ private Settings $settings
) {
$this->options_group_slug = $options_group_slug;
$this->section_slug = $section_slug;
@@ -56,7 +66,7 @@ class ScopeAndPrioritySettingsSection extends SettingsSection {
protected function add_settings_groups(): void {
$this->settings_groups = array (
- WordPressHooksSettingsGroup::GROUP_ID => new WordPressHooksSettingsGroup($this->options_group_slug, $this->section_slug),
+ WordPressHooksSettingsGroup::GROUP_ID => new WordPressHooksSettingsGroup($this->options_group_slug, $this->section_slug, $this->settings ),
);
}
}
diff --git a/src/public/class-general.php b/src/public/class-general.php
index a3421da..186188a 100644
--- a/src/public/class-general.php
+++ b/src/public/class-general.php
@@ -33,26 +33,6 @@ use footnotes\includes\settings\referrersandtooltips\TooltipsSettingsGroup;
*/
class General {
- /**
- * The ID of this plugin.
- *
- * @since 2.8.0
-
- * @access private
- * @var string $plugin_name The ID of this plugin.
- */
- private string $plugin_name;
-
- /**
- * The version of this plugin.
- *
- * @since 2.8.0
-
- * @access private
- * @var string $version The current version of this plugin.
- */
- private string $version;
-
/**
* The reference container widget.
*
@@ -120,18 +100,41 @@ class General {
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
- public function __construct( string $plugin_name, string $version ) {
+ public function __construct(
+ /**
+ * The ID of this plugin.
+ *
+ * @access private
+ * @since 2.8.0
+ * @see Footnotes::$plugin_name
+ */
+ private string $plugin_name,
- $this->plugin_name = $plugin_name;
- $this->version = $version;
+ /**
+ * The version of this plugin.
+ *
+ * @access private
+ * @since 2.8.0
+ * @see Footnotes::$version
+ */
+ private string $version,
+
+ /**
+ * The plugin settings object.
+ *
+ * @access private
+ * @since 2.8.0
+ */
+ private Settings $settings
+ ) {
$this->load_dependencies();
// Set conditions re-used for stylesheet enqueuing and in class/task.php.
- self::$amp_enabled = Settings::instance()->get_setting( AMPCompatSettingsGroup::FOOTNOTES_AMP_COMPATIBILITY_ENABLE['key'] )->get_value();
- self::$tooltips_enabled = Settings::instance()->get_setting( TooltipsSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_ENABLED['key'] )->get_value();
- self::$alternative_tooltips_enabled = Settings::instance()->get_setting( TooltipsSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_ALTERNATIVE['key'] )->get_value();
- self::$script_mode = Settings::instance()->get_setting( ReferenceContainerSettingsGroup::FOOTNOTES_REFERENCE_CONTAINER_SCRIPT_MODE['key'] );
+ self::$amp_enabled = $this->settings->get_setting_value( AMPCompatSettingsGroup::FOOTNOTES_AMP_COMPATIBILITY_ENABLE['key'] );
+ self::$tooltips_enabled = $this->settings->get_setting_value( TooltipsSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_ENABLED['key'] );
+ self::$alternative_tooltips_enabled = $this->settings->get_setting_value( TooltipsSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_ALTERNATIVE['key'] );
+ self::$script_mode = $this->settings->get_setting_value( ReferenceContainerSettingsGroup::FOOTNOTES_REFERENCE_CONTAINER_SCRIPT_MODE['key'] );
}
/**
@@ -156,7 +159,7 @@ class General {
$this->reference_container_widget = new Widget\Reference_Container( $this->plugin_name );
- $this->task = new Parser();
+ $this->task = new Parser($this->settings);
}
/**
@@ -193,7 +196,7 @@ class General {
}
// Set basic responsive page layout mode for use in stylesheet name.
- $page_layout_option = Settings::instance()->get( FOOTNOTES_PAGE_LAYOUT_SUPPORT );
+ $page_layout_option = $this->settings->get( FOOTNOTES_PAGE_LAYOUT_SUPPORT );
switch ( $page_layout_option ) {
case 'reference-container':
$layout_mode = '1';
diff --git a/src/public/class-parser.php b/src/public/class-parser.php
index e30d2d3..eb58957 100644
--- a/src/public/class-parser.php
+++ b/src/public/class-parser.php
@@ -49,8 +49,7 @@ use footnotes\includes\settings\customcss\CustomCSSSettingsGroup;
* @since 1.5.0
* @since 2.8.0 Rename class from `Footnotes_Task` to `Parser`.
*/
-class Parser {
-
+class Parser {
/**
* Contains all footnotes found in the searched content.
*
@@ -277,7 +276,15 @@ class Parser {
* @todo Reorganise dependencies.
* @todo Move call to `register_hooks()` to {@see General}.
*/
- public function __construct() {
+ public function __construct(
+ /**
+ * The plugin settings object.
+ *
+ * @access private
+ * @since 2.8.0
+ */
+ private Settings $settings
+ ) {
// TODO: Reorg dependencies.
require_once plugin_dir_path( __DIR__ ) . 'includes/class-config.php';
require_once plugin_dir_path( __DIR__ ) . 'includes/class-convert.php';
@@ -299,11 +306,11 @@ class Parser {
*/
public function register_hooks(): void {
// Get values from settings.
- $the_title_priority = Settings::instance()->get_setting( WordPressHooksSettingsGroup::EXPERT_LOOKUP_THE_TITLE_PRIORITY_LEVEL['key'] )->get_value();
- $the_content_priority = Settings::instance()->get_setting( WordPressHooksSettingsGroup::EXPERT_LOOKUP_THE_CONTENT_PRIORITY_LEVEL['key'] )->get_value();
- $the_excerpt_priority = Settings::instance()->get_setting( WordPressHooksSettingsGroup::EXPERT_LOOKUP_THE_EXCERPT_PRIORITY_LEVEL['key'] )->get_value();
- $widget_title_priority = Settings::instance()->get_setting( WordPressHooksSettingsGroup::EXPERT_LOOKUP_WIDGET_TITLE_PRIORITY_LEVEL['key'] )->get_value();
- $widget_text_priority = Settings::instance()->get_setting( WordPressHooksSettingsGroup::EXPERT_LOOKUP_WIDGET_TEXT_PRIORITY_LEVEL['key'] )->get_value();
+ $the_title_priority = $this->settings->get_setting_value( WordPressHooksSettingsGroup::EXPERT_LOOKUP_THE_TITLE_PRIORITY_LEVEL['key'] );
+ $the_content_priority = $this->settings->get_setting_value( WordPressHooksSettingsGroup::EXPERT_LOOKUP_THE_CONTENT_PRIORITY_LEVEL['key'] );
+ $the_excerpt_priority = $this->settings->get_setting_value( WordPressHooksSettingsGroup::EXPERT_LOOKUP_THE_EXCERPT_PRIORITY_LEVEL['key'] );
+ $widget_title_priority = $this->settings->get_setting_value( WordPressHooksSettingsGroup::EXPERT_LOOKUP_WIDGET_TITLE_PRIORITY_LEVEL['key'] );
+ $widget_text_priority = $this->settings->get_setting_value( WordPressHooksSettingsGroup::EXPERT_LOOKUP_WIDGET_TEXT_PRIORITY_LEVEL['key'] );
// PHP_INT_MAX can be set by -1.
$the_title_priority = ( -1 === $the_title_priority ) ? PHP_INT_MAX : $the_title_priority;
@@ -326,7 +333,7 @@ class Parser {
PHP_INT_MAX
);
- if ( Settings::instance()->get_setting( WordPressHooksSettingsGroup::EXPERT_LOOKUP_THE_TITLE['key'] )->get_value() ) {
+ if ( $this->settings->get_setting_value( WordPressHooksSettingsGroup::EXPERT_LOOKUP_THE_TITLE['key'] ) ) {
add_filter(
'the_title',
fn( string $content): string => $this->footnotes_in_title( $content ),
@@ -335,7 +342,7 @@ class Parser {
}
// Configurable priority level for reference container relative positioning; default 98.
- if ( Settings::instance()->get_setting( WordPressHooksSettingsGroup::EXPERT_LOOKUP_THE_CONTENT['key'] )->get_value() ) {
+ if ( $this->settings->get_setting_value( WordPressHooksSettingsGroup::EXPERT_LOOKUP_THE_CONTENT['key'] ) ) {
add_filter(
'the_content',
fn( string $content): string => $this->footnotes_in_content( $content ),
@@ -377,7 +384,7 @@ class Parser {
);
}
- if ( Settings::instance()->get_setting( WordPressHooksSettingsGroup::EXPERT_LOOKUP_THE_EXCERPT['key'] )->get_value() ) {
+ if ( $this->settings->get_setting_value( WordPressHooksSettingsGroup::EXPERT_LOOKUP_THE_EXCERPT['key'] ) ) {
/**
* Adds a filter to the excerpt hook.
*
@@ -393,7 +400,7 @@ class Parser {
);
}
- if ( Settings::instance()->get_setting( WordPressHooksSettingsGroup::EXPERT_LOOKUP_WIDGET_TITLE['key'] )->get_value() ) {
+ if ( $this->settings->get_setting_value( WordPressHooksSettingsGroup::EXPERT_LOOKUP_WIDGET_TITLE['key'] ) ) {
/**
* TODO
*/
@@ -404,7 +411,7 @@ class Parser {
);
}
- if ( Settings::instance()->get_setting( WordPressHooksSettingsGroup::EXPERT_LOOKUP_WIDGET_TEXT['key'] )->get_value() ) {
+ if ( $this->settings->get_setting_value( WordPressHooksSettingsGroup::EXPERT_LOOKUP_WIDGET_TEXT['key'] ) ) {
/**
* TODO
*/
@@ -436,7 +443,7 @@ class Parser {
*
* Native smooth scrolling only works in recent browsers.
*/
- if ( Settings::instance()->get_setting( ScrollingSettingsGroup::FOOTNOTES_CSS_SMOOTH_SCROLLING['key'] )->get_value() ) {
+ if ( $this->settings->get_setting_value( ScrollingSettingsGroup::FOOTNOTES_CSS_SMOOTH_SCROLLING['key'] ) ) {
echo "html {scroll-behavior: smooth;}\r\n";
}
@@ -446,7 +453,7 @@ class Parser {
* Cannot be included in external stylesheet, as it is only optional.
* The scope is variable too: referrers only, or all superscript elements.
*/
- $normalize_superscript = Settings::instance()->get_setting( ReferrersSettingsGroup::FOOTNOTE_REFERRERS_NORMAL_SUPERSCRIPT['key'] )->get_value();
+ $normalize_superscript = $this->settings->get_setting_value( ReferrersSettingsGroup::FOOTNOTE_REFERRERS_NORMAL_SUPERSCRIPT['key'] );
if ( 'no' !== $normalize_superscript ) {
if ( 'all' === $normalize_superscript ) {
echo 'sup {';
@@ -457,14 +464,14 @@ class Parser {
}
// Reference container display on home page.
- if ( ! ( Settings::instance()->get_setting( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_START_PAGE_ENABLE['key'] )->get_value() ) ) {
+ if ( ! ( $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_START_PAGE_ENABLE['key'] ) ) ) {
echo ".home .footnotes_reference_container { display: none; }\r\n";
}
// Reference container top and bottom margins.
- $reference_container_top_margin = (int) Settings::instance()->get_setting( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_TOP_MARGIN['key'] )->get_value();
- $reference_container_bottom_margin = (int) Settings::instance()->get_setting( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_BOTTOM_MARGIN['key'] )->get_value();
+ $reference_container_top_margin = (int) $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_TOP_MARGIN['key'] );
+ $reference_container_bottom_margin = (int) $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_BOTTOM_MARGIN['key'] );
echo '.footnotes_reference_container {margin-top: ';
echo empty( $reference_container_top_margin ) ? '0' : $reference_container_top_margin;
echo 'px !important; margin-bottom: ';
@@ -472,9 +479,9 @@ class Parser {
echo "px !important;}\r\n";
// Reference container label bottom border.
- if ( ( Settings::instance()->get_setting( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_LABEL_BOTTOM_BORDER['key'] )->get_value() ) ) {
+ if ( ( $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_LABEL_BOTTOM_BORDER['key'] ) ) ) {
echo '.footnote_container_prepare > ';
- echo Settings::instance()->get_setting( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_LABEL_ELEMENT['key'] )->get_value() ;
+ echo $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_LABEL_ELEMENT['key'] ) ;
echo " {border-bottom: 1px solid #aaaaaa !important;}\r\n";
}
@@ -487,7 +494,7 @@ class Parser {
* issues as browsers won’t reload these style sheets after settings are
* changed while the version string is not.
*/
- if ( ( Settings::instance()->get_setting( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_ROW_BORDERS_ENABLE['key'] )->get_value() ) ) {
+ if ( ( $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_ROW_BORDERS_ENABLE['key'] ) ) ) {
echo '.footnotes_table, .footnotes_plugin_reference_row {';
echo 'border: 1px solid #060606;';
echo " !important;}\r\n";
@@ -497,16 +504,16 @@ class Parser {
}
// Ref container first column width and max-width.
- $column_width_enabled = ( Settings::instance()->get_setting( ReferenceContainerSettingsGroup::BACKLINKS_COLUMN_WIDTH_ENABLED['key'] )->get_value() );
- $column_max_width_enabled = ( Settings::instance()->get_setting( ReferenceContainerSettingsGroup::BACKLINKS_COLUMN_MAX_WIDTH_ENABLED['key'] )->get_value() );
+ $column_width_enabled = ( $this->settings->get_setting_value( ReferenceContainerSettingsGroup::BACKLINKS_COLUMN_WIDTH_ENABLED['key'] ) );
+ $column_max_width_enabled = ( $this->settings->get_setting_value( ReferenceContainerSettingsGroup::BACKLINKS_COLUMN_MAX_WIDTH_ENABLED['key'] ) );
if ( $column_width_enabled || $column_max_width_enabled ) {
echo '.footnote-reference-container { table-layout: fixed; }';
echo '.footnote_plugin_index, .footnote_plugin_index_combi {';
if ( $column_width_enabled ) {
- $column_width_scalar = Settings::instance()->get_setting( ReferenceContainerSettingsGroup::BACKLINKS_COLUMN_WIDTH_SCALAR['key'] )->get_value();
- $column_width_unit = Settings::instance()->get_setting( ReferenceContainerSettingsGroup::BACKLINKS_COLUMN_WIDTH_UNIT['key'] )->get_value();
+ $column_width_scalar = $this->settings->get_setting_value( ReferenceContainerSettingsGroup::BACKLINKS_COLUMN_WIDTH_SCALAR['key'] );
+ $column_width_unit = $this->settings->get_setting_value( ReferenceContainerSettingsGroup::BACKLINKS_COLUMN_WIDTH_UNIT['key'] );
if ( ! empty( $column_width_scalar ) ) {
if ( '%' === $column_width_unit && $column_width_scalar > 100 ) {
@@ -520,8 +527,8 @@ class Parser {
}
if ( $column_max_width_enabled ) {
- $column_max_width_scalar = Settings::instance()->get_setting( ReferenceContainerSettingsGroup::BACKLINKS_COLUMN_MAX_WIDTH_SCALAR['key'] )->get_value();
- $column_max_width_unit = Settings::instance()->get_setting( ReferenceContainerSettingsGroup::BACKLINKS_COLUMN_MAX_WIDTH_UNIT['key'] )->get_value();
+ $column_max_width_scalar = $this->settings->get_setting_value( ReferenceContainerSettingsGroup::BACKLINKS_COLUMN_MAX_WIDTH_SCALAR['key'] );
+ $column_max_width_unit = $this->settings->get_setting_value( ReferenceContainerSettingsGroup::BACKLINKS_COLUMN_MAX_WIDTH_UNIT['key'] );
if ( ! empty( $column_max_width_scalar ) ) {
if ( '%' === $column_max_width_unit && $column_max_width_scalar > 100 ) {
@@ -538,14 +545,15 @@ class Parser {
}
// Hard links scroll offset.
- self::$hard_links_enabled = Settings::instance()->get_setting( HardLinksSettingsGroup::FOOTNOTES_HARD_LINKS_ENABLE['key'] )->get_value();
+ // TODO: remove cast
+ 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.
if ( General::$amp_enabled || 'jquery' !== General::$script_mode ) {
self::$hard_links_enabled = true;
}
- self::$scroll_offset = (int)Settings::instance()->get_setting( ScrollingSettingsGroup::FOOTNOTES_SCROLL_OFFSET['key'] )->get_value();
+ self::$scroll_offset = (int) $this->settings->get_setting_value( ScrollingSettingsGroup::FOOTNOTES_SCROLL_OFFSET['key'] );
if ( self::$hard_links_enabled ) {
echo '.footnote_referrer_anchor, .footnote_item_anchor {bottom: ';
echo self::$scroll_offset;
@@ -558,46 +566,46 @@ class Parser {
// Tooltip appearance: Tooltip font size.
echo ' font-size: ';
- if ( Settings::instance()->get_setting( TooltipAppearanceSettingsGroup::MOUSE_OVER_BOX_FONT_SIZE_ENABLED['key'] )->get_value() ) {
- echo Settings::instance()->get_setting( TooltipAppearanceSettingsGroup::MOUSE_OVER_BOX_FONT_SIZE_SCALAR['key'] )->get_value();
- echo Settings::instance()->get_setting( TooltipAppearanceSettingsGroup::MOUSE_OVER_BOX_FONT_SIZE_UNIT['key'] )->get_value();
+ if ( $this->settings->get_setting_value( TooltipAppearanceSettingsGroup::MOUSE_OVER_BOX_FONT_SIZE_ENABLED['key'] ) ) {
+ echo $this->settings->get_setting_value( TooltipAppearanceSettingsGroup::MOUSE_OVER_BOX_FONT_SIZE_SCALAR['key'] );
+ echo $this->settings->get_setting_value( TooltipAppearanceSettingsGroup::MOUSE_OVER_BOX_FONT_SIZE_UNIT['key'] );
} else {
echo 'inherit';
}
echo ' !important;';
// Tooltip Text color.
- $color = Settings::instance()->get_setting( TooltipAppearanceSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_COLOR['key'] )->get_value();
+ $color = $this->settings->get_setting_value( TooltipAppearanceSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_COLOR['key'] );
if ( ! empty( $color ) ) {
printf( ' color: %s !important;', $color );
}
// Tooltip Background color.
- $background = Settings::instance()->get_setting( TooltipAppearanceSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_BACKGROUND['key'] )->get_value();
+ $background = $this->settings->get_setting_value( TooltipAppearanceSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_BACKGROUND['key'] );
if ( ! empty( $background ) ) {
printf( ' background-color: %s !important;', $background );
}
// Tooltip Border width.
- $border_width = Settings::instance()->get_setting( TooltipAppearanceSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_BORDER_WIDTH['key'] )->get_value();
+ $border_width = $this->settings->get_setting_value( TooltipAppearanceSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_BORDER_WIDTH['key'] );
if ( ! empty( $border_width ) && (int) $border_width > 0 ) {
printf( ' border-width: %dpx !important; border-style: solid !important;', $border_width );
}
// Tooltip Border color.
- $border_color = Settings::instance()->get_setting( TooltipAppearanceSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_BORDER_COLOR['key'] )->get_value();
+ $border_color = $this->settings->get_setting_value( TooltipAppearanceSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_BORDER_COLOR['key'] );
if ( ! empty( $border_color ) ) {
printf( ' border-color: %s !important;', $border_color );
}
// Tooltip Corner radius.
- $border_radius = Settings::instance()->get_setting( TooltipAppearanceSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_BORDER_RADIUS['key'] )->get_value();
+ $border_radius = $this->settings->get_setting_value( TooltipAppearanceSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_BORDER_RADIUS['key'] );
if ( ! empty( $border_radius ) && (int) $border_radius > 0 ) {
printf( ' border-radius: %dpx !important;', $border_radius );
}
// Tooltip Shadow color.
- $box_shadow_color = Settings::instance()->get_setting( TooltipAppearanceSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_SHADOW_COLOR['key'] )->get_value();
+ $box_shadow_color = $this->settings->get_setting_value( TooltipAppearanceSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_SHADOW_COLOR['key'] );
if ( ! empty( $box_shadow_color ) ) {
printf( ' -webkit-box-shadow: 2px 2px 11px %s;', $box_shadow_color );
printf( ' -moz-box-shadow: 2px 2px 11px %s;', $box_shadow_color );
@@ -611,7 +619,7 @@ class Parser {
*
* Position and timing of jQuery tooltips are script-defined.
*/
- $max_width = Settings::instance()->get_setting( TooltipDimensionsSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_MAX_WIDTH['key'] )->get_value();
+ $max_width = $this->settings->get_setting_value( TooltipDimensionsSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_MAX_WIDTH['key'] );
if ( ! empty( $max_width ) && (int) $max_width > 0 ) {
printf( ' max-width: %dpx !important;', $max_width );
}
@@ -622,7 +630,7 @@ class Parser {
echo "}\r\n";
// Dimensions.
- $alternative_tooltip_width = (int) Settings::instance()->get_setting( TooltipDimensionsSettingsGroup::FOOTNOTES_ALTERNATIVE_MOUSE_OVER_BOX_WIDTH['key'] )->get_value();
+ $alternative_tooltip_width = (int) $this->settings->get_setting_value( TooltipDimensionsSettingsGroup::FOOTNOTES_ALTERNATIVE_MOUSE_OVER_BOX_WIDTH['key'] );
echo '.footnote_tooltip.position {';
echo ' width: max-content; ';
@@ -630,8 +638,8 @@ class Parser {
echo ' max-width: ' . $alternative_tooltip_width . 'px;';
// Position.
- $alternative_position = Settings::instance()->get_setting( TooltipPositionSettingsGroup::FOOTNOTES_ALTERNATIVE_MOUSE_OVER_BOX_POSITION['key'] )->get_value();
- $offset_x = (int) Settings::instance()->get_setting( TooltipPositionSettingsGroup::FOOTNOTES_ALTERNATIVE_MOUSE_OVER_BOX_OFFSET_X['key'] )->get_value();
+ $alternative_position = $this->settings->get_setting_value( TooltipPositionSettingsGroup::FOOTNOTES_ALTERNATIVE_MOUSE_OVER_BOX_POSITION['key'] );
+ $offset_x = (int) $this->settings->get_setting_value( TooltipPositionSettingsGroup::FOOTNOTES_ALTERNATIVE_MOUSE_OVER_BOX_OFFSET_X['key'] );
if ( 'top left' === $alternative_position || 'bottom left' === $alternative_position ) {
echo ' right: ' . ( empty( $offset_x ) ? 0 : $offset_x ) . 'px;';
@@ -639,7 +647,7 @@ class Parser {
echo ' left: ' . ( empty( $offset_x ) ? 0 : $offset_x ) . 'px;';
}
- $offset_y = (int) Settings::instance()->get_setting( TooltipPositionSettingsGroup::FOOTNOTES_ALTERNATIVE_MOUSE_OVER_BOX_OFFSET_Y['key'] )->get_value();
+ $offset_y = (int) $this->settings->get_setting_value( TooltipPositionSettingsGroup::FOOTNOTES_ALTERNATIVE_MOUSE_OVER_BOX_OFFSET_Y['key'] );
if ( 'top left' === $alternative_position || 'top right' === $alternative_position ) {
echo ' bottom: ' . ( empty( $offset_y ) ? 0 : $offset_y ) . 'px;';
@@ -649,13 +657,13 @@ class Parser {
echo "}\r\n";
// Timing.
- $fade_in_delay = Settings::instance()->get_setting( TooltipTimingSettingsGroup::MOUSE_OVER_BOX_FADE_IN_DELAY['key'] )->get_value();
+ $fade_in_delay = $this->settings->get_setting_value( TooltipTimingSettingsGroup::MOUSE_OVER_BOX_FADE_IN_DELAY['key'] );
$fade_in_delay = empty( $fade_in_delay ) ? '0' : $fade_in_delay;
- $fade_in_duration = Settings::instance()->get_setting( TooltipTimingSettingsGroup::MOUSE_OVER_BOX_FADE_IN_DURATION['key'] )->get_value();
+ $fade_in_duration = $this->settings->get_setting_value( TooltipTimingSettingsGroup::MOUSE_OVER_BOX_FADE_IN_DURATION['key'] );
$fade_in_duration = empty( $fade_in_duration ) ? '0' : $fade_in_duration;
- $fade_out_delay = Settings::instance()->get_setting( TooltipTimingSettingsGroup::MOUSE_OVER_BOX_FADE_OUT_DELAY['key'] )->get_value();
+ $fade_out_delay = $this->settings->get_setting_value( TooltipTimingSettingsGroup::MOUSE_OVER_BOX_FADE_OUT_DELAY['key'] );
$fade_out_delay = empty( $fade_out_delay ) ? '0' : $fade_out_delay;
- $fade_out_duration = Settings::instance()->get_setting( TooltipTimingSettingsGroup::MOUSE_OVER_BOX_FADE_OUT_DURATION['key'] )->get_value();
+ $fade_out_duration = $this->settings->get_setting_value( TooltipTimingSettingsGroup::MOUSE_OVER_BOX_FADE_OUT_DURATION['key'] );
$fade_out_duration = empty( $fade_out_duration ) ? '0' : $fade_out_duration;
/*
@@ -701,7 +709,7 @@ class Parser {
* Set custom CSS to override settings, not conversely.
* Legacy Custom CSS is used until it’s set to disappear after dashboard tab migration.
*/
- echo Settings::instance()->get_setting( CustomCSSSettingsGroup::CUSTOM_CSS['key'] )->get_value();
+ echo $this->settings->get_setting_value( CustomCSSSettingsGroup::CUSTOM_CSS['key'] );
// Insert end tag without switching out of PHP.
echo "\r\n\r\n";
@@ -734,11 +742,11 @@ class Parser {
* @since 1.5.0
*/
public function footnotes_output_footer(): void {
- if ( 'footer' === Settings::instance()->get_setting( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_POSITION['key'] )->get_value() ) {
+ if ( 'footer' === $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_POSITION['key'] ) ) {
echo $this->reference_container();
}
// Get setting for love and share this plugin.
- $love_me_index = Settings::instance()->get_setting( LoveSettingsGroup::FOOTNOTES_LOVE['key'] )->get_value();
+ $love_me_index = $this->settings->get_setting_value( LoveSettingsGroup::FOOTNOTES_LOVE['key'] );
// Check if the admin allows to add a link to the footer.
if ( empty( $love_me_index ) || 'no' === strtolower( $love_me_index ) || ! self::$allow_love_me ) {
return;
@@ -807,8 +815,8 @@ class Parser {
*/
public function footnotes_in_content( string $content ): string {
- $ref_container_position = Settings::instance()->get_setting( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_POSITION['key'] )->get_value();
- $footnote_section_shortcode = Settings::instance()->get_setting( ReferenceContainerSettingsGroup::FOOTNOTE_SECTION_SHORTCODE['key'] )->get_value();
+ $ref_container_position = $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_POSITION['key'] );
+ $footnote_section_shortcode = $this->settings->get_setting_value( ReferenceContainerSettingsGroup::FOOTNOTE_SECTION_SHORTCODE['key'] );
$footnote_section_shortcode_length = strlen( $footnote_section_shortcode );
// TODO: Replace with `str_contains()`, but currently breaks Rector downgrade.
@@ -856,7 +864,7 @@ class Parser {
* @return string $excerpt Processed or new excerpt.
*/
public function footnotes_in_excerpt( string $excerpt ): string {
- $excerpt_mode = Settings::instance()->get_setting( ExcerptsSettingsGroup::FOOTNOTES_IN_EXCERPT['key'] )->get_value();
+ $excerpt_mode = $this->settings->get_setting_value( ExcerptsSettingsGroup::FOOTNOTES_IN_EXCERPT['key'] );
if ( 'yes' === $excerpt_mode ) {
return $this->generate_excerpt_with_footnotes( $excerpt );
@@ -1044,7 +1052,7 @@ class Parser {
public function footnotes_in_widget_text( string $content ): string {
// phpcs:disable WordPress.PHP.YodaConditions.NotYoda
// Appends the reference container if set to "post_end".
- return $this->exec( $content, 'post_end' === Settings::instance()->get_setting( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_POSITION['key'] )->get_value() );
+ return $this->exec( $content, 'post_end' === $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_POSITION['key'] ) );
// phpcs:enable WordPress.PHP.YodaConditions.NotYoda
}
@@ -1066,7 +1074,7 @@ class Parser {
*/
// Append the reference container or insert at shortcode.
- $reference_container_position_shortcode = Settings::instance()->get_setting( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_POSITION_SHORTCODE['key'] )->get_value();
+ $reference_container_position_shortcode = $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_POSITION_SHORTCODE['key'] );
if ( empty( $reference_container_position_shortcode ) ) {
$reference_container_position_shortcode = '[[references]]';
}
@@ -1114,11 +1122,11 @@ class Parser {
public function unify_delimiters( string $content ): string {
// Get footnotes start and end tag short codes.
- $starting_tag = Settings::instance()->get_setting( ShortcodeSettingsGroup::FOOTNOTES_SHORT_CODE_START['key'] )->get_value();
- $ending_tag = Settings::instance()->get_setting( ShortcodeSettingsGroup::FOOTNOTES_SHORT_CODE_END['key'] )->get_value();
+ $starting_tag = $this->settings->get_setting_value( ShortcodeSettingsGroup::FOOTNOTES_SHORT_CODE_START['key'] );
+ $ending_tag = $this->settings->get_setting_value( ShortcodeSettingsGroup::FOOTNOTES_SHORT_CODE_END['key'] );
if ( 'userdefined' === $starting_tag || 'userdefined' === $ending_tag ) {
- $starting_tag = Settings::instance()->get_setting( ShortcodeSettingsGroup::FOOTNOTES_SHORT_CODE_START_USER_DEFINED['key'] )->get_value();
- $ending_tag = Settings::instance()->get_setting( ShortcodeSettingsGroup::FOOTNOTES_SHORT_CODE_END_USER_DEFINED['key'] )->get_value();
+ $starting_tag = $this->settings->get_setting_value( ShortcodeSettingsGroup::FOOTNOTES_SHORT_CODE_START_USER_DEFINED['key'] );
+ $ending_tag = $this->settings->get_setting_value( ShortcodeSettingsGroup::FOOTNOTES_SHORT_CODE_END_USER_DEFINED['key'] );
}
// If any footnotes short code is empty, return the content without changes.
@@ -1191,7 +1199,7 @@ class Parser {
*/
// If enabled.
- if ( Settings::instance()->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.
if ( '((' === self::$start_tag || '(((' === self::$start_tag ) {
@@ -1260,7 +1268,7 @@ class Parser {
} while ( preg_match( $value_regex, $content ) );
// Optionally moves footnotes outside at the end of the label element.
- $label_issue_solution = Settings::instance()->get_setting( ReferrersInLabelsSettingsGroup::FOOTNOTES_LABEL_ISSUE_SOLUTION['key'] )->get_value();
+ $label_issue_solution = $this->settings->get_setting_value( ReferrersInLabelsSettingsGroup::FOOTNOTES_LABEL_ISSUE_SOLUTION['key'] );
if ( 'move' === $label_issue_solution ) {
@@ -1331,7 +1339,7 @@ class Parser {
if ( General::$amp_enabled ) {
// Whether first clicking a referrer needs to expand the reference container.
- if ( ( Settings::instance()->get_setting( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_COLLAPSE['key'] )->get_value() ) ) {
+ if ( ( $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_COLLAPSE['key'] ) ) ) {
// Load 'public/partials/amp-footnote-expand.html'.
$template = new Template( Template::PUBLIC, 'amp-footnote-expand' );
@@ -1382,7 +1390,7 @@ class Parser {
$footnote_text = substr( $content, $pos_start + strlen( self::$start_tag ), $length - strlen( self::$start_tag ) );
// Get tooltip text if present.
- self::$tooltip_shortcode = Settings::instance()->get_setting( TooltipTextSettingsGroup::FOOTNOTES_TOOLTIP_EXCERPT_DELIMITER['key'] )->get_value();
+ self::$tooltip_shortcode = $this->settings->get_setting_value( TooltipTextSettingsGroup::FOOTNOTES_TOOLTIP_EXCERPT_DELIMITER['key'] );
self::$tooltip_shortcode_length = strlen( self::$tooltip_shortcode );
$tooltip_text_length = strpos( $footnote_text, (string) self::$tooltip_shortcode );
$has_tooltip_text = (bool) $tooltip_text_length;
@@ -1406,7 +1414,7 @@ class Parser {
*
* TODO: Split into own method.
*/
- if ( ( Settings::instance()->get_setting( ReferenceContainerSettingsGroup::FOOTNOTE_URL_WRAP_ENABLED['key'] )->get_value() ) ) {
+ if ( ( $this->settings->get_setting_value( ReferenceContainerSettingsGroup::FOOTNOTE_URL_WRAP_ENABLED['key'] ) ) ) {
$footnote_text = preg_replace(
'#(?get_setting( HardLinksSettingsGroup::REFERRER_FRAGMENT_ID_SLUG['key'] )->get_value();
- self::$footnote_link_slug = Settings::instance()->get_setting( HardLinksSettingsGroup::FOOTNOTE_FRAGMENT_ID_SLUG['key'] )->get_value();
- self::$link_ids_separator = Settings::instance()->get_setting( HardLinksSettingsGroup::HARD_LINK_IDS_SEPARATOR['key'] )->get_value();
+ self::$referrer_link_slug = $this->settings->get_setting_value( HardLinksSettingsGroup::REFERRER_FRAGMENT_ID_SLUG['key'] );
+ self::$footnote_link_slug = $this->settings->get_setting_value( HardLinksSettingsGroup::FOOTNOTE_FRAGMENT_ID_SLUG['key'] );
+ self::$link_ids_separator = $this->settings->get_setting_value( HardLinksSettingsGroup::HARD_LINK_IDS_SEPARATOR['key'] );
// Streamline ID concatenation.
self::$post_container_id_compound = self::$link_ids_separator;
@@ -1437,11 +1445,11 @@ class Parser {
// Display the footnote referrers and the tooltips.
if ( ! $hide_footnotes_text ) {
- $index = Convert::index( $footnote_index, Settings::instance()->get_setting( NumberingSettingsGroup::FOOTNOTES_COUNTER_STYLE['key'] )->get_value() );
+ $index = Convert::index( $footnote_index, $this->settings->get_setting_value( NumberingSettingsGroup::FOOTNOTES_COUNTER_STYLE['key'] ) );
// Display only a truncated footnote text if option enabled.
- $enable_excerpt = Settings::instance()->get_setting( TooltipTruncationSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_EXCERPT_ENABLED['key'] )->get_value();
- $max_length = Settings::instance()->get_setting( TooltipTruncationSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_EXCERPT_LENGTH['key'] )->get_value();
+ $enable_excerpt = $this->settings->get_setting_value( TooltipTruncationSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_EXCERPT_ENABLED['key'] );
+ $max_length = $this->settings->get_setting_value( TooltipTruncationSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_EXCERPT_LENGTH['key'] );
// Define excerpt text as footnote text by default.
$excerpt_text = $footnote_text;
@@ -1467,7 +1475,7 @@ class Parser {
if ( General::$amp_enabled ) {
// If the reference container is also collapsed by default.
- if ( ( Settings::instance()->get_setting( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_COLLAPSE['key'] )->get_value() ) ) {
+ if ( ( $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_COLLAPSE['key'] ) ) ) {
$excerpt_text .= ' on="tap:footnote_references_container_';
$excerpt_text .= self::$post_id . '_' . self::$reference_container_id;
@@ -1501,7 +1509,7 @@ class Parser {
$excerpt_text .= '>';
// Configurable read-on button label.
- $excerpt_text .= Settings::instance()->get_setting( TooltipTruncationSettingsGroup::FOOTNOTES_TOOLTIP_READON_LABEL['key'] )->get_value();
+ $excerpt_text .= $this->settings->get_setting_value( TooltipTruncationSettingsGroup::FOOTNOTES_TOOLTIP_READON_LABEL['key'] );
$excerpt_text .= self::$hard_links_enabled ? '' : '';
}
@@ -1512,7 +1520,7 @@ class Parser {
*
* Define the HTML element to use for the referrers.
*/
- if ( Settings::instance()->get_setting( ReferrersSettingsGroup::FOOTNOTES_REFERRER_SUPERSCRIPT_TAGS['key'] )->get_value() ) {
+ if ( $this->settings->get_setting_value( ReferrersSettingsGroup::FOOTNOTES_REFERRER_SUPERSCRIPT_TAGS['key'] ) ) {
$sup_span = 'sup';
@@ -1555,7 +1563,7 @@ class Parser {
$referrer_anchor_element = '';
// The link element is set independently as it may be needed for styling.
- if ( ( Settings::instance()->get_setting( ReferenceContainerSettingsGroup::LINK_ELEMENT_ENABLED['key'] )->get_value() ) ) {
+ if ( ( $this->settings->get_setting_value( ReferenceContainerSettingsGroup::LINK_ELEMENT_ENABLED['key'] ) ) ) {
self::$link_span = 'a';
self::$link_open_tag = '';
@@ -1599,9 +1607,9 @@ class Parser {
'note_id' => $index,
'hard-link' => $footnote_link_argument,
'sup-span' => $sup_span,
- 'before' => Settings::instance()->get_setting( ReferrersSettingsGroup::FOOTNOTES_STYLING_BEFORE['key'] )->get_value(),
+ 'before' => $this->settings->get_setting_value( ReferrersSettingsGroup::FOOTNOTES_STYLING_BEFORE['key'] ),
'index' => $index,
- 'after' => Settings::instance()->get_setting( ReferrersSettingsGroup::FOOTNOTES_STYLING_AFTER['key'] )->get_value(),
+ 'after' => $this->settings->get_setting_value( ReferrersSettingsGroup::FOOTNOTES_STYLING_AFTER['key'] ),
'anchor-element' => $referrer_anchor_element,
'style' => $tooltip_style,
'text' => $tooltip_content,
@@ -1615,12 +1623,12 @@ class Parser {
// If tooltips are enabled but neither AMP nor alternative are.
if ( General::$tooltips_enabled && ! General::$amp_enabled && ! General::$alternative_tooltips_enabled ) {
- $offset_y = Settings::instance()->get_setting( TooltipPositionSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_OFFSET_Y['key'] )->get_value();
- $offset_x = Settings::instance()->get_setting( TooltipPositionSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_OFFSET_X['key'] )->get_value();
- $fade_in_delay = Settings::instance()->get_setting( TooltipTimingSettingsGroup::MOUSE_OVER_BOX_FADE_IN_DELAY['key'] )->get_value();
- $fade_in_duration = Settings::instance()->get_setting( TooltipTimingSettingsGroup::MOUSE_OVER_BOX_FADE_IN_DURATION['key'] )->get_value();
- $fade_out_delay = Settings::instance()->get_setting( TooltipTimingSettingsGroup::MOUSE_OVER_BOX_FADE_OUT_DELAY['key'] )->get_value();
- $fade_out_duration = Settings::instance()->get_setting( TooltipTimingSettingsGroup::MOUSE_OVER_BOX_FADE_OUT_DURATION['key'] )->get_value();
+ $offset_y = $this->settings->get_setting_value( TooltipPositionSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_OFFSET_Y['key'] );
+ $offset_x = $this->settings->get_setting_value( TooltipPositionSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_OFFSET_X['key'] );
+ $fade_in_delay = $this->settings->get_setting_value( TooltipTimingSettingsGroup::MOUSE_OVER_BOX_FADE_IN_DELAY['key'] );
+ $fade_in_duration = $this->settings->get_setting_value( TooltipTimingSettingsGroup::MOUSE_OVER_BOX_FADE_IN_DURATION['key'] );
+ $fade_out_delay = $this->settings->get_setting_value( TooltipTimingSettingsGroup::MOUSE_OVER_BOX_FADE_OUT_DELAY['key'] );
+ $fade_out_duration = $this->settings->get_setting_value( TooltipTimingSettingsGroup::MOUSE_OVER_BOX_FADE_OUT_DURATION['key'] );
// Fill in 'public/partials/tooltip.html'.
$template_tooltip->replace(
@@ -1628,7 +1636,7 @@ class Parser {
'post_id' => self::$post_id,
'container_id' => self::$reference_container_id,
'note_id' => $index,
- 'position' => Settings::instance()->get_setting( TooltipPositionSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_POSITION['key'] )->get_value(),
+ 'position' => $this->settings->get_setting_value( TooltipPositionSettingsGroup::FOOTNOTES_MOUSE_OVER_BOX_POSITION['key'] ),
'offset-y' => empty( $offset_y ) ? 0 : $offset_y,
'offset-x' => empty( $offset_x ) ? 0 : $offset_x,
'fade-in-delay' => empty( $fade_in_delay ) ? 0 : $fade_in_delay,
@@ -1701,16 +1709,14 @@ class Parser {
*/
// If the backlink symbol is enabled.
- if ( ( Settings::instance()->get_setting( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_BACKLINK_SYMBOL_ENABLE['key'] )->get_value() ) ) {
-
+ if ( $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_BACKLINK_SYMBOL_ENABLE['key'] )) {
+ $arrow_setting = $this->settings->get_setting( BacklinkSymbolSettingsGroup::HYPERLINK_ARROW['key']);
+
// Get html arrow.
- $arrow = Convert::get_arrow( Settings::instance()->get_setting( BacklinkSymbolSettingsGroup::HYPERLINK_ARROW['key'] )->get_value() );
- // Set html arrow to the first one if invalid index defined.
- if ( is_array( $arrow ) ) {
- $arrow = Convert::get_arrow( 0 );
- }
+ $arrow = $arrow_setting->get_input_options()[$arrow_setting->get_value() || 0];
+
// Get user defined arrow.
- $arrow_user_defined = Settings::instance()->get_setting( BacklinkSymbolSettingsGroup::HYPERLINK_ARROW_USER_DEFINED['key'] )->get_value();
+ $arrow_user_defined = $this->settings->get_setting_value( BacklinkSymbolSettingsGroup::HYPERLINK_ARROW_USER_DEFINED['key'] );
if ( ! empty( $arrow_user_defined ) ) {
$arrow = $arrow_user_defined;
}
@@ -1733,12 +1739,12 @@ class Parser {
* Initially an appended comma was hard-coded in this algorithm for enumerations.
* The comma in enumerations is not universally preferred.
*/
- if ( ( Settings::instance()->get_setting( ReferenceContainerSettingsGroup::BACKLINKS_SEPARATOR_ENABLED['key'] )->get_value() ) ) {
+ if ( ( $this->settings->get_setting_value( ReferenceContainerSettingsGroup::BACKLINKS_SEPARATOR_ENABLED['key'] ) ) ) {
if ( empty( $separator ) ) {
// If it is not, check which option is on.
- $separator_option = Settings::instance()->get_setting( ReferenceContainerSettingsGroup::BACKLINKS_SEPARATOR_OPTION['key'] )->get_value();
+ $separator_option = $this->settings->get_setting_value( ReferenceContainerSettingsGroup::BACKLINKS_SEPARATOR_OPTION['key'] );
// TODO: replace with `match` (but currently it breaks the Rector
// downgrade to PHP 7.4.
// https://github.com/rectorphp/rector/issues/6315
@@ -1753,7 +1759,7 @@ class Parser {
$separator = ' –';
break;
default:
- $separator = Settings::instance()->get_setting( ReferenceContainerSettingsGroup::BACKLINKS_SEPARATOR_CUSTOM['key'] )->get_value();
+ $separator = $this->settings->get_setting_value( ReferenceContainerSettingsGroup::BACKLINKS_SEPARATOR_CUSTOM['key'] );
break;
}
}
@@ -1767,12 +1773,12 @@ class Parser {
*
* Initially a dot was appended in the table row template.
*/
- if ( ( Settings::instance()->get_setting( ReferenceContainerSettingsGroup::BACKLINKS_TERMINATOR_ENABLED['key'] )->get_value() ) ) {
+ if ( ( $this->settings->get_setting_value( ReferenceContainerSettingsGroup::BACKLINKS_TERMINATOR_ENABLED['key'] ) ) ) {
if ( empty( $terminator ) ) {
// If it is not, check which option is on.
- $terminator_option = Settings::instance()->get_setting( ReferenceContainerSettingsGroup::BACKLINKS_TERMINATOR_OPTION['key'] )->get_value();
+ $terminator_option = $this->settings->get_setting_value( ReferenceContainerSettingsGroup::BACKLINKS_TERMINATOR_OPTION['key'] );
// TODO: replace with `match` (but currently it breaks the Rector
// downgrade to PHP 7.4.
// https://github.com/rectorphp/rector/issues/6315
@@ -1787,7 +1793,7 @@ class Parser {
$terminator = ':';
break;
default:
- $terminator = Settings::instance()->get_setting( ReferenceContainerSettingsGroup::BACKLINKS_TERMINATOR_CUSTOM['key'] )->get_value();
+ $terminator = $this->settings->get_setting_value( ReferenceContainerSettingsGroup::BACKLINKS_TERMINATOR_CUSTOM['key'] );
break;
}
}
@@ -1804,7 +1810,7 @@ class Parser {
* Variable number length and proportional character width require explicit line breaks.
* Otherwise, an ordinary space character offering a line break opportunity is inserted.
*/
- $line_break = ( Settings::instance()->get_setting( ReferenceContainerSettingsGroup::BACKLINKS_LINE_BREAKS_ENABLED['key'] )->get_value() ) ? '
' : ' ';
+ $line_break = ( $this->settings->get_setting_value( ReferenceContainerSettingsGroup::BACKLINKS_LINE_BREAKS_ENABLED['key'] ) ) ? '
' : ' ';
/*
* Line breaks for source readability.
@@ -1818,7 +1824,7 @@ class Parser {
/*
* Reference container table row template load.
*/
- $combine_identical_footnotes = ( Settings::instance()->get_setting( NumberingSettingsGroup::COMBINE_IDENTICAL_FOOTNOTES['key'] )->get_value() );
+ $combine_identical_footnotes = ( $this->settings->get_setting_value( NumberingSettingsGroup::COMBINE_IDENTICAL_FOOTNOTES['key'] ) );
// AMP compatibility requires a full set of AMP compatible table row templates.
if ( General::$amp_enabled ) {
@@ -1826,9 +1832,9 @@ class Parser {
if ( $combine_identical_footnotes ) {
// The combining template allows for backlink clusters and supports cell clicking for single notes.
$template = new Template( Template::PUBLIC, 'amp-reference-container-body-combi' );
- } elseif ( ( Settings::instance()->get_setting( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_3COLUMN_LAYOUT_ENABLE['key'] )->get_value() ) ) {
+ } elseif ( ( $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_3COLUMN_LAYOUT_ENABLE['key'] ) ) ) {
$template = new Template( Template::PUBLIC, 'amp-reference-container-body-3column' );
- } elseif ( ( Settings::instance()->get_setting( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_BACKLINK_SYMBOL_SWITCH['key'] )->get_value() ) ) {
+ } elseif ( ( $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_BACKLINK_SYMBOL_SWITCH['key'] ) ) ) {
$template = new Template( Template::PUBLIC, 'amp-reference-container-body-switch' );
} else {
@@ -1839,9 +1845,9 @@ class Parser {
} elseif ( $combine_identical_footnotes ) {
// The combining template allows for backlink clusters and supports cell clicking for single notes.
$template = new Template( Template::PUBLIC, 'reference-container-body-combi' );
- } elseif ( ( Settings::instance()->get_setting( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_3COLUMN_LAYOUT_ENABLE['key'] )->get_value() ) ) {
+ } elseif ( ( $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_3COLUMN_LAYOUT_ENABLE['key'] ) ) ) {
$template = new Template( Template::PUBLIC, 'reference-container-body-3column' );
- } elseif ( ( Settings::instance()->get_setting( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_BACKLINK_SYMBOL_SWITCH['key'] )->get_value() ) ) {
+ } elseif ( ( $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_BACKLINK_SYMBOL_SWITCH['key'] ) ) ) {
$template = new Template( Template::PUBLIC, 'reference-container-body-switch' );
} else {
@@ -1853,7 +1859,7 @@ class Parser {
/*
* Switch backlink symbol and footnote number.
*/
- $symbol_switch = ( Settings::instance()->get_setting( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_BACKLINK_SYMBOL_SWITCH['key'] )->get_value() );
+ $symbol_switch = ( $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_BACKLINK_SYMBOL_SWITCH['key'] ) );
// Loop through all footnotes found in the page.
$num_footnotes = count( self::$footnotes );
@@ -1873,7 +1879,7 @@ class Parser {
// Get the footnote index string and.
// Keep supporting legacy index placeholder.
- $footnote_id = Convert::index( $index + 1, Settings::instance()->get_setting( NumberingSettingsGroup::FOOTNOTES_COUNTER_STYLE['key'] )->get_value() );
+ $footnote_id = Convert::index( $index + 1, $this->settings->get_setting_value( NumberingSettingsGroup::FOOTNOTES_COUNTER_STYLE['key'] ) );
/**
* Case of only one backlink per table row.
@@ -1893,9 +1899,9 @@ class Parser {
*
* @since 2.5.4
*/
- if ( Settings::instance()->get_setting( HardLinksSettingsGroup::FOOTNOTES_BACKLINK_TOOLTIP_ENABLE['key'] )->get_value() ) {
+ if ( $this->settings->get_setting_value( HardLinksSettingsGroup::FOOTNOTES_BACKLINK_TOOLTIP_ENABLE['key'] ) ) {
$use_backbutton_hint = ' title="';
- $use_backbutton_hint .= Settings::instance()->get_setting( HardLinksSettingsGroup::FOOTNOTES_BACKLINK_TOOLTIP_TEXT['key'] )->get_value();
+ $use_backbutton_hint .= $this->settings->get_setting_value( HardLinksSettingsGroup::FOOTNOTES_BACKLINK_TOOLTIP_TEXT['key'] );
$use_backbutton_hint .= '"';
} else {
$use_backbutton_hint = '';
@@ -2018,7 +2024,7 @@ class Parser {
$flag_combined = true;
// Update the footnote ID.
- $footnote_id = Convert::index( ( $check_index + 1 ), Settings::instance()->get_setting( NumberingSettingsGroup::FOOTNOTES_COUNTER_STYLE['key'] )->get_value() );
+ $footnote_id = Convert::index( ( $check_index + 1 ), $this->settings->get_setting_value( NumberingSettingsGroup::FOOTNOTES_COUNTER_STYLE['key'] ) );
// Resume composing the backlinks enumeration.
$footnote_backlinks .= "$separator";
@@ -2081,10 +2087,10 @@ class Parser {
$has_tooltip_text = (bool) $tooltip_text_length;
if ( $has_tooltip_text ) {
$not_tooltip_text = substr( $footnote_text, ( $tooltip_text_length + self::$tooltip_shortcode_length ) );
- self::$mirror_tooltip_text = Settings::instance()->get_setting( TooltipTextSettingsGroup::FOOTNOTES_TOOLTIP_EXCERPT_MIRROR_ENABLE['key'] )->get_value();
+ self::$mirror_tooltip_text = $this->settings->get_setting_value( TooltipTextSettingsGroup::FOOTNOTES_TOOLTIP_EXCERPT_MIRROR_ENABLE['key'] );
if ( self::$mirror_tooltip_text ) {
$tooltip_text = substr( $footnote_text, 0, $tooltip_text_length );
- $reference_text_introducer = Settings::instance()->get_setting( TooltipTextSettingsGroup::FOOTNOTES_TOOLTIP_EXCERPT_MIRROR_SEPARATOR['key'] )->get_value();
+ $reference_text_introducer = $this->settings->get_setting_value( TooltipTextSettingsGroup::FOOTNOTES_TOOLTIP_EXCERPT_MIRROR_SEPARATOR['key'] );
$reference_text = $tooltip_text . $reference_text_introducer . $not_tooltip_text;
} else {
$reference_text = $not_tooltip_text;
@@ -2103,7 +2109,7 @@ class Parser {
// Used in standard layout W/O COMBINED FOOTNOTES.
'post_id' => self::$post_id,
'container_id' => self::$reference_container_id,
- 'note_id' => Convert::index( $first_footnote_index, Settings::instance()->get_setting( NumberingSettingsGroup::FOOTNOTES_COUNTER_STYLE['key'] )->get_value() ),
+ 'note_id' => Convert::index( $first_footnote_index, $this->settings->get_setting_value( NumberingSettingsGroup::FOOTNOTES_COUNTER_STYLE['key'] ) ),
'link-start' => self::$link_open_tag,
'link-end' => self::$link_close_tag,
'link-span' => self::$link_span,
@@ -2132,10 +2138,11 @@ class Parser {
}
// Call again for robustness when priority levels don't match any longer.
- self::$scroll_offset = Settings::instance()->get_setting( ScrollingSettingsGroup::FOOTNOTES_SCROLL_OFFSET['key'] )->get_value();
+ // TODO: remove cast
+ self::$scroll_offset = (int) $this->settings->get_setting_value( ScrollingSettingsGroup::FOOTNOTES_SCROLL_OFFSET['key'] );
// Streamline.
- $collapse_default = ( Settings::instance()->get_setting( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_COLLAPSE['key'] )->get_value() );
+ $collapse_default = $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_COLLAPSE['key'] );
/*
* Reference container label.
@@ -2144,14 +2151,14 @@ class Parser {
* In case of empty label that would apply to the left half button character.
* Hence the point in setting an empty label to U+202F NARROW NO-BREAK SPACE.
*/
- $reference_container_label = Settings::instance()->get_setting( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_NAME['key'] )->get_value();
+ $reference_container_label = $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_NAME['key'] );
// Select the reference container template.
// Whether AMP compatibility mode is enabled.
if ( General::$amp_enabled ) {
// Whether the reference container is collapsed by default.
- if ( ( Settings::instance()->get_setting( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_COLLAPSE['key'] )->get_value() ) ) {
+ if ( ( $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_COLLAPSE['key'] ) ) ) {
// Load 'public/partials/amp-reference-container-collapsed.html'.
$template_container = new Template( Template::PUBLIC, 'amp-reference-container-collapsed' );
@@ -2181,11 +2188,11 @@ class Parser {
if ( 'jquery' === General::$script_mode ) {
$scroll_offset = ( self::$scroll_offset / 100 );
- $scroll_up_duration = Settings::instance()->get_setting( ScrollingSettingsGroup::FOOTNOTES_SCROLL_DURATION['key'] )->get_value();
+ $scroll_up_duration = $this->settings->get_setting_value( ScrollingSettingsGroup::FOOTNOTES_SCROLL_DURATION['key'] );
- if ( Settings::instance()->get_setting( ScrollingSettingsGroup::FOOTNOTES_SCROLL_DURATION_ASYMMETRICITY['key'] )->get_value() ) {
+ if ( $this->settings->get_setting_value( ScrollingSettingsGroup::FOOTNOTES_SCROLL_DURATION_ASYMMETRICITY['key'] ) ) {
- $scroll_down_duration = Settings::instance()->get_setting( ScrollingSettingsGroup::FOOTNOTES_SCROLL_DOWN_DURATION['key'] )->get_value();
+ $scroll_down_duration = $this->settings->get_setting_value( ScrollingSettingsGroup::FOOTNOTES_SCROLL_DOWN_DURATION['key'] );
} else {
@@ -2193,8 +2200,8 @@ class Parser {
}
- $scroll_down_delay = Settings::instance()->get_setting( ScrollingSettingsGroup::FOOTNOTES_SCROLL_DOWN_DELAY['key'] )->get_value();
- $scroll_up_delay = Settings::instance()->get_setting( ScrollingSettingsGroup::FOOTNOTES_SCROLL_UP_DELAY['key'] )->get_value();
+ $scroll_down_delay = $this->settings->get_setting_value( ScrollingSettingsGroup::FOOTNOTES_SCROLL_DOWN_DELAY['key'] );
+ $scroll_up_delay = $this->settings->get_setting_value( ScrollingSettingsGroup::FOOTNOTES_SCROLL_UP_DELAY['key'] );
}
@@ -2202,7 +2209,7 @@ class Parser {
array(
'post_id' => self::$post_id,
'container_id' => self::$reference_container_id,
- 'element' => Settings::instance()->get_setting( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_LABEL_ELEMENT['key'] )->get_value(),
+ 'element' => $this->settings->get_setting_value( ReferenceContainerSettingsGroup::REFERENCE_CONTAINER_LABEL_ELEMENT['key'] ),
'name' => empty( $reference_container_label ) ? ' ' : $reference_container_label,
'button-style' => $collapse_default ? '' : 'display: none;',
'style' => $collapse_default ? 'display: none;' : '',