refactor: upgrade to PHP 7.4

This commit is contained in:
Ben Goldsworthy 2021-05-02 19:55:38 +01:00
parent 70c2954122
commit 4afbb94003
7 changed files with 45 additions and 101 deletions

View file

@ -49,7 +49,7 @@ abstract class Engine {
* *
* @since 1.5.0 * @since 1.5.0
*/ */
protected ?string $a_str_sub_page_hook; protected ?string $a_str_sub_page_hook = null;
/** /**
* Stores all Sections for the child sub-page. * Stores all Sections for the child sub-page.
@ -197,9 +197,7 @@ abstract class Engine {
$this->get_sub_page_title(), $this->get_sub_page_title(),
'manage_options', 'manage_options',
Init::C_STR_MAIN_MENU_SLUG . $this->get_sub_page_slug(), Init::C_STR_MAIN_MENU_SLUG . $this->get_sub_page_slug(),
function () { fn() => $this->display_content()
return $this->display_content();
}
); );
} }
@ -215,9 +213,7 @@ abstract class Engine {
add_settings_section( add_settings_section(
$l_arr_section['id'], $l_arr_section['id'],
'', '',
function () { fn() => $this->description(),
return $this->description();
},
$l_arr_section['id'] $l_arr_section['id']
); );
$this->register_meta_boxes( $l_arr_section['id'] ); $this->register_meta_boxes( $l_arr_section['id'] );

View file

@ -73,28 +73,20 @@ class Init {
// Register hooks/actions. // Register hooks/actions.
add_action( add_action(
'admin_menu', 'admin_menu',
function () { fn() => $this->register_options_submenu()
return $this->register_options_submenu();
}
); );
add_action( add_action(
'admin_init', 'admin_init',
function () { fn() => $this->initialize_settings()
return $this->initialize_settings();
}
); );
// Register AJAX callbacks for Plugin information. // Register AJAX callbacks for Plugin information.
add_action( add_action(
'wp_ajax_nopriv_footnotes_get_plugin_info', 'wp_ajax_nopriv_footnotes_get_plugin_info',
function () { fn() => $this->get_plugin_meta_information()
return $this->get_plugin_meta_information();
}
); );
add_action( add_action(
'wp_ajax_footnotes_get_plugin_info', 'wp_ajax_footnotes_get_plugin_info',
function () { fn() => $this->get_plugin_meta_information()
return $this->get_plugin_meta_information();
}
); );
} }
@ -151,9 +143,7 @@ class Init {
\footnotes\includes\Config::C_STR_PLUGIN_PUBLIC_NAME, \footnotes\includes\Config::C_STR_PLUGIN_PUBLIC_NAME,
'manage_options', 'manage_options',
self::C_STR_MAIN_MENU_SLUG, self::C_STR_MAIN_MENU_SLUG,
function () { fn() => $this->settings_page->display_content()
return $this->settings_page->display_content();
}
); );
$this->settings_page->register_sub_page(); $this->settings_page->register_sub_page();
} }

View file

@ -54,7 +54,7 @@ class Core {
* *
* @var Loader $loader Maintains and registers all hooks for the plugin. * @var Loader $loader Maintains and registers all hooks for the plugin.
*/ */
protected $loader; protected ?\footnotes\includes\Loader $loader = null;
/** /**
* The unique identifier of this plugin * The unique identifier of this plugin
@ -63,7 +63,7 @@ class Core {
* *
* @var string $plugin_name The string used to uniquely identify this plugin. * @var string $plugin_name The string used to uniquely identify this plugin.
*/ */
protected $plugin_name; protected string $plugin_name;
/** /**
* The current version of the plugin. * The current version of the plugin.
@ -73,7 +73,7 @@ class Core {
* *
* @var string $version The current version of the plugin. * @var string $version The current version of the plugin.
*/ */
protected $version; protected string $version;
/** /**
* Builds the core of the plugin. * Builds the core of the plugin.

View file

@ -31,7 +31,7 @@ class Loader {
* *
* @var (string|int|object)[][] $actions The actions registered with WordPress to fire when the plugin loads. * @var (string|int|object)[][] $actions The actions registered with WordPress to fire when the plugin loads.
*/ */
protected $actions; protected array $actions;
/** /**
* The array of filters registered with WordPress. * The array of filters registered with WordPress.
@ -41,7 +41,7 @@ class Loader {
* *
* @var (string|int|object)[][] $filters The filters registered with WordPress to fire when the plugin loads. * @var (string|int|object)[][] $filters The filters registered with WordPress to fire when the plugin loads.
*/ */
protected $filters; protected array $filters;
/** /**
* Initialize the collections used to maintain the actions and filters. * Initialize the collections used to maintain the actions and filters.

View file

@ -1106,15 +1106,13 @@ class Settings {
/********************************************************************** /**********************************************************************
* SETTINGS STORAGE. * SETTINGS STORAGE.
**********************************************************************/ **********************************************************************/
/** /**
* Stores a singleton reference of this class. * Stores a singleton reference of this class.
* *
* @var Settings
* *
* @since 1.5.0 * @since 1.5.0
*/ */
private static $a_obj_instance; private static ?\footnotes\includes\Settings $a_obj_instance = null;
/** /**
* Contains all Settings Container names. * Contains all Settings Container names.

View file

@ -51,28 +51,22 @@ class Template {
* Contains the content of the template after initialize. * Contains the content of the template after initialize.
* *
* @since 1.5.0 * @since 1.5.0
*
* @var string
*/ */
private $a_str_original_content = ''; private ?string $a_str_original_content = '';
/** /**
* Contains the content of the template after initialize with replaced place holders. * Contains the content of the template after initialize with replaced place holders.
* *
* @since 1.5.0 * @since 1.5.0
*
* @var string
*/ */
private $a_str_replaced_content = ''; private string $a_str_replaced_content = '';
/** /**
* Plugin Directory * Plugin Directory
* *
* @since 2.4.0d3 * @since 2.4.0d3
*
* @var string
*/ */
public $plugin_directory; public string $plugin_directory;
/** /**
* Class Constructor. Reads and loads the template file without replace any placeholder. * Class Constructor. Reads and loads the template file without replace any placeholder.

View file

@ -30,23 +30,21 @@ class Parser {
* @since 1.5.0 * @since 1.5.0
* @var string[] * @var string[]
*/ */
public static $a_arr_footnotes = array(); public static array $a_arr_footnotes = array();
/** /**
* Flag if the display of 'LOVE FOOTNOTES' is allowed on the current public page. * Flag if the display of 'LOVE FOOTNOTES' is allowed on the current public page.
* *
* @since 1.5.0 * @since 1.5.0
* @var bool
*/ */
public static $a_bool_allow_love_me = true; public static bool $a_bool_allow_love_me = true;
/** /**
* Prefix for the Footnote html element ID. * Prefix for the Footnote html element ID.
* *
* @since 1.5.8 * @since 1.5.8
* @var string
*/ */
public static $a_str_prefix = ''; public static string $a_str_prefix = '';
/** /**
* Autoload a.k.a. infinite scroll, or archive view. * Autoload a.k.a. infinite scroll, or archive view.
@ -55,9 +53,8 @@ class Parser {
* post ID to make everything unique wrt infinite scroll and archive view. * post ID to make everything unique wrt infinite scroll and archive view.
* *
* @since 2.0.6 * @since 2.0.6
* @var int
*/ */
public static $a_int_post_id = 0; public static int $a_int_post_id = 0;
/** /**
* Multiple reference containers in content and widgets. * Multiple reference containers in content and widgets.
@ -69,7 +66,7 @@ class Parser {
* @since 2.2.9 * @since 2.2.9
* @var int Incremented every time after a reference container is inserted. * @var int Incremented every time after a reference container is inserted.
*/ */
public static $a_int_reference_container_id = 1; public static int $a_int_reference_container_id = 1;
/** /**
* Hard links for AMP compatibility. * Hard links for AMP compatibility.
@ -77,9 +74,8 @@ class Parser {
* A property because used both in {@see search()} and {@see reference_container()}. * A property because used both in {@see search()} and {@see reference_container()}.
* *
* @since 2.0.0 * @since 2.0.0
* @var bool
*/ */
public static $a_bool_hard_links_enabled = false; public static bool $a_bool_hard_links_enabled = false;
/** /**
* The referrer slug. * The referrer slug.
@ -124,9 +120,8 @@ class Parser {
* Hence it needs to be loaded twice, because priority levels may not match. * Hence it needs to be loaded twice, because priority levels may not match.
* *
* @since 2.1.4 * @since 2.1.4
* @var int
*/ */
public static $a_int_scroll_offset = 34; public static int $a_int_scroll_offset = 34;
/* /*
* Optional link element for footnote referrers and backlinks * Optional link element for footnote referrers and backlinks
@ -146,33 +141,29 @@ class Parser {
* Yet styling these elements with the link color is not universally preferred, so that * Yet styling these elements with the link color is not universally preferred, so that
* the very presence of these link elements may need to be avoided. * the very presence of these link elements may need to be avoided.
*/ */
/** /**
* The span element name. * The span element name.
* *
* @since 2.3.0 * @since 2.3.0
* @todo Remove. * @todo Remove.
* @var string
*/ */
public static $a_str_link_span = 'span'; public static string $a_str_link_span = 'span';
/** /**
* The opening tag. * The opening tag.
* *
* @since 2.3.0 * @since 2.3.0
* @todo Remove. * @todo Remove.
* @var string
*/ */
public static $a_str_link_open_tag = ''; public static string $a_str_link_open_tag = '';
/** /**
* The closing tag. * The closing tag.
* *
* @since 2.3.0 * @since 2.3.0
* @todo Remove. * @todo Remove.
* @var string
*/ */
public static $a_str_link_close_tag = ''; public static string $a_str_link_close_tag = '';
/* /*
* Dedicated tooltip text. * Dedicated tooltip text.
@ -195,53 +186,47 @@ class Parser {
* The tooltip delimiter shortcode length. * The tooltip delimiter shortcode length.
* *
* @since 2.5.2 * @since 2.5.2
* @var int
*/ */
public static $a_int_tooltip_shortcode_length = 12; public static int $a_int_tooltip_shortcode_length = 12;
/** /**
* Whether to mirror the tooltip text in the reference container. * Whether to mirror the tooltip text in the reference container.
* *
* @since 2.5.2 * @since 2.5.2
* @var bool
*/ */
public static $a_bool_mirror_tooltip_text = false; public static bool $a_bool_mirror_tooltip_text = false;
/** /**
* Footnote delimiter start short code. * Footnote delimiter start short code.
* *
* @since 1.5.0 * @since 1.5.0
* @since 2.6.2 Move from constant to class property. * @since 2.6.2 Move from constant to class property.
* @var string
*/ */
public static $a_str_start_tag = ''; public static string|int $a_str_start_tag = '';
/** /**
* Footnote delimiter end short code. * Footnote delimiter end short code.
* *
* @since 1.5.0 * @since 1.5.0
* @since 2.6.2 Move from constant to class property. * @since 2.6.2 Move from constant to class property.
* @var string
*/ */
public static $a_str_end_tag = ''; public static string|int $a_str_end_tag = '';
/** /**
* Footnote delimiter start short code in RegEx format. * Footnote delimiter start short code in RegEx format.
* *
* @since 2.4.0 * @since 2.4.0
* @since 2.6.2 Move from global constant to class property. * @since 2.6.2 Move from global constant to class property.
* @var string
*/ */
public static $a_str_start_tag_regex = ''; public static ?string $a_str_start_tag_regex = '';
/** /**
* Footnote delimiter end short code in RegEx format. * Footnote delimiter end short code in RegEx format.
* *
* @since 2.4.0 * @since 2.4.0
* @since 2.6.2 Move from global constant to class property. * @since 2.6.2 Move from global constant to class property.
* @var string
*/ */
public static $a_str_end_tag_regex = ''; public static ?string $a_str_end_tag_regex = '';
/** /**
* Footnote delimiter syntax validation enabled. * Footnote delimiter syntax validation enabled.
@ -255,9 +240,8 @@ class Parser {
* released in urgency to provide AMP compat before 2021. * released in urgency to provide AMP compat before 2021.
* *
* @since 2.4.0 * @since 2.4.0
* @var bool
*/ */
public static $a_bool_syntax_error_flag = true; public static bool $a_bool_syntax_error_flag = true;
/** /**
* Initialize the class and set its properties. * Initialize the class and set its properties.
@ -304,27 +288,21 @@ class Parser {
// Append custom css to the header. // Append custom css to the header.
add_filter( add_filter(
'wp_head', 'wp_head',
function () { fn() => $this->footnotes_output_head(),
return $this->footnotes_output_head();
},
PHP_INT_MAX PHP_INT_MAX
); );
// Append the love and share me slug to the footer. // Append the love and share me slug to the footer.
add_filter( add_filter(
'wp_footer', 'wp_footer',
function () { fn() => $this->footnotes_output_footer(),
return $this->footnotes_output_footer();
},
PHP_INT_MAX PHP_INT_MAX
); );
if ( Includes\Convert::to_bool( Includes\Settings::instance()->get( \footnotes\includes\Settings::C_STR_EXPERT_LOOKUP_THE_TITLE ) ) ) { if ( Includes\Convert::to_bool( Includes\Settings::instance()->get( \footnotes\includes\Settings::C_STR_EXPERT_LOOKUP_THE_TITLE ) ) ) {
add_filter( add_filter(
'the_title', 'the_title',
function ( string $p_str_content ) : string { fn(string $p_str_content): string => $this->footnotes_in_title( $p_str_content ),
return $this->footnotes_in_title( $p_str_content );
},
$l_int_the_title_priority $l_int_the_title_priority
); );
} }
@ -333,9 +311,7 @@ class Parser {
if ( Includes\Convert::to_bool( Includes\Settings::instance()->get( \footnotes\includes\Settings::C_STR_EXPERT_LOOKUP_THE_CONTENT ) ) ) { if ( Includes\Convert::to_bool( Includes\Settings::instance()->get( \footnotes\includes\Settings::C_STR_EXPERT_LOOKUP_THE_CONTENT ) ) ) {
add_filter( add_filter(
'the_content', 'the_content',
function ( string $p_str_content ) : string { fn(string $p_str_content): string => $this->footnotes_in_content( $p_str_content ),
return $this->footnotes_in_content( $p_str_content );
},
$l_int_the_content_priority $l_int_the_content_priority
); );
@ -353,9 +329,7 @@ class Parser {
*/ */
add_filter( add_filter(
'term_description', 'term_description',
function ( string $p_str_content ) : string { fn(string $p_str_content): string => $this->footnotes_in_content( $p_str_content ),
return $this->footnotes_in_content( $p_str_content );
},
$l_int_the_content_priority $l_int_the_content_priority
); );
@ -371,9 +345,7 @@ class Parser {
*/ */
add_filter( add_filter(
'pum_popup_content', 'pum_popup_content',
function ( string $p_str_content ) : string { fn(string $p_str_content): string => $this->footnotes_in_content( $p_str_content ),
return $this->footnotes_in_content( $p_str_content );
},
$l_int_the_content_priority $l_int_the_content_priority
); );
} }
@ -389,9 +361,7 @@ class Parser {
*/ */
add_filter( add_filter(
'the_excerpt', 'the_excerpt',
function ( string $p_str_excerpt ) : string { fn(string $p_str_excerpt): string => $this->footnotes_in_excerpt( $p_str_excerpt ),
return $this->footnotes_in_excerpt( $p_str_excerpt );
},
$l_int_the_excerpt_priority $l_int_the_excerpt_priority
); );
} }
@ -402,9 +372,7 @@ class Parser {
*/ */
add_filter( add_filter(
'widget_title', 'widget_title',
function ( string $p_str_content ) : string { fn(string $p_str_content): string => $this->footnotes_in_widget_title( $p_str_content ),
return $this->footnotes_in_widget_title( $p_str_content );
},
$l_int_widget_title_priority $l_int_widget_title_priority
); );
} }
@ -415,9 +383,7 @@ class Parser {
*/ */
add_filter( add_filter(
'widget_text', 'widget_text',
function ( string $p_str_content ) : string { fn(string $p_str_content): string => $this->footnotes_in_widget_text( $p_str_content ),
return $this->footnotes_in_widget_text( $p_str_content );
},
$l_int_widget_text_priority $l_int_widget_text_priority
); );
} }
@ -968,7 +934,7 @@ class Parser {
); );
// Prevent the footnotes from altering the excerpt: previously hard-coded '5ED84D6'. // Prevent the footnotes from altering the excerpt: previously hard-coded '5ED84D6'.
$l_int_placeholder = '@' . wp_rand( 100000000, 2147483647 ) . '@'; $l_int_placeholder = '@' . wp_rand( 100_000_000, 2_147_483_647 ) . '@';
$p_str_content = preg_replace( $p_str_content = preg_replace(
'#' . self::$a_str_start_tag_regex . '.+?' . self::$a_str_end_tag_regex . '#', '#' . self::$a_str_start_tag_regex . '.+?' . self::$a_str_end_tag_regex . '#',
$l_int_placeholder, $l_int_placeholder,
@ -1305,7 +1271,7 @@ class Parser {
} }
// Post ID to make everything unique wrt infinite scroll and archive view. // Post ID to make everything unique wrt infinite scroll and archive view.
self::$a_int_post_id = get_the_id(); self::$a_int_post_id = (int) get_the_id();
/* /*
* Empties the footnotes list every time Footnotes is run when the_content hook is called. * Empties the footnotes list every time Footnotes is run when the_content hook is called.