refactor: run Rector ORDER setlist

This commit is contained in:
Ben Goldsworthy 2021-05-02 21:05:37 +01:00
parent 667d8dada9
commit 114121a7e2
9 changed files with 542 additions and 568 deletions

View file

@ -65,35 +65,6 @@ class Admin {
}
/**
* Load the required admin-specific dependencies.
*
* Includes the following files that provide the admin-specific functionality
* of this plugin:
*
* - {@see WYSIWYG}: Provides plugin integration with the WYSIWYG editor.
* - {@see layout\Settings}: Defines the plugin dashboard page(s).
*
* @access private
*
* @since 2.8.0
*/
private function load_dependencies(): void {
/**
* The class responsible for WYSIWYG editor integration.
*/
require_once plugin_dir_path( __DIR__ ) . 'admin/class-wysiwyg.php';
$this->wysiwyg = new WYSIWYG( $this->plugin_name );
/**
* The class responsible for constructing the plugin dashboard page(s).
*/
require_once plugin_dir_path( __DIR__ ) . 'admin/layout/class-init.php';
new layout\Init( $this->plugin_name );
}
/**
* Register the stylesheets for the admin area.
*
@ -154,6 +125,34 @@ class Admin {
$plugin_links[] = sprintf( '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6Z6CZDW8PPBBJ" target="_blank">%s</a>', __( 'Donate', 'footnotes' ) );
return $plugin_links;
}
/**
* Load the required admin-specific dependencies.
*
* Includes the following files that provide the admin-specific functionality
* of this plugin:
*
* - {@see WYSIWYG}: Provides plugin integration with the WYSIWYG editor.
* - {@see layout\Settings}: Defines the plugin dashboard page(s).
*
* @access private
*
* @since 2.8.0
*/
private function load_dependencies(): void {
/**
* The class responsible for WYSIWYG editor integration.
*/
require_once plugin_dir_path( __DIR__ ) . 'admin/class-wysiwyg.php';
$this->wysiwyg = new WYSIWYG( $this->plugin_name );
/**
* The class responsible for constructing the plugin dashboard page(s).
*/
require_once plugin_dir_path( __DIR__ ) . 'admin/layout/class-init.php';
new layout\Init( $this->plugin_name );
}
}

View file

@ -69,6 +69,121 @@ abstract class Engine {
* @since 1.5.0
*/
abstract public function get_priority(): int;
/**
* Registers a sub-page.
*
* @since 1.5.0
*/
public function register_sub_page(): void {
global $submenu;
if ( array_key_exists( plugin_basename( Init::MAIN_MENU_SLUG ), $submenu ) ) {
foreach ( $submenu[ plugin_basename( Init::MAIN_MENU_SLUG ) ] as $sub_menu ) {
if ( plugin_basename( Init::MAIN_MENU_SLUG . $this->get_sub_page_slug() ) === $sub_menu[2] ) {
remove_submenu_page( Init::MAIN_MENU_SLUG, Init::MAIN_MENU_SLUG . $this->get_sub_page_slug() );
}
}
}
$this->sub_page_hook = add_submenu_page(
Init::MAIN_MENU_SLUG,
$this->get_sub_page_title(),
$this->get_sub_page_title(),
'manage_options',
Init::MAIN_MENU_SLUG . $this->get_sub_page_slug(),
fn() => $this->display_content()
);
}
/**
* Registers all sections for a sub-page.
*
* @since 1.5.0
*/
public function register_sections(): void {
foreach ( $this->get_sections() as $section ) {
// Append tab to the tab-array.
$this->sections[ $section['id'] ] = $section;
add_settings_section(
$section['id'],
'',
fn() => $this->description(),
$section['id']
);
$this->register_meta_boxes( $section['id'] );
}
}
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
/**
* Displays the content of specific sub-page.
*
* @since 1.5.0
* @todo Review nonce verification.
*/
public function display_content(): void {
$this->append_scripts();
$active_section_id = isset( $_GET['t'] ) ? wp_unslash( $_GET['t'] ) : array_key_first( $this->sections );
$active_section = $this->sections[ $active_section_id ];
// Store settings.
$settings_updated = false;
if ( array_key_exists( 'save-settings', $_POST ) && 'save' === $_POST['save-settings'] ) {
unset( $_POST['save-settings'] );
unset( $_POST['submit'] );
$settings_updated = $this->save_settings();
}
// Display all sections and highlight the active section.
echo '<div class="wrap">';
echo '<h2 class="nav-tab-wrapper">';
// Iterate through all register sections.
foreach ( $this->sections as $id => $description ) {
echo sprintf(
'<a class="nav-tab%s" href="?page=%s&t=%s">%s</a>',
( $id === $active_section['id'] ) ? ' nav-tab-active' : '',
Init::MAIN_MENU_SLUG,
$id,
$description['title']
);
}
echo '</h2><br/>';
if ( $settings_updated ) {
echo sprintf( '<div id="message" class="updated">%s</div>', __( 'Settings saved', 'footnotes' ) );
}
// Form to submit the active section.
echo '<!--suppress HtmlUnknownTarget --><form method="post" action="">';
echo '<input type="hidden" name="save-settings" value="save" />';
// Outputs the settings field of the active section.
do_settings_sections( $active_section['id'] );
do_meta_boxes( $active_section['id'], 'main', null );
// Add submit button to active section if defined.
if ( $active_section['submit'] ) {
submit_button();
}
echo '</form>';
echo '</div>';
// Echo JavaScript for the expand/collapse function of the meta boxes.
echo '<script type="text/javascript">';
echo 'jQuery(document).ready(function ($) {';
echo 'jQuery(".footnotes-color-picker").wpColorPicker();';
echo "jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed');";
echo "postboxes.add_postbox_toggles('" . $this->sub_page_hook . "');";
echo '});';
echo '</script>';
}
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
/**
* Output the description of a section. May be overwritten in any section.
*
* @since 1.5.0
* @todo Required? Should be `abstract`?
*/
public function description(): void {
// Default no description will be displayed.
}
/**
* Returns the unique slug of the child sub-page.
@ -170,186 +285,6 @@ abstract class Engine {
);
}
/**
* Registers a sub-page.
*
* @since 1.5.0
*/
public function register_sub_page(): void {
global $submenu;
if ( array_key_exists( plugin_basename( Init::MAIN_MENU_SLUG ), $submenu ) ) {
foreach ( $submenu[ plugin_basename( Init::MAIN_MENU_SLUG ) ] as $sub_menu ) {
if ( plugin_basename( Init::MAIN_MENU_SLUG . $this->get_sub_page_slug() ) === $sub_menu[2] ) {
remove_submenu_page( Init::MAIN_MENU_SLUG, Init::MAIN_MENU_SLUG . $this->get_sub_page_slug() );
}
}
}
$this->sub_page_hook = add_submenu_page(
Init::MAIN_MENU_SLUG,
$this->get_sub_page_title(),
$this->get_sub_page_title(),
'manage_options',
Init::MAIN_MENU_SLUG . $this->get_sub_page_slug(),
fn() => $this->display_content()
);
}
/**
* Registers all sections for a sub-page.
*
* @since 1.5.0
*/
public function register_sections(): void {
foreach ( $this->get_sections() as $section ) {
// Append tab to the tab-array.
$this->sections[ $section['id'] ] = $section;
add_settings_section(
$section['id'],
'',
fn() => $this->description(),
$section['id']
);
$this->register_meta_boxes( $section['id'] );
}
}
/**
* Registers all Meta boxes for a sub-page.
*
* @access private
* @param string $parent_id Parent section unique ID.
*
* @since 1.5.0
*/
private function register_meta_boxes( string $parent_id ): void {
// Iterate through each meta box.
foreach ( $this->get_meta_boxes() as $meta_box ) {
if ( $parent_id !== $meta_box['parent'] ) {
continue;
}
add_meta_box(
$parent_id . '-' . $meta_box['id'],
$meta_box['title'],
array( $this, $meta_box['callback'] ),
$parent_id,
'main'
);
}
}
/**
* Append JavaScript and CSS files for specific sub-page.
*
* @access private
*
* @since 1.5.0
* @todo Move to {@see Includes\Admin}.
*/
private function append_scripts(): void {
wp_enqueue_script( 'postbox' );
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'wp-color-picker' );
}
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
/**
* Displays the content of specific sub-page.
*
* @since 1.5.0
* @todo Review nonce verification.
*/
public function display_content(): void {
$this->append_scripts();
$active_section_id = isset( $_GET['t'] ) ? wp_unslash( $_GET['t'] ) : array_key_first( $this->sections );
$active_section = $this->sections[ $active_section_id ];
// Store settings.
$settings_updated = false;
if ( array_key_exists( 'save-settings', $_POST ) && 'save' === $_POST['save-settings'] ) {
unset( $_POST['save-settings'] );
unset( $_POST['submit'] );
$settings_updated = $this->save_settings();
}
// Display all sections and highlight the active section.
echo '<div class="wrap">';
echo '<h2 class="nav-tab-wrapper">';
// Iterate through all register sections.
foreach ( $this->sections as $id => $description ) {
echo sprintf(
'<a class="nav-tab%s" href="?page=%s&t=%s">%s</a>',
( $id === $active_section['id'] ) ? ' nav-tab-active' : '',
Init::MAIN_MENU_SLUG,
$id,
$description['title']
);
}
echo '</h2><br/>';
if ( $settings_updated ) {
echo sprintf( '<div id="message" class="updated">%s</div>', __( 'Settings saved', 'footnotes' ) );
}
// Form to submit the active section.
echo '<!--suppress HtmlUnknownTarget --><form method="post" action="">';
echo '<input type="hidden" name="save-settings" value="save" />';
// Outputs the settings field of the active section.
do_settings_sections( $active_section['id'] );
do_meta_boxes( $active_section['id'], 'main', null );
// Add submit button to active section if defined.
if ( $active_section['submit'] ) {
submit_button();
}
echo '</form>';
echo '</div>';
// Echo JavaScript for the expand/collapse function of the meta boxes.
echo '<script type="text/javascript">';
echo 'jQuery(document).ready(function ($) {';
echo 'jQuery(".footnotes-color-picker").wpColorPicker();';
echo "jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed');";
echo "postboxes.add_postbox_toggles('" . $this->sub_page_hook . "');";
echo '});';
echo '</script>';
}
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
/**
* Save all plugin settings.
*
* @access private
* @return bool `true` on save success, else `false`.
*
* @since 1.5.0
* @todo Review nonce verification.
*/
private function save_settings(): bool {
$new_settings = array();
$active_section_id = isset( $_GET['t'] ) ? wp_unslash( $_GET['t'] ) : array_key_first( $this->sections );
$active_section = $this->sections[ $active_section_id ];
foreach ( array_keys( Includes\Settings::instance()->get_defaults( $active_section['container'] ) ) as $key ) {
$new_settings[ $key ] = array_key_exists( $key, $_POST ) ? wp_unslash( $_POST[ $key ] ) : '';
}
// Update settings.
return Includes\Settings::instance()->save_options( $active_section['container'], $new_settings );
}
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
/**
* Output the description of a section. May be overwritten in any section.
*
* @since 1.5.0
* @todo Required? Should be `abstract`?
*/
public function description(): void {
// Default no description will be displayed.
}
/**
* Loads a specified setting.
*
@ -582,5 +517,63 @@ abstract class Engine {
$max
);
}
/**
* Registers all Meta boxes for a sub-page.
*
* @access private
* @param string $parent_id Parent section unique ID.
*
* @since 1.5.0
*/
private function register_meta_boxes( string $parent_id ): void {
// Iterate through each meta box.
foreach ( $this->get_meta_boxes() as $meta_box ) {
if ( $parent_id !== $meta_box['parent'] ) {
continue;
}
add_meta_box(
$parent_id . '-' . $meta_box['id'],
$meta_box['title'],
array( $this, $meta_box['callback'] ),
$parent_id,
'main'
);
}
}
/**
* Append JavaScript and CSS files for specific sub-page.
*
* @access private
*
* @since 1.5.0
* @todo Move to {@see Includes\Admin}.
*/
private function append_scripts(): void {
wp_enqueue_script( 'postbox' );
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'wp-color-picker' );
}
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
/**
* Save all plugin settings.
*
* @access private
* @return bool `true` on save success, else `false`.
*
* @since 1.5.0
* @todo Review nonce verification.
*/
private function save_settings(): bool {
$new_settings = array();
$active_section_id = isset( $_GET['t'] ) ? wp_unslash( $_GET['t'] ) : array_key_first( $this->sections );
$active_section = $this->sections[ $active_section_id ];
foreach ( array_keys( Includes\Settings::instance()->get_defaults( $active_section['container'] ) ) as $key ) {
$new_settings[ $key ] = array_key_exists( $key, $_POST ) ? wp_unslash( $_POST[ $key ] ) : '';
}
// Update settings.
return Includes\Settings::instance()->save_options( $active_section['container'], $new_settings );
}
}

View file

@ -86,36 +86,6 @@ class Init {
);
}
/**
* Load the required dependencies for the layouts pages.
*
* Include the following files that make up the plugin:
*
* - {@see Includes\Config}: defines plugin constants;
* - {@see Includes\Settings}: defines configurable plugin settings; and
* - {@see Settings}: defines the plugin settings page.
*
* @access private
*
* @since 2.8.0
*/
private function load_dependencies(): void {
/**
* Defines plugin constants.
*/
require_once plugin_dir_path( dirname( __FILE__, 2 ) ) . 'includes/class-config.php';
/**
* Defines configurable plugin settings.
*/
require_once plugin_dir_path( dirname( __FILE__, 2 ) ) . 'includes/class-settings.php';
/**
* Represents the plugin settings dashboard page.
*/
require_once plugin_dir_path( __DIR__ ) . 'layout/class-settings.php';
}
/**
* Registers the settings and initialises the settings page.
*
@ -207,5 +177,34 @@ class Init {
);
exit;
}
/**
* Load the required dependencies for the layouts pages.
*
* Include the following files that make up the plugin:
*
* - {@see Includes\Config}: defines plugin constants;
* - {@see Includes\Settings}: defines configurable plugin settings; and
* - {@see Settings}: defines the plugin settings page.
*
* @access private
*
* @since 2.8.0
*/
private function load_dependencies(): void {
/**
* Defines plugin constants.
*/
require_once plugin_dir_path( dirname( __FILE__, 2 ) ) . 'includes/class-config.php';
/**
* Defines configurable plugin settings.
*/
require_once plugin_dir_path( dirname( __FILE__, 2 ) ) . 'includes/class-settings.php';
/**
* Represents the plugin settings dashboard page.
*/
require_once plugin_dir_path( __DIR__ ) . 'layout/class-settings.php';
}
// phpcs:enable WordPress.Security.NonceVerification.Missing
}

View file

@ -57,100 +57,6 @@ class Settings extends Engine {
return 10;
}
/**
* Returns the unique slug of the sub-page.
*
* @since 1.5.0
* @return string
*/
protected function get_sub_page_slug(): string {
return '-' . $this->plugin_name;
}
/**
* Returns the title of the sub-page.
*
* @since 1.5.0
* @return string
*/
protected function get_sub_page_title(): string {
return \footnotes\includes\Config::PLUGIN_PUBLIC_NAME;
}
/**
* Returns an array of all registered sections for the sub-page.
*
* @see Engine::add_section() For more information on the section array format.
* @return array[] All of the registered sections.
*
* @since 1.5.0
* @since 2.1.6 Remove conditional rendering of Expert tab.
*/
protected function get_sections(): array {
$tabs = array();
// Sync tab name with mirror in task.php.
$tabs[] = $this->add_section( 'settings', __( 'General settings', 'footnotes' ), 0, true );
// Sync tab name with mirror in public function custom_css_migration().
$tabs[] = $this->add_section( 'customize', __( 'Referrers and tooltips', 'footnotes' ), 1, true );
$tabs[] = $this->add_section( 'expert', __( 'Scope and priority', 'footnotes' ), 2, true );
$tabs[] = $this->add_section( 'customcss', __( 'Custom CSS', 'footnotes' ), 3, true );
$tabs[] = $this->add_section( 'how-to', __( 'Quick start guide', 'footnotes' ), 4, false );
return $tabs;
}
/**
* Returns an array of all registered meta boxes for each section of the sub-page.
*
* @see Engine::add_meta_box() For more information on the
* meta box array format.
* @return array[] All of the registered meta boxes.
*
* @since 1.5.0
* @since 2.2.0 Re-order and rename tabs.
*/
protected function get_meta_boxes(): array {
$meta_boxes = array();
$meta_boxes[] = $this->add_meta_box( 'settings', 'amp-compat', __( 'AMP compatibility', 'footnotes' ), 'amp_compat' );
$meta_boxes[] = $this->add_meta_box( 'settings', 'start-end', __( 'Footnote start and end short codes', 'footnotes' ), 'start_end' );
$meta_boxes[] = $this->add_meta_box( 'settings', 'numbering', __( 'Footnotes numbering', 'footnotes' ), 'numbering' );
$meta_boxes[] = $this->add_meta_box( 'settings', 'scrolling', __( 'Scrolling behavior', 'footnotes' ), 'scrolling' );
$meta_boxes[] = $this->add_meta_box( 'settings', 'hard-links', __( 'URL fragment ID configuration', 'footnotes' ), 'hard_links' );
$meta_boxes[] = $this->add_meta_box( 'settings', 'reference-container', __( 'Reference container', 'footnotes' ), 'reference_container' );
$meta_boxes[] = $this->add_meta_box( 'settings', 'excerpts', __( 'Footnotes in excerpts', 'footnotes' ), 'excerpts' );
$meta_boxes[] = $this->add_meta_box( 'settings', 'love', \footnotes\includes\Config::PLUGIN_HEADING_NAME . '&nbsp;' . \footnotes\includes\Config::LOVE_SYMBOL_HEADING, 'love' );
$meta_boxes[] = $this->add_meta_box( 'customize', 'hyperlink-arrow', __( 'Backlink symbol', 'footnotes' ), 'hyperlink_arrow' );
$meta_boxes[] = $this->add_meta_box( 'customize', 'superscript', __( 'Referrers', 'footnotes' ), 'superscript' );
$meta_boxes[] = $this->add_meta_box( 'customize', 'label-solution', __( 'Referrers in labels', 'footnotes' ), 'label_solution' );
$meta_boxes[] = $this->add_meta_box( 'customize', 'mouse-over-box', __( 'Tooltips', 'footnotes' ), 'mouseover_box' );
$meta_boxes[] = $this->add_meta_box( 'customize', 'mouse-over-box-position', __( 'Tooltip position', 'footnotes' ), 'mouseover_box_position' );
$meta_boxes[] = $this->add_meta_box( 'customize', 'mouse-over-box-dimensions', __( 'Tooltip dimensions', 'footnotes' ), 'mouseover_box_dimensions' );
$meta_boxes[] = $this->add_meta_box( 'customize', 'mouse-over-box-timing', __( 'Tooltip timing', 'footnotes' ), 'mouseover_box_timing' );
$meta_boxes[] = $this->add_meta_box( 'customize', 'mouse-over-box-truncation', __( 'Tooltip truncation', 'footnotes' ), 'mouseover_box_truncation' );
$meta_boxes[] = $this->add_meta_box( 'customize', 'mouse-over-box-text', __( 'Tooltip text', 'footnotes' ), 'mouseover_box_text' );
$meta_boxes[] = $this->add_meta_box( 'customize', 'mouse-over-box-appearance', __( 'Tooltip appearance', 'footnotes' ), 'mouseover_box_appearance' );
if ( Includes\Convert::to_bool( Includes\Settings::instance()->get( \footnotes\includes\Settings::CUSTOM_CSS_LEGACY_ENABLE ) ) ) {
$meta_boxes[] = $this->add_meta_box( 'customize', 'custom-css', __( 'Your existing Custom CSS code', 'footnotes' ), 'custom_css' );
}
$meta_boxes[] = $this->add_meta_box( 'expert', 'lookup', __( 'WordPress hooks with priority level', 'footnotes' ), 'lookup_hooks' );
if ( Includes\Convert::to_bool( Includes\Settings::instance()->get( \footnotes\includes\Settings::CUSTOM_CSS_LEGACY_ENABLE ) ) ) {
$meta_boxes[] = $this->add_meta_box( 'customcss', 'custom-css-migration', __( 'Your existing Custom CSS code', 'footnotes' ), 'custom_css_migration' );
}
$meta_boxes[] = $this->add_meta_box( 'customcss', 'custom-css-new', __( 'Custom CSS', 'footnotes' ), 'custom_css_new' );
$meta_boxes[] = $this->add_meta_box( 'how-to', 'help', __( 'Brief introduction: How to use the plugin', 'footnotes' ), 'help' );
$meta_boxes[] = $this->add_meta_box( 'how-to', 'donate', __( 'Help us to improve our Plugin', 'footnotes' ), 'donate' );
return $meta_boxes;
}
/**
* Displays the AMP compatibility mode option.
*
@ -1309,4 +1215,94 @@ class Settings extends Engine {
echo $template->get_content();
// phpcs:enable
}
/**
* Returns the unique slug of the sub-page.
*
* @since 1.5.0
* @return string
*/
protected function get_sub_page_slug(): string {
return '-' . $this->plugin_name;
}
/**
* Returns the title of the sub-page.
*
* @since 1.5.0
* @return string
*/
protected function get_sub_page_title(): string {
return \footnotes\includes\Config::PLUGIN_PUBLIC_NAME;
}
/**
* Returns an array of all registered sections for the sub-page.
*
* @see Engine::add_section() For more information on the section array format.
* @return array[] All of the registered sections.
*
* @since 1.5.0
* @since 2.1.6 Remove conditional rendering of Expert tab.
*/
protected function get_sections(): array {
$tabs = array();
// Sync tab name with mirror in task.php.
$tabs[] = $this->add_section( 'settings', __( 'General settings', 'footnotes' ), 0, true );
// Sync tab name with mirror in public function custom_css_migration().
$tabs[] = $this->add_section( 'customize', __( 'Referrers and tooltips', 'footnotes' ), 1, true );
$tabs[] = $this->add_section( 'expert', __( 'Scope and priority', 'footnotes' ), 2, true );
$tabs[] = $this->add_section( 'customcss', __( 'Custom CSS', 'footnotes' ), 3, true );
$tabs[] = $this->add_section( 'how-to', __( 'Quick start guide', 'footnotes' ), 4, false );
return $tabs;
}
/**
* Returns an array of all registered meta boxes for each section of the sub-page.
*
* @see Engine::add_meta_box() For more information on the
* meta box array format.
* @return array[] All of the registered meta boxes.
*
* @since 1.5.0
* @since 2.2.0 Re-order and rename tabs.
*/
protected function get_meta_boxes(): array {
$meta_boxes = array();
$meta_boxes[] = $this->add_meta_box( 'settings', 'amp-compat', __( 'AMP compatibility', 'footnotes' ), 'amp_compat' );
$meta_boxes[] = $this->add_meta_box( 'settings', 'start-end', __( 'Footnote start and end short codes', 'footnotes' ), 'start_end' );
$meta_boxes[] = $this->add_meta_box( 'settings', 'numbering', __( 'Footnotes numbering', 'footnotes' ), 'numbering' );
$meta_boxes[] = $this->add_meta_box( 'settings', 'scrolling', __( 'Scrolling behavior', 'footnotes' ), 'scrolling' );
$meta_boxes[] = $this->add_meta_box( 'settings', 'hard-links', __( 'URL fragment ID configuration', 'footnotes' ), 'hard_links' );
$meta_boxes[] = $this->add_meta_box( 'settings', 'reference-container', __( 'Reference container', 'footnotes' ), 'reference_container' );
$meta_boxes[] = $this->add_meta_box( 'settings', 'excerpts', __( 'Footnotes in excerpts', 'footnotes' ), 'excerpts' );
$meta_boxes[] = $this->add_meta_box( 'settings', 'love', \footnotes\includes\Config::PLUGIN_HEADING_NAME . '&nbsp;' . \footnotes\includes\Config::LOVE_SYMBOL_HEADING, 'love' );
$meta_boxes[] = $this->add_meta_box( 'customize', 'hyperlink-arrow', __( 'Backlink symbol', 'footnotes' ), 'hyperlink_arrow' );
$meta_boxes[] = $this->add_meta_box( 'customize', 'superscript', __( 'Referrers', 'footnotes' ), 'superscript' );
$meta_boxes[] = $this->add_meta_box( 'customize', 'label-solution', __( 'Referrers in labels', 'footnotes' ), 'label_solution' );
$meta_boxes[] = $this->add_meta_box( 'customize', 'mouse-over-box', __( 'Tooltips', 'footnotes' ), 'mouseover_box' );
$meta_boxes[] = $this->add_meta_box( 'customize', 'mouse-over-box-position', __( 'Tooltip position', 'footnotes' ), 'mouseover_box_position' );
$meta_boxes[] = $this->add_meta_box( 'customize', 'mouse-over-box-dimensions', __( 'Tooltip dimensions', 'footnotes' ), 'mouseover_box_dimensions' );
$meta_boxes[] = $this->add_meta_box( 'customize', 'mouse-over-box-timing', __( 'Tooltip timing', 'footnotes' ), 'mouseover_box_timing' );
$meta_boxes[] = $this->add_meta_box( 'customize', 'mouse-over-box-truncation', __( 'Tooltip truncation', 'footnotes' ), 'mouseover_box_truncation' );
$meta_boxes[] = $this->add_meta_box( 'customize', 'mouse-over-box-text', __( 'Tooltip text', 'footnotes' ), 'mouseover_box_text' );
$meta_boxes[] = $this->add_meta_box( 'customize', 'mouse-over-box-appearance', __( 'Tooltip appearance', 'footnotes' ), 'mouseover_box_appearance' );
if ( Includes\Convert::to_bool( Includes\Settings::instance()->get( \footnotes\includes\Settings::CUSTOM_CSS_LEGACY_ENABLE ) ) ) {
$meta_boxes[] = $this->add_meta_box( 'customize', 'custom-css', __( 'Your existing Custom CSS code', 'footnotes' ), 'custom_css' );
}
$meta_boxes[] = $this->add_meta_box( 'expert', 'lookup', __( 'WordPress hooks with priority level', 'footnotes' ), 'lookup_hooks' );
if ( Includes\Convert::to_bool( Includes\Settings::instance()->get( \footnotes\includes\Settings::CUSTOM_CSS_LEGACY_ENABLE ) ) ) {
$meta_boxes[] = $this->add_meta_box( 'customcss', 'custom-css-migration', __( 'Your existing Custom CSS code', 'footnotes' ), 'custom_css_migration' );
}
$meta_boxes[] = $this->add_meta_box( 'customcss', 'custom-css-new', __( 'Custom CSS', 'footnotes' ), 'custom_css_new' );
$meta_boxes[] = $this->add_meta_box( 'how-to', 'help', __( 'Brief introduction: How to use the plugin', 'footnotes' ), 'help' );
$meta_boxes[] = $this->add_meta_box( 'how-to', 'donate', __( 'Help us to improve our Plugin', 'footnotes' ), 'donate' );
return $meta_boxes;
}
}

View file

@ -46,102 +46,6 @@ class Convert {
}
}
/**
* Converts an integer into Latin ASCII characters, either lower or upper-case.
*
* This function works from values AZZ (meaning there is a limit of 676
* gootnotes per Page).
*
* @param int $value Value to be converted.
* @param bool $upper_case Whether to convert the value to upper-case.
*
* @since 1.0-gamma
* @todo Replace with built-in char casting.
*/
private static function to_latin( int $value, bool $upper_case ): string {
// Output string.
$return = '';
$offset = 0;
// Check if the value is higher then 26 = Z.
while ( $value > 26 ) {
// Increase offset and reduce counter.
$offset++;
$value -= 26;
}
// If offset set (more then Z), then add a new letter in front.
if ( $offset > 0 ) {
$return = chr( $offset + 64 );
}
// Add the origin letter.
$return .= chr( $value + 64 );
// Return the latin character representing the integer.
if ( $upper_case ) {
return strtoupper( $return );
}
return strtolower( $return );
}
/**
* Converts an integer to a leading-0 integer.
*
* @param int $value Value to be converted.
* @return string Value with a leading zero.
*
* @since 1.0-gamma
* @todo Replace with built-in string formatting.
*/
private static function to_arabic_leading( int $value ): string {
// Add a leading 0 if number lower then 10.
if ( $value < 10 ) {
return '0' . $value;
}
return $value;
}
/**
* Converts an integer to a Roman numeral.
*
* @param int $value Value to be converted.
* @param bool $upper_case Whether to convert the value to upper-case.
*
* @since 1.0-gamma
*/
private static function to_roman( int $value, bool $upper_case ): string {
// Table containing all necessary roman letters.
$roman_numerals = array(
'M' => 1000,
'CM' => 900,
'D' => 500,
'CD' => 400,
'C' => 100,
'XC' => 90,
'L' => 50,
'XL' => 40,
'X' => 10,
'IX' => 9,
'V' => 5,
'IV' => 4,
'I' => 1,
);
// Return value.
$return = '';
// Iterate through integer value until it is reduced to 0.
while ( $value > 0 ) {
foreach ( $roman_numerals as $roman => $arabic ) {
if ( $value >= $arabic ) {
$value -= $arabic;
$return .= $roman;
break;
}
}
}
// Return roman letters as string.
if ( $upper_case ) {
return strtoupper( $return );
}
return strtolower( $return );
}
/**
* Converts a string depending on its value to a boolean.
*
@ -230,5 +134,98 @@ class Convert {
}
echo '<br/>';
}
/**
* Converts an integer into Latin ASCII characters, either lower or upper-case.
*
* This function works from values AZZ (meaning there is a limit of 676
* gootnotes per Page).
*
* @param int $value Value to be converted.
* @param bool $upper_case Whether to convert the value to upper-case.
*
* @since 1.0-gamma
* @todo Replace with built-in char casting.
*/
private static function to_latin( int $value, bool $upper_case ): string {
// Output string.
$return = '';
$offset = 0;
// Check if the value is higher then 26 = Z.
while ( $value > 26 ) {
// Increase offset and reduce counter.
$offset++;
$value -= 26;
}
// If offset set (more then Z), then add a new letter in front.
if ( $offset > 0 ) {
$return = chr( $offset + 64 );
}
// Add the origin letter.
$return .= chr( $value + 64 );
// Return the latin character representing the integer.
if ( $upper_case ) {
return strtoupper( $return );
}
return strtolower( $return );
}
/**
* Converts an integer to a leading-0 integer.
*
* @param int $value Value to be converted.
* @return string Value with a leading zero.
*
* @since 1.0-gamma
* @todo Replace with built-in string formatting.
*/
private static function to_arabic_leading( int $value ): string {
// Add a leading 0 if number lower then 10.
if ( $value < 10 ) {
return '0' . $value;
}
return $value;
}
/**
* Converts an integer to a Roman numeral.
*
* @param int $value Value to be converted.
* @param bool $upper_case Whether to convert the value to upper-case.
*
* @since 1.0-gamma
*/
private static function to_roman( int $value, bool $upper_case ): string {
// Table containing all necessary roman letters.
$roman_numerals = array(
'M' => 1000,
'CM' => 900,
'D' => 500,
'CD' => 400,
'C' => 100,
'XC' => 90,
'L' => 50,
'XL' => 40,
'X' => 10,
'IX' => 9,
'V' => 5,
'IV' => 4,
'I' => 1,
);
// Return value.
$return = '';
// Iterate through integer value until it is reduced to 0.
while ( $value > 0 ) {
foreach ( $roman_numerals as $roman => $arabic ) {
if ( $value >= $arabic ) {
$value -= $arabic;
$return .= $roman;
break;
}
}
}
// Return roman letters as string.
if ( $upper_case ) {
return strtoupper( $return );
}
return strtolower( $return );
}
// phpcs:enable WordPress.PHP.DevelopmentFunctions.error_log_var_dump, WordPress.PHP.DevelopmentFunctions.error_log_print_r
}

View file

@ -97,6 +97,44 @@ class Core {
$this->define_public_hooks();
}
/**
* Runs the loader to execute all of the hooks with WordPress.
*
* @since 1.5.0
*
* @return void
*/
public function run() {
$this->loader->run();
}
/**
* Gets the name of the plugin used to uniquely identify it within the
* context of WordPress and to define internationalization functionality.
*
* @since 2.8.0
*/
public function get_plugin_name(): string {
return $this->plugin_name;
}
/**
* Returns a reference to the class that orchestrates the hooks with the plugin.
*
* @since 2.8.0
*/
public function get_loader(): Loader {
return $this->loader;
}
/**
* Gets the version number of the plugin.
*
* @since 2.8.0
*/
public function get_version(): string {
return $this->version;
}
/**
* Load the required dependencies for this plugin.
*
@ -154,7 +192,6 @@ class Core {
$this->loader = new Loader();
}
/**
* Define the locale for this plugin for internationalization.
*
@ -173,7 +210,6 @@ class Core {
$this->loader->add_action( 'plugins_loaded', $i18n, 'load_plugin_textdomain' );
}
/**
* Register all of the hooks related to the admin area functionality of the
* plugin.
@ -205,7 +241,6 @@ class Core {
$this->loader->add_action( 'wp_ajax_footnotes_getTags', $admin->wysiwyg, 'ajax_callback' );
// phpcs:enable
}
/**
* Register all of the hooks related to the public-facing functionality of
* the plugin.
@ -224,43 +259,4 @@ class Core {
$this->loader->add_action( 'widgets_init', $general, 'register_widgets' );
}
/**
* Runs the loader to execute all of the hooks with WordPress.
*
* @since 1.5.0
*
* @return void
*/
public function run() {
$this->loader->run();
}
/**
* Gets the name of the plugin used to uniquely identify it within the
* context of WordPress and to define internationalization functionality.
*
* @since 2.8.0
*/
public function get_plugin_name(): string {
return $this->plugin_name;
}
/**
* Returns a reference to the class that orchestrates the hooks with the plugin.
*
* @since 2.8.0
*/
public function get_loader(): Loader {
return $this->loader;
}
/**
* Gets the version number of the plugin.
*
* @since 2.8.0
*/
public function get_version(): string {
return $this->version;
}
}

View file

@ -91,6 +91,25 @@ class Loader {
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
}
/**
* Registers the filters and actions with WordPress.
*
* @since 2.8.0
* @see Loader::add() For more information on the hook array format.
*
* @return void
*/
public function run() {
foreach ( $this->filters as $filter ) {
add_filter( $filter['hook'], array( $filter['component'], $filter['callback'] ), $filter['priority'], $filter['accepted_args'] );
}
foreach ( $this->actions as $action ) {
add_action( $action['hook'], array( $action['component'], $action['callback'] ), $action['priority'], $action['accepted_args'] );
}
}
/**
* A utility function that is used to register the actions and hooks into a single
* collection.
@ -127,24 +146,4 @@ class Loader {
}
/**
* Registers the filters and actions with WordPress.
*
* @since 2.8.0
* @see Loader::add() For more information on the hook array format.
*
* @return void
*/
public function run() {
foreach ( $this->filters as $filter ) {
add_filter( $filter['hook'], array( $filter['component'], $filter['callback'] ), $filter['priority'], $filter['accepted_args'] );
}
foreach ( $this->actions as $action ) {
add_action( $action['hook'], array( $action['component'], $action['callback'] ), $action['priority'], $action['accepted_args'] );
}
}
}

View file

@ -1103,16 +1103,6 @@ class Settings {
*/
const FOOTNOTE_SECTION_SHORTCODE = 'footnotes_inputfield_section_shortcode';
/**********************************************************************
* SETTINGS STORAGE.
**********************************************************************/
/**
* Stores a singleton reference of this class.
*
* @since 1.5.0
*/
private static ?\footnotes\includes\Settings $instance = null;
/**
* Contains all Settings Container names.
*
@ -1330,6 +1320,15 @@ class Settings {
* @todo Create `PreferencesSet` class.
*/
private array $settings = array();
/**********************************************************************
* SETTINGS STORAGE.
**********************************************************************/
/**
* Stores a singleton reference of this class.
*
* @since 1.5.0
*/
private static ?\footnotes\includes\Settings $instance = null;
/**
* Loads all Settings from each WordPress Settings Container.
@ -1340,21 +1339,6 @@ class Settings {
$this->load_all();
}
/**
* 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;
}
/**
* Returns the name of a specified Settings Container.
*
@ -1379,51 +1363,6 @@ class Settings {
return $this->default[ $this->container[ $index ] ];
}
/**
* Loads all Settings from each Settings container.
*
* @since 1.5.0
*/
private function load_all(): void {
// Clear current settings.
$this->settings = array();
$num_settings = count( $this->container );
for ( $i = 0; $i < $num_settings; $i++ ) {
// Load settings.
$this->settings = array_merge( $this->settings, $this->load( $i ) );
}
}
/**
* Loads all settings from specified Settings Containers.
*
* @param int $index Settings container index.
* @return (string|int)[] Loaded settings (or defaults if specified container is empty).
*
* @since 1.5.0
*/
private function load( int $index ): array {
// Load all settings from container.
$options = get_option( $this->get_container( $index ) );
// Load all default settings.
$default = $this->default[ $this->get_container( $index ) ];
// No settings found, set them to their default value.
if ( empty( $options ) ) {
return $default;
}
// Iterate through all available settings ( = default values).
foreach ( $default as $key => $value ) {
// Available setting not found in the container.
if ( ! array_key_exists( $key, $options ) ) {
// Define the setting with its default value.
$options[ $key ] = $value;
}
}
// Return settings loaded from Container.
return $options;
}
/**
* Updates a whole Setting Container on save.
*
@ -1467,4 +1406,61 @@ class Settings {
register_setting( $this->get_container( $i ), $this->get_container( $i ) );
}
}
/**
* 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 Settings container.
*
* @since 1.5.0
*/
private function load_all(): void {
// Clear current settings.
$this->settings = array();
$num_settings = count( $this->container );
for ( $i = 0; $i < $num_settings; $i++ ) {
// Load settings.
$this->settings = array_merge( $this->settings, $this->load( $i ) );
}
}
/**
* Loads all settings from specified Settings Containers.
*
* @param int $index Settings container index.
* @return (string|int)[] Loaded settings (or defaults if specified container is empty).
*
* @since 1.5.0
*/
private function load( int $index ): array {
// Load all settings from container.
$options = get_option( $this->get_container( $index ) );
// Load all default settings.
$default = $this->default[ $this->get_container( $index ) ];
// No settings found, set them to their default value.
if ( empty( $options ) ) {
return $default;
}
// Iterate through all available settings ( = default values).
foreach ( $default as $key => $value ) {
// Available setting not found in the container.
if ( ! array_key_exists( $key, $options ) ) {
// Define the setting with its default value.
$options[ $key ] = $value;
}
}
// Return settings loaded from Container.
return $options;
}
}

View file

@ -46,6 +46,12 @@ class Template {
* @var string
*/
const PUBLIC = 'public/partials';
/**
* Plugin Directory
*
* @since 2.4.0d3
*/
public string $plugin_directory;
/**
* Contains the content of the template after initialize.
@ -61,13 +67,6 @@ class Template {
*/
private string $replaced_content = '';
/**
* Plugin Directory
*
* @since 2.4.0d3
*/
public string $plugin_directory;
/**
* Class Constructor. Reads and loads the template file without replace any placeholder.
*