Merge pull request #170 from markcheret/type-decs

Add type declarations, increase minimum supported PHP version and add Rector dep
This commit is contained in:
Ben Goldsworthy 2021-05-02 19:41:40 +01:00 committed by GitHub
commit 6f6b643e25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 3082 additions and 3473 deletions

View file

@ -1,5 +1,7 @@
#!/bin/bash
# TODO: Add transpilation to PHP 7.4
echo "Building Plugin..."
# Moves everything including the style sheets over to `dist/`
@ -33,8 +35,8 @@ rm -r dist/*/{js,css}/*[^\.min].{js,css}
echo "Minification complete."
if [[ $1 == "-v" ]]; then
rm -rf ../VVV/www/wordpress-one/public_html/wp-content/plugins/footnotes
mv dist footnotes && mv footnotes ../VVV/www/wordpress-one/public_html/wp-content/plugins
rm -rf ../VVV/www/wordpress-two/public_html/wp-content/plugins/footnotes
mv dist footnotes && mv footnotes ../VVV/www/wordpress-two/public_html/wp-content/plugins
fi
echo "Build complete."

11
_tools/deploy-dev.sh Executable file
View file

@ -0,0 +1,11 @@
#!/bin/bash
if [[ $1 == "-v" ]]; then
echo "Deploying to VVV site #1"
rm -rf ../VVV/www/wordpress-one/public_html/wp-content/plugins/footnotes
cp -r src footnotes && mv footnotes ../VVV/www/wordpress-one/public_html/wp-content/plugins
#rm -rf ./footnotes
fi
echo "Deploy complete."
exit 0

View file

@ -6,11 +6,13 @@
"cm": "npm run cz",
"release": "./_tools/release.sh",
"release:commit": "composer run release -- -c",
"deploy": "composer run build -- -v",
"deploy:dev": "./_tools/deploy-dev.sh -v",
"build": "./_tools/build.sh",
"lint": "composer run lint:php; npm run lint",
"lint:fix": "composer run lint:php:fix; npm run lint:fix",
"lint:php": "./vendor/bin/phpcs --standard=WordPress,PHPCompatibilityWP --runtime-set testVersion 7.0- --colors --encoding=utf-8 -p --ignore=index.php ./src/*.php ./src/*/*.php ./src/*/*/*.php",
"lint:php:fix": "./vendor/bin/phpcbf --standard=WordPress,PHPCompatibilityWP --runtime-set testVersion 7.0- --colors --encoding=utf-8 -p --ignore=index.php ./src/*.php ./src/*/*.php ./src/*/*/*.php",
"lint:php": "./vendor/bin/phpcs --standard=WordPress,PHPCompatibilityWP --runtime-set testVersion 7.4- --colors --encoding=utf-8 -p --ignore=index.php ./src/*.php ./src/*/*.php ./src/*/*/*.php",
"lint:php:fix": "./vendor/bin/phpcbf --standard=WordPress,PHPCompatibilityWP --runtime-set testVersion 7.4- --colors --encoding=utf-8 -p --ignore=index.php ./src/*.php ./src/*/*.php ./src/*/*/*.php",
"lint:css": "npm run lint:css",
"lint:css:fix": "npm run lint:css:fix",
"lint:js": "npm run lint:js",
@ -28,9 +30,9 @@
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
"phpcompatibility/php-compatibility": "*",
"wp-coding-standards/wpcs": "^2.3",
"phpdocumentor/phpdocumentor": "^3.0",
"marcocesarato/php-conventional-changelog": "^1.9",
"phpcompatibility/phpcompatibility-wp": "*"
"phpcompatibility/phpcompatibility-wp": "*",
"rector/rector": "^0.10.16"
},
"prefer-stable": true
}

4896
composer.lock generated

File diff suppressed because it is too large Load diff

31
rector.php Normal file
View file

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\SetList;
use Rector\Set\ValueObject\DowngradeSetList;
use Rector\Core\ValueObject\PhpVersion;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
// get parameters
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PATHS, [
__DIR__ . '/src',
]);
// Define what rule sets will be applied
$parameters->set(Option::SETS, [
SetList::CODE_QUALITY,
SetList::DEAD_CODE,
SetList::TYPE_DECLARATION,
// DowngradeSetList::PHP_80,
// DowngradeSetList::PHP_74,
// DowngradeSetList::PHP_73,
//DowngradeSetList::PHP_72,
]);
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_71);
};

View file

@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
Tags: footnote, footnotes, bibliography, formatting, notes, Post, posts, reference, referencing
Requires at least: 3.9
Tested up to: 5.7.1
Requires PHP: 7.0
Requires PHP: 7.4
Stable Tag: 2.7.3
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html

View file

@ -11,6 +11,8 @@
* @since 2.8.0
*/
declare(strict_types=1);
namespace footnotes\admin;
use footnotes\includes as Includes;
@ -34,7 +36,7 @@ class Admin {
* @see Includes\Footnotes::$plugin_name
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
private string $plugin_name;
/**
* The version of this plugin.
@ -44,7 +46,7 @@ class Admin {
* @see Includes\Footnotes::$version
* @var string $version The current version of this plugin.
*/
private $version;
private string $version;
/**
* The WYSIWYG editor integration object.
@ -52,7 +54,7 @@ class Admin {
* @since 2.8.0
* @var WYSIWYG $wysiwyg The WYSIWYG editor integration object.
*/
public $wysiwyg;
public WYSIWYG $wysiwyg;
/**
* Initialize the class and set its properties.
@ -62,7 +64,7 @@ class Admin {
*
* @since 2.8.0
*/
public function __construct( $plugin_name, $version ) {
public function __construct( string $plugin_name, string $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
@ -84,7 +86,7 @@ class Admin {
*
* @since 2.8.0
*/
private function load_dependencies() {
private function load_dependencies(): void {
/**
* The class responsible for WYSIWYG editor integration.
*/
@ -105,7 +107,7 @@ class Admin {
*
* @since 2.8.0
*/
public function enqueue_styles() {
public function enqueue_styles(): void {
wp_enqueue_style(
$this->plugin_name,
@ -113,11 +115,12 @@ class Admin {
array(),
( PRODUCTION_ENV ) ? $this->version : filemtime(
plugin_dir_path(
dirname( __FILE__ )
__FILE__
) . 'css/settings.css'
),
'all'
);
}
/**
@ -125,7 +128,7 @@ class Admin {
*
* @since 2.8.0
*/
public function enqueue_scripts() {
public function enqueue_scripts(): void {
wp_enqueue_script(
$this->plugin_name,
@ -133,7 +136,7 @@ class Admin {
array(),
( PRODUCTION_ENV ) ? $this->version : filemtime(
plugin_dir_path(
dirname( __FILE__ )
__FILE__
) . 'js/wysiwyg-editor.js'
),
false

View file

@ -13,6 +13,8 @@
* move from `class/` sub-directory to `admin/`.
*/
declare(strict_types=1);
namespace footnotes\admin;
use footnotes\includes as Includes;
@ -25,29 +27,6 @@ use footnotes\includes as Includes;
*/
class WYSIWYG {
/**
* The ID of this plugin.
*
* @access private
* @var string $plugin_name The ID of this plugin.
*
* @since 2.8.0
*/
private $plugin_name;
/**
* Initialize the class and set its properties.
*
* @param string $plugin_name The name of this plugin.
*
* @since 2.8.0
*/
public function __construct( $plugin_name ) {
$this->plugin_name = $plugin_name;
}
/**
* Append a new Button to the WYSIWYG editor of Posts and Pages.
*
@ -57,8 +36,8 @@ class WYSIWYG {
* @since 1.5.0
* @todo Should this be `static`?
*/
public static function new_visual_editor_button( $p_arr_buttons ) {
array_push( $p_arr_buttons, 'footnotes' );
public static function new_visual_editor_button( array $p_arr_buttons ): array {
$p_arr_buttons[] = 'footnotes';
return $p_arr_buttons;
}
@ -67,8 +46,8 @@ class WYSIWYG {
*
* @since 1.5.0
*/
public static function new_plain_text_editor_button() {
$l_obj_template = new Includes\Template( Includes\Template::C_STR_DASHBOARD, 'editor-button' );
public static function new_plain_text_editor_button(): void {
$l_obj_template = new Includes\Template( \footnotes\includes\Template::C_STR_DASHBOARD, 'editor-button' );
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
echo $l_obj_template->get_content();
// phpcs:enable
@ -83,7 +62,7 @@ class WYSIWYG {
* @since 1.5.0
* @todo Should this be `static`?
*/
public static function include_scripts( $p_arr_plugins ) {
public static function include_scripts( array $p_arr_plugins ): array {
$p_arr_plugins['footnotes'] = plugins_url( '/../admin/js/wysiwyg-editor' . ( ( PRODUCTION_ENV ) ? '.min' : '' ) . '.js', __FILE__ );
return $p_arr_plugins;
}
@ -94,13 +73,13 @@ class WYSIWYG {
*
* @since 1.5.0
*/
public static function ajax_callback() {
public static function ajax_callback(): void {
// Get start and end tag for the footnotes short code.
$l_str_starting_tag = Includes\Settings::instance()->get( Includes\Settings::C_STR_FOOTNOTES_SHORT_CODE_START );
$l_str_ending_tag = Includes\Settings::instance()->get( Includes\Settings::C_STR_FOOTNOTES_SHORT_CODE_END );
$l_str_starting_tag = Includes\Settings::instance()->get( \footnotes\includes\Settings::C_STR_FOOTNOTES_SHORT_CODE_START );
$l_str_ending_tag = Includes\Settings::instance()->get( \footnotes\includes\Settings::C_STR_FOOTNOTES_SHORT_CODE_END );
if ( 'userdefined' === $l_str_starting_tag || 'userdefined' === $l_str_ending_tag ) {
$l_str_starting_tag = Includes\Settings::instance()->get( Includes\Settings::C_STR_FOOTNOTES_SHORT_CODE_START_USER_DEFINED );
$l_str_ending_tag = Includes\Settings::instance()->get( Includes\Settings::C_STR_FOOTNOTES_SHORT_CODE_END_USER_DEFINED );
$l_str_starting_tag = Includes\Settings::instance()->get( \footnotes\includes\Settings::C_STR_FOOTNOTES_SHORT_CODE_START_USER_DEFINED );
$l_str_ending_tag = Includes\Settings::instance()->get( \footnotes\includes\Settings::C_STR_FOOTNOTES_SHORT_CODE_END_USER_DEFINED );
}
echo wp_json_encode(
array(

View file

@ -13,6 +13,8 @@
* rename `dashboard/` sub-directory to `layout/`.
*/
declare(strict_types=1);
namespace footnotes\admin\layout;
use footnotes\includes as Includes;
@ -37,7 +39,7 @@ abstract class Engine {
*
* @since 2.8.0
*/
protected $plugin_name;
protected string $plugin_name;
/**
* Stores the Hook connection string for the child sub-page.
@ -47,7 +49,7 @@ abstract class Engine {
*
* @since 1.5.0
*/
protected $a_str_sub_page_hook = null;
protected ?string $a_str_sub_page_hook;
/**
* Stores all Sections for the child sub-page.
@ -57,7 +59,7 @@ abstract class Engine {
*
* @since 1.5.0
*/
protected $a_arr_sections = array();
protected array $a_arr_sections = array();
/**
* Returns a Priority index. Lower numbers have a higher priority.
@ -67,7 +69,7 @@ abstract class Engine {
*
* @since 1.5.0
*/
abstract public function get_priority();
abstract public function get_priority(): int;
/**
* Returns the unique slug of the child sub-page.
@ -78,7 +80,7 @@ abstract class Engine {
*
* @since 1.5.0
*/
abstract protected function get_sub_page_slug();
abstract protected function get_sub_page_slug(): string;
/**
* Returns the title of the child sub-page.
@ -89,7 +91,7 @@ abstract class Engine {
*
* @since 1.5.0
*/
abstract protected function get_sub_page_title();
abstract protected function get_sub_page_title(): string;
/**
* Returns an array of all registered sections for a sub-page.
@ -100,7 +102,7 @@ abstract class Engine {
*
* @since 1.5.0
*/
abstract protected function get_sections();
abstract protected function get_sections(): array;
/**
* Returns an array of all registered meta boxes.
@ -111,7 +113,7 @@ abstract class Engine {
*
* @since 1.5.0
*/
abstract protected function get_meta_boxes();
abstract protected function get_meta_boxes(): array;
/**
* Returns an array describing a sub-page section.
@ -121,7 +123,7 @@ abstract class Engine {
* @param string $p_str_title Title of the section.
* @param int $p_int_settings_container_index Settings Container index.
* @param bool $p_bool_has_submit_button Whether a Submit button should
* be displayed for this section. Default `true`.
* be displayed for this section. Default `true`.
* @return array {
* A dashboard section.
*
@ -134,7 +136,7 @@ abstract class Engine {
* @since 1.5.0
* @todo Refactor sections into their own class?
*/
protected function add_section( $p_str_id, $p_str_title, $p_int_settings_container_index, $p_bool_has_submit_button = true ) {
protected function add_section( string $p_str_id, string $p_str_title, int $p_int_settings_container_index, bool $p_bool_has_submit_button = true ): array {
return array(
'id' => $this->plugin_name . '-' . $p_str_id,
'title' => $p_str_title,
@ -164,7 +166,7 @@ abstract class Engine {
* @todo Refactor meta boxes into their own class?
* @todo Pass actual functions rather than strings?
*/
protected function add_meta_box( $p_str_section_id, $p_str_id, $p_str_title, $p_str_callback_function_name ) {
protected function add_meta_box( string $p_str_section_id, string $p_str_id, string $p_str_title, string $p_str_callback_function_name ): array {
return array(
'parent' => $this->plugin_name . '-' . $p_str_section_id,
'id' => $p_str_id,
@ -178,7 +180,7 @@ abstract class Engine {
*
* @since 1.5.0
*/
public function register_sub_page() {
public function register_sub_page(): void {
global $submenu;
if ( array_key_exists( plugin_basename( Init::C_STR_MAIN_MENU_SLUG ), $submenu ) ) {
@ -195,7 +197,9 @@ abstract class Engine {
$this->get_sub_page_title(),
'manage_options',
Init::C_STR_MAIN_MENU_SLUG . $this->get_sub_page_slug(),
array( $this, 'display_content' )
function () {
return $this->display_content();
}
);
}
@ -204,14 +208,16 @@ abstract class Engine {
*
* @since 1.5.0
*/
public function register_sections() {
public function register_sections(): void {
foreach ( $this->get_sections() as $l_arr_section ) {
// Append tab to the tab-array.
$this->a_arr_sections[ $l_arr_section['id'] ] = $l_arr_section;
add_settings_section(
$l_arr_section['id'],
'',
array( $this, 'Description' ),
function () {
return $this->description();
},
$l_arr_section['id']
);
$this->register_meta_boxes( $l_arr_section['id'] );
@ -226,7 +232,7 @@ abstract class Engine {
*
* @since 1.5.0
*/
private function register_meta_boxes( $p_str_parent_id ) {
private function register_meta_boxes( string $p_str_parent_id ): void {
// Iterate through each meta box.
foreach ( $this->get_meta_boxes() as $l_arr_meta_box ) {
if ( $p_str_parent_id !== $l_arr_meta_box['parent'] ) {
@ -250,7 +256,7 @@ abstract class Engine {
* @since 1.5.0
* @todo Move to {@see Includes\Admin}.
*/
private function append_scripts() {
private function append_scripts(): void {
wp_enqueue_script( 'postbox' );
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'wp-color-picker' );
@ -263,7 +269,7 @@ abstract class Engine {
* @since 1.5.0
* @todo Review nonce verification.
*/
public function display_content() {
public function display_content(): void {
$this->append_scripts();
// Get the current section.
@ -273,12 +279,10 @@ abstract class Engine {
// Store settings.
$l_bool_settings_updated = false;
if ( array_key_exists( 'save-settings', $_POST ) ) {
if ( 'save' === $_POST['save-settings'] ) {
unset( $_POST['save-settings'] );
unset( $_POST['submit'] );
$l_bool_settings_updated = $this->save_settings();
}
if ( array_key_exists( 'save-settings', $_POST ) && 'save' === $_POST['save-settings'] ) {
unset( $_POST['save-settings'] );
unset( $_POST['submit'] );
$l_bool_settings_updated = $this->save_settings();
}
// Display all sections and highlight the active section.
@ -286,7 +290,6 @@ abstract class Engine {
echo '<h2 class="nav-tab-wrapper">';
// Iterate through all register sections.
foreach ( $this->a_arr_sections as $l_str_id => $l_arr_description ) {
$l_str_tab_active = ( $l_str_id === $l_arr_active_section['id'] ) ? ' nav-tab-active' : '';
echo sprintf(
'<a class="nav-tab%s" href="?page=%s&t=%s">%s</a>',
( $l_str_id === $l_arr_active_section['id'] ) ? ' nav-tab-active' : '',
@ -336,7 +339,7 @@ abstract class Engine {
* @since 1.5.0
* @todo Review nonce verification.
*/
private function save_settings() {
private function save_settings(): bool {
$l_arr_new_settings = array();
// TODO: add nonce verification.
@ -346,13 +349,8 @@ abstract class Engine {
$l_str_active_section_id = isset( $_GET['t'] ) ? wp_unslash( $_GET['t'] ) : key( $this->a_arr_sections );
$l_arr_active_section = $this->a_arr_sections[ $l_str_active_section_id ];
foreach ( Includes\Settings::instance()->get_defaults( $l_arr_active_section['container'] ) as $l_str_key => $l_mixed_value ) {
if ( array_key_exists( $l_str_key, $_POST ) ) {
$l_arr_new_settings[ $l_str_key ] = wp_unslash( $_POST[ $l_str_key ] );
} else {
// Setting is not defined in the POST array, define it to avoid the Default value.
$l_arr_new_settings[ $l_str_key ] = '';
}
foreach ( array_keys( Includes\Settings::instance()->get_defaults( $l_arr_active_section['container'] ) ) as $l_str_key ) {
$l_arr_new_settings[ $l_str_key ] = array_key_exists( $l_str_key, $_POST ) ? wp_unslash( $_POST[ $l_str_key ] ) : '';
}
// Update settings.
return Includes\Settings::instance()->save_options( $l_arr_active_section['container'], $l_arr_new_settings );
@ -365,7 +363,7 @@ abstract class Engine {
* @since 1.5.0
* @todo Required? Should be `abstract`?
*/
public function description() {
public function description(): void {
// Default no description will be displayed.
}
@ -386,18 +384,18 @@ abstract class Engine {
* @since 2.5.11 Broken due to accidental removal of `esc_attr()` call.
* @since 2.6.1 Restore `esc_attr()` call.
*/
protected function load_setting( $p_str_setting_key_name ) {
protected function load_setting( string $p_str_setting_key_name ): array {
// Get current section.
reset( $this->a_arr_sections );
$p_arr_return = array();
$p_arr_return['id'] = sprintf( '%s', $p_str_setting_key_name );
$p_arr_return['name'] = sprintf( '%s', $p_str_setting_key_name );
$p_arr_return['id'] = $p_str_setting_key_name;
$p_arr_return['name'] = $p_str_setting_key_name;
$p_arr_return['value'] = esc_attr( Includes\Settings::instance()->get( $p_str_setting_key_name ) );
return $p_arr_return;
}
/**
* Returns a simple text inside HTML `<span>` element.
* Returns a simple text inside a 'span' element.
*
* @access protected
* @param string $p_str_text Message to be surrounded with `<span>` tags.
@ -406,12 +404,12 @@ abstract class Engine {
* @since 1.5.0
* @todo Refactor HTML generation.
*/
protected function add_text( $p_str_text ) {
protected function add_text( string $p_str_text ): string {
return sprintf( '<span>%s</span>', $p_str_text );
}
/**
* Returns the HTML tag for an `<input>`/`<select>` label.
* Returns the HTML tag for a 'label' element.
*
* @access protected
* @param string $p_str_setting_name Settings key.
@ -421,7 +419,7 @@ abstract class Engine {
* @since 1.5.0
* @todo Refactor HTML generation.
*/
protected function add_label( $p_str_setting_name, $p_str_caption ) {
protected function add_label( string $p_str_setting_name, string $p_str_caption ): string {
if ( empty( $p_str_caption ) ) {
return '';
}
@ -441,7 +439,7 @@ abstract class Engine {
}
/**
* Constructs the HTML for a text `<input>` element.
* Constructs the HTML for a text 'input' element.
*
* @access protected
* @param string $p_str_setting_name Setting key.
@ -453,7 +451,7 @@ abstract class Engine {
* @since 1.5.0
* @todo Refactor HTML generation.
*/
protected function add_text_box( $p_str_setting_name, $p_str_max_length = 999, $p_bool_readonly = false, $p_bool_hidden = false ) {
protected function add_text_box( string $p_str_setting_name, int $p_str_max_length = 999, bool $p_bool_readonly = false, bool $p_bool_hidden = false ): string {
$l_str_style = '';
// Collect data for given settings field.
$l_arr_data = $this->load_setting( $p_str_setting_name );
@ -472,7 +470,7 @@ abstract class Engine {
}
/**
* Constructs the HTML for a checkbox `<input>` element.
* Constructs the HTML for a checkbox 'input' element.
*
* @access protected
* @param string $p_str_setting_name Setting key.
@ -481,7 +479,7 @@ abstract class Engine {
* @since 1.5.0
* @todo Refactor HTML generation.
*/
protected function add_checkbox( $p_str_setting_name ) {
protected function add_checkbox( string $p_str_setting_name ): string {
// Collect data for given settings field.
$l_arr_data = $this->load_setting( $p_str_setting_name );
return sprintf(
@ -493,7 +491,7 @@ abstract class Engine {
}
/**
* Constructs the HTML for a `<select>` element.
* Constructs the HTML for a 'select' element.
*
* @access protected
* @param string $p_str_setting_name Setting key.
@ -503,7 +501,7 @@ abstract class Engine {
* @since 1.5.0
* @todo Refactor HTML generation.
*/
protected function add_select_box( $p_str_setting_name, $p_arr_options ) {
protected function add_select_box( string $p_str_setting_name, array $p_arr_options ): string {
// Collect data for given settings field.
$l_arr_data = $this->load_setting( $p_str_setting_name );
$l_str_options = '';
@ -529,7 +527,7 @@ abstract class Engine {
}
/**
* Constructs the HTML for a `<textarea>` element.
* Constructs the HTML for a 'textarea' element.
*
* @access protected
* @param string $p_str_setting_name Setting key.
@ -538,7 +536,7 @@ abstract class Engine {
* @since 1.5.0
* @todo Refactor HTML generation.
*/
protected function add_textarea( $p_str_setting_name ) {
protected function add_textarea( $p_str_setting_name ): string {
// Collect data for given settings field.
$l_arr_data = $this->load_setting( $p_str_setting_name );
return sprintf(
@ -550,7 +548,7 @@ abstract class Engine {
}
/**
* Constructs the HTML for a text `<input>` element with the colour selection
* Constructs the HTML for a text 'input' element with the colour selection
* class.
*
* @access protected
@ -561,7 +559,7 @@ abstract class Engine {
* @todo Refactor HTML generation.
* @todo Use proper colorpicker element.
*/
protected function add_color_selection( $p_str_setting_name ) {
protected function add_color_selection( string $p_str_setting_name ): string {
// Collect data for given settings field.
$l_arr_data = $this->load_setting( $p_str_setting_name );
return sprintf(
@ -573,7 +571,7 @@ abstract class Engine {
}
/**
* Constructs the HTML for numeric `<input>` element.
* Constructs the HTML for numeric 'input' element.
*
* @access protected
* @param string $p_str_setting_name Setting key.
@ -585,7 +583,7 @@ abstract class Engine {
* @since 1.5.0
* @todo Refactor HTML generation.
*/
protected function add_num_box( $p_str_setting_name, $p_in_min, $p_int_max, $p_bool_deci = false ) {
protected function add_num_box( string $p_str_setting_name, int $p_in_min, int $p_int_max, bool $p_bool_deci = false ): string {
// Collect data for given settings field.
$l_arr_data = $this->load_setting( $p_str_setting_name );

View file

@ -13,6 +13,8 @@
* rename `dashboard/` sub-directory to `layout/`.
*/
declare(strict_types=1);
namespace footnotes\admin\layout;
use footnotes\includes as Includes;
@ -33,7 +35,7 @@ class Init {
*
* @since 2.8.0
*/
private $plugin_name;
private string $plugin_name;
/**
* Slug for the Plugin main menu.
@ -51,7 +53,7 @@ class Init {
*
* @since 1.5.0
*/
private $settings_page;
private Settings $settings_page;
/**
* Initializes all WordPress hooks for the Plugin Settings.
@ -61,7 +63,7 @@ class Init {
* @since 1.5.0
* @since 2.8.0 Added `$plugin_name` parameter.
*/
public function __construct( $plugin_name ) {
public function __construct( string $plugin_name ) {
$this->plugin_name = $plugin_name;
$this->load_dependencies();
@ -69,11 +71,31 @@ class Init {
$this->settings_page = new Settings( $this->plugin_name );
// Register hooks/actions.
add_action( 'admin_menu', array( $this, 'register_options_submenu' ) );
add_action( 'admin_init', array( $this, 'initialize_settings' ) );
add_action(
'admin_menu',
function () {
return $this->register_options_submenu();
}
);
add_action(
'admin_init',
function () {
return $this->initialize_settings();
}
);
// Register AJAX callbacks for Plugin information.
add_action( 'wp_ajax_nopriv_footnotes_get_plugin_info', array( $this, 'get_plugin_meta_information' ) );
add_action( 'wp_ajax_footnotes_get_plugin_info', array( $this, 'get_plugin_meta_information' ) );
add_action(
'wp_ajax_nopriv_footnotes_get_plugin_info',
function () {
return $this->get_plugin_meta_information();
}
);
add_action(
'wp_ajax_footnotes_get_plugin_info',
function () {
return $this->get_plugin_meta_information();
}
);
}
/**
@ -89,7 +111,7 @@ class Init {
*
* @since 2.8.0
*/
private function load_dependencies() {
private function load_dependencies(): void {
/**
* Defines plugin constants.
*/
@ -111,7 +133,7 @@ class Init {
*
* @since 1.5.0
*/
public function initialize_settings() {
public function initialize_settings(): void {
Includes\Settings::instance()->register_settings();
$this->settings_page->register_sections();
}
@ -122,14 +144,16 @@ class Init {
* @since 1.5.0
* @see http://codex.wordpress.org/Function_Reference/add_menu_page
*/
public function register_options_submenu() {
public function register_options_submenu(): void {
add_submenu_page(
'options-general.php',
'footnotes Settings',
Includes\Config::C_STR_PLUGIN_PUBLIC_NAME,
\footnotes\includes\Config::C_STR_PLUGIN_PUBLIC_NAME,
'manage_options',
self::C_STR_MAIN_MENU_SLUG,
array( $this->settings_page, 'display_content' )
function () {
return $this->settings_page->display_content();
}
);
$this->settings_page->register_sub_page();
}
@ -140,8 +164,8 @@ class Init {
*
* @since 1.5.0
*/
public function get_plugin_meta_information() {
// TODO: add nonce verification.
public function get_plugin_meta_information(): void {
// TODO: add nonce verification?
// Get plugin internal name from POST data.
if ( isset( $_POST['plugin'] ) ) {
@ -173,7 +197,7 @@ class Init {
exit;
}
$l_int_num_ratings = array_key_exists( 'num_ratings', $l_arr_plugin ) ? intval( $l_arr_plugin['num_ratings'] ) : 0;
$l_int_num_ratings = array_key_exists( 'num_ratings', $l_arr_plugin ) ? (int) $l_arr_plugin['num_ratings'] : 0;
$l_int_rating = array_key_exists( 'rating', $l_arr_plugin ) ? floatval( $l_arr_plugin['rating'] ) : 0.0;
$l_int_stars = round( 5 * $l_int_rating / 100.0, 1 );

File diff suppressed because it is too large Load diff

View file

@ -25,6 +25,8 @@
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
*/
declare(strict_types=1);
namespace footnotes;
// If this file is called directly, abort.
@ -63,10 +65,8 @@ define( 'PRODUCTION_ENV', false );
*
* @since 2.8.0
* @see includes\Activator::activate()
*
* @return void
*/
function activate_footnotes() {
function activate_footnotes(): void {
/**
* Provides plugin activation functionality.
*/
@ -80,10 +80,8 @@ function activate_footnotes() {
*
* @since 2.8.0
* @see includes\Deactivator::deactivate()
*
* @return void
*/
function deactivate_footnotes() {
function deactivate_footnotes(): void {
/**
* Provides plugin deactivation functionality.
*/
@ -92,8 +90,15 @@ function deactivate_footnotes() {
includes\Deactivator::deactivate();
}
register_activation_hook( __FILE__, 'activate_footnotes' );
register_deactivation_hook( __FILE__, 'deactivate_footnotes' );
/*
* TODO: currently these throw an error:
* Uncaught TypeError: call_user_func_array(): Argument #1 ($function) must be
* a valid callback, function "deactivate_footnotes" not found or invalid
* function name in /srv/www/wordpress-one/public_html/wp-includes/class-wp-hook.php:292
*
* register_activation_hook( __FILE__, 'activate_footnotes' );
* register_deactivation_hook( __FILE__, 'deactivate_footnotes' );
*/
/**
* The core plugin class that defines internationalization, admin-specific and
@ -108,10 +113,8 @@ require_once plugin_dir_path( __FILE__ ) . 'includes/class-core.php';
* the plugin from this point in the file does not affect the page life cycle.
*
* @since 2.8.0
*
* @return void
*/
function run_footnotes() {
function run_footnotes(): void {
/**
* The plugin core.
*

View file

@ -25,6 +25,8 @@
* @since 2.8.0
*/
declare(strict_types=1);
namespace footnotes\includes;
/**

View file

@ -29,6 +29,8 @@
* @deprecated
*/
declare(strict_types=1);
namespace footnotes\includes;
/**

View file

@ -8,6 +8,8 @@
* rename `class/` sub-directory to `includes/`.
*/
declare(strict_types=1);
namespace footnotes\includes;
/**
@ -22,16 +24,16 @@ class Convert {
*
* @param int $p_int_index Index to be converted.
* @param string $p_str_convert_style Counter style to use.
* @return string Converted Index converted to the defined counter style.
* @return string The index converted to the defined counter style.
*
* @since 1.5.0
*/
public static function index( $p_int_index, $p_str_convert_style = 'arabic_plain' ) {
public static function index( int $p_int_index, string $p_str_convert_style = 'arabic_plain' ): string {
switch ( $p_str_convert_style ) {
case 'romanic':
return self::to_romanic( $p_int_index, true );
case 'roman':
return self::to_roman( $p_int_index, true );
case 'roman_low':
return self::to_romanic( $p_int_index, false );
return self::to_roman( $p_int_index, false );
case 'latin_high':
return self::to_latin( $p_int_index, true );
case 'latin_low':
@ -40,7 +42,7 @@ class Convert {
return self::to_arabic_leading( $p_int_index );
case 'arabic_plain':
default:
return $p_int_index;
return (string) $p_int_index;
}
}
@ -52,12 +54,11 @@ class Convert {
*
* @param int $p_int_value Value to be converted.
* @param bool $p_bool_upper_case Whether to convert the value to upper-case.
* @return string
*
* @since 1.0-gamma
* @todo Replace with built-in char casting.
*/
private static function to_latin( $p_int_value, $p_bool_upper_case ) {
private static function to_latin( int $p_int_value, bool $p_bool_upper_case ): string {
// Output string.
$l_str_return = '';
$l_int_offset = 0;
@ -89,7 +90,7 @@ class Convert {
* @since 1.0-gamma
* @todo Replace with built-in string formatting.
*/
private static function to_arabic_leading( $p_int_value ) {
private static function to_arabic_leading( int $p_int_value ): string {
// Add a leading 0 if number lower then 10.
if ( $p_int_value < 10 ) {
return '0' . $p_int_value;
@ -102,13 +103,12 @@ class Convert {
*
* @param int $p_int_value Value to be converted.
* @param bool $p_bool_upper_case Whether to convert the value to upper-case.
* @return string
*
* @since 1.0-gamma
*/
private static function to_romanic( $p_int_value, $p_bool_upper_case ) {
// Table containing all necessary romanic letters.
$l_arr_romanic_letters = array(
private static function to_roman( int $p_int_value, bool $p_bool_upper_case ): string {
// Table containing all necessary roman letters.
$l_arr_roman_numerals = array(
'M' => 1000,
'CM' => 900,
'D' => 500,
@ -127,15 +127,15 @@ class Convert {
$l_str_return = '';
// Iterate through integer value until it is reduced to 0.
while ( $p_int_value > 0 ) {
foreach ( $l_arr_romanic_letters as $l_str_romanic => $l_int_arabic ) {
foreach ( $l_arr_roman_numerals as $l_str_roman => $l_int_arabic ) {
if ( $p_int_value >= $l_int_arabic ) {
$p_int_value -= $l_int_arabic;
$l_str_return .= $l_str_romanic;
$l_str_return .= $l_str_roman;
break;
}
}
}
// Return romanic letters as string.
// Return roman letters as string.
if ( $p_bool_upper_case ) {
return strtoupper( $l_str_return );
}
@ -151,7 +151,7 @@ class Convert {
* @since 1.0-beta
* @todo Replace with built-in type casting.
*/
public static function to_bool( $p_str_value ) {
public static function to_bool( string $p_str_value ): bool {
// Convert string to lower-case to make it easier.
$p_str_value = strtolower( $p_str_value );
// Check if string seems to contain a "true" value.
@ -171,17 +171,18 @@ class Convert {
* Get an HTML array short code depending on Arrow-Array key index.
*
* @param int $p_int_index Index representing the arrow. If empty, all arrows are specified.
* @return array|string Array of all arrows if index is empty, otherwise HTML tag of a specific arrow.
* @return string|string[] Array of all arrows if index is empty, otherwise HTML tag of a specific arrow.
*
* @since 1.3.2
* @todo Review.
* @todo Single return type.
*/
public static function get_arrow( $p_int_index = -1 ) {
public static function get_arrow( int $p_int_index = -1 ) {
// Define all possible arrows.
$l_arr_arrows = array( '&#8593;', '&#8613;', '&#8607;', '&#8617;', '&#8626;', '&#8629;', '&#8657;', '&#8673;', '&#8679;', '&#65514;' );
// Convert index to an integer.
if ( ! is_int( $p_int_index ) ) {
$p_int_index = intval( $p_int_index );
$p_int_index = (int) $p_int_index;
}
// Return the whole arrow array.
if ( $p_int_index < 0 || $p_int_index > count( $l_arr_arrows ) ) {
@ -196,6 +197,7 @@ class Convert {
* Displays a variable.
*
* @param mixed $p_mixed_value The variable to display.
* @return void
*
* @since 1.5.0
* @todo Replace with proper logging/debug functions.

View file

@ -27,6 +27,8 @@
* Renamed parent `class/` directory to `includes/`.
*/
declare(strict_types=1);
namespace footnotes\includes;
use footnotes\general as General;
@ -86,11 +88,7 @@ class Core {
* @return void
*/
public function __construct() {
if ( defined( 'PLUGIN_VERSION' ) ) {
$this->version = PLUGIN_VERSION;
} else {
$this->version = '0.0.0';
}
$this->version = defined( 'PLUGIN_VERSION' ) ? PLUGIN_VERSION : '0.0.0';
$this->plugin_name = 'footnotes';
$this->load_dependencies();

View file

@ -6,6 +6,8 @@
* @since 2.8.0
*/
declare(strict_types=1);
namespace footnotes\includes;
/**
@ -24,6 +26,8 @@ class Deactivator {
* Currently NOP.
*
* @since 2.8.0
*
* @return void
*/
public static function deactivate() {
// Nothing yet.

View file

@ -8,6 +8,8 @@
* rename `class/` sub-directory to `includes/`.
*/
declare(strict_types=1);
namespace footnotes\includes;
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-config.php';
@ -31,6 +33,8 @@ class i18n {
*
* @since 1.5.1
* @since 2.8.0 Rename from `load()` to `load_plugin_textdomain()`. Remove unused `$p_str_language_code` parameter.
*
* @return void
*/
public function load_plugin_textdomain() {
load_plugin_textdomain(

View file

@ -7,6 +7,8 @@
* @since 2.8.0
*/
declare(strict_types=1);
namespace footnotes\includes;
/**
@ -24,20 +26,20 @@ class Loader {
/**
* The array of actions registered with WordPress.
*
* @access protected
* @var array $actions The actions registered with WordPress to fire when the plugin loads.
*
* @since 2.8.0
* @see Loader::add() For more information on the hook array format.
*
* @var (string|int|object)[][] $actions The actions registered with WordPress to fire when the plugin loads.
*/
protected $actions;
/**
* The array of filters registered with WordPress.
*
* @access protected
* @var array $filters The filters registered with WordPress to fire when the plugin loads.
*
* @since 2.8.0
* @see Loader::add() For more information on the hook array format.
*
* @var (string|int|object)[][] $filters The filters registered with WordPress to fire when the plugin loads.
*/
protected $filters;
@ -45,6 +47,8 @@ class Loader {
* Initialize the collections used to maintain the actions and filters.
*
* @since 2.8.0
*
* @return void
*/
public function __construct() {
@ -56,13 +60,15 @@ class Loader {
/**
* Add a new action to the collection to be registered with WordPress.
*
* @since 2.8.0
* @see Loader::add() For more information on the hook array format.
*
* @param string $hook The name of the WordPress action that is being registered.
* @param object $component A reference to the instance of the object on which the action is defined.
* @param string $callback The name of the function definition on the `$component`.
* @param int $priority (optional) The priority at which the function should be fired. Default is 10.
* @param int $accepted_args (optional) The number of arguments that should be passed to the $callback. Default is 1.
*
* @since 2.8.0
* @param int $priority Optional. The priority at which the function should be fired. Default is 10.
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
* @return void
*/
public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
@ -71,13 +77,15 @@ class Loader {
/**
* Add a new filter to the collection to be registered with WordPress.
*
* @since 2.8.0
* @see Loader::add() For more information on the hook array format.
*
* @param string $hook The name of the WordPress filter that is being registered.
* @param object $component A reference to the instance of the object on which the filter is defined.
* @param string $callback The name of the function definition on the `$component`.
* @param int $priority (optional) The priority at which the function should be fired. Default is 10.
* @param int $accepted_args (optional) The number of arguments that should be passed to the $callback. Default is 1.
*
* @since 2.8.0
* @param int $priority Optional. The priority at which the function should be fired. Default is 10.
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
* @return void
*/
public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
@ -87,16 +95,23 @@ class Loader {
* A utility function that is used to register the actions and hooks into a single
* collection.
*
* @access private
* @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
* @param string $hook The name of the WordPress filter that is being registered.
* @param object $component A reference to the instance of the object on which the filter is defined.
* @param string $callback The name of the function definition on the `$component`.
* @param int $priority The priority at which the function should be fired.
* @param int $accepted_args The number of arguments that should be passed to the `$callback`.
* @return array The collection of actions and filters registered with WordPress.
*
* @since 2.8.0
*
* @param (string|int|object)[][] $hooks The collection of hooks that is being registered (that is, actions or filters).
* @param string $hook The name of the WordPress filter that is being registered.
* @param object $component A reference to the instance of the object on which the filter is defined.
* @param string $callback The name of the function definition on the `$component`.
* @param int $priority The priority at which the function should be fired.
* @param int $accepted_args The number of arguments that should be passed to the `$callback`.
* @return (string|int|object)[][] {
* The registered hook(s).
*
* @type string $hook The name of the registered WordPress hook.
* @type object $component A reference to the instance of the object on which the hook is defined.
* @type string $callback The name of the function definition on the `$component`.
* @type int $priority The priority at which the function should be fired.
* @type int $accepted_args The number of arguments that should be passed to the `$callback`.
* }
*/
private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
@ -116,6 +131,9 @@ 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() {

View file

@ -8,6 +8,8 @@
* Renamed parent `class/` directory to `includes/`.
*/
declare(strict_types=1);
namespace footnotes\includes;
/**
@ -1112,7 +1114,7 @@ class Settings {
*
* @since 1.5.0
*/
private static $a_obj_instance = null;
private static $a_obj_instance;
/**
* Contains all Settings Container names.
@ -1123,7 +1125,7 @@ class Settings {
*
* @since 1.5.0
*/
private $a_arr_container = array(
private array $a_arr_container = array(
'footnotes_storage',
'footnotes_storage_custom',
'footnotes_storage_expert',
@ -1136,10 +1138,11 @@ class Settings {
* @since 1.5.0
* @todo Review. Why are the constants just initialised with these values?
* At the very least, we should stop using yes to mean `true` etc.
* @todo Create `PreferencesSet` class.
*
* @var (string|int)[]
*/
private $a_arr_default = array(
private array $a_arr_default = array(
// General settings.
'footnotes_storage' => array(
@ -1226,7 +1229,7 @@ class Settings {
'footnotes_storage_custom' => array(
// Backlink symbol.
self::C_STR_HYPERLINK_ARROW => '&#8593;',
self::C_STR_HYPERLINK_ARROW => 0,
self::C_STR_HYPERLINK_ARROW_USER_DEFINED => '',
// Referrers.
@ -1327,8 +1330,9 @@ class Settings {
* @var (string|int)[]
*
* @since 1.5.0
* @todo Create `PreferencesSet` class.
*/
private $a_arr_settings = array();
private array $a_arr_settings = array();
/**
* Loads all Settings from each WordPress Settings Container.
@ -1347,7 +1351,7 @@ class Settings {
* @since 1.5.0
* @todo Remove?
*/
public static function instance() {
public static function instance(): self {
// No instance defined yet, load it.
if ( ! self::$a_obj_instance ) {
self::$a_obj_instance = new self();
@ -1360,11 +1364,11 @@ class Settings {
* Returns the name of a specified Settings Container.
*
* @param int $p_int_index Settings Container index.
* @return str Settings Container name.
* @return string Settings Container name.
*
* @since 1.5.0
*/
public function get_container( $p_int_index ) {
public function get_container( int $p_int_index ): string {
return $this->a_arr_container[ $p_int_index ];
}
@ -1376,7 +1380,7 @@ class Settings {
*
* @since 1.5.6
*/
public function get_defaults( $p_int_index ) {
public function get_defaults( int $p_int_index ): array {
return $this->a_arr_default[ $this->a_arr_container[ $p_int_index ] ];
}
@ -1385,7 +1389,7 @@ class Settings {
*
* @since 1.5.0
*/
private function load_all() {
private function load_all(): void {
// Clear current settings.
$this->a_arr_settings = array();
$num_settings = count( $this->a_arr_container );
@ -1403,7 +1407,7 @@ class Settings {
*
* @since 1.5.0
*/
private function load( $p_int_index ) {
private function load( int $p_int_index ): array {
// Load all settings from container.
$l_arr_options = get_option( $this->get_container( $p_int_index ) );
// Load all default settings.
@ -1434,7 +1438,7 @@ class Settings {
*
* @since 1.5.0
*/
public function save_options( $p_int_index, $p_arr_new_values ) {
public function save_options( int $p_int_index, array $p_arr_new_values ): bool {
if ( update_option( $this->get_container( $p_int_index ), $p_arr_new_values ) ) {
$this->load_all();
return true;
@ -1449,9 +1453,10 @@ class Settings {
* @return string|int|null Setting value, or `null` if setting key is invalid.
*
* @since 1.5.0
* @todo Add return type.
*/
public function get( $p_str_key ) {
return array_key_exists( $p_str_key, $this->a_arr_settings ) ? $this->a_arr_settings[ $p_str_key ] : null;
public function get( string $p_str_key ) {
return $this->a_arr_settings[ $p_str_key ] ?? null;
}
/**
@ -1461,7 +1466,7 @@ class Settings {
*
* @since 1.5.0
*/
public function register_settings() {
public function register_settings(): void {
// Register all settings.
$num_settings = count( $this->a_arr_container );
for ( $i = 0; $i < $num_settings; $i++ ) {

View file

@ -11,6 +11,8 @@
* rename `class/` sub-directory to `includes/`.
*/
declare(strict_types=1);
namespace footnotes\includes;
/**
@ -30,59 +32,60 @@ class Template {
/**
* Directory name for dashboard partials.
*
* @var string
*
* @since 1.5.0
*
* @var string
*/
const C_STR_DASHBOARD = 'admin/partials';
/**
* Directory name for public partials.
*
* @var string
*
* @since 1.5.0
*
* @var string
*/
const C_STR_PUBLIC = 'public/partials';
/**
* Contains the content of the template after initialize.
*
* @var string
*
* @since 1.5.0
*
* @var string
*/
private $a_str_original_content = '';
/**
* Contains the content of the template after initialize with replaced place holders.
*
* @var string
*
* @since 1.5.0
*
* @var string
*/
private $a_str_replaced_content = '';
/**
* Plugin Directory
*
* @var string
*
* @since 2.4.0d3
*
* @var string
*/
public $plugin_directory;
/**
* Class Constructor. Reads and loads the template file without replace any placeholder.
*
* @since 1.5.0
* @todo Refactor templating.
*
* @param string $p_str_file_type Template file type.
* @param string $p_str_file_name Template file name inside the `partials/` directory, without the file extension.
* @param string $p_str_extension (optional) Template file extension (default: 'html').
*
* @since 1.5.0
* @todo Refactor templating.
* @return void
*/
public function __construct( $p_str_file_type, $p_str_file_name, $p_str_extension = 'html' ) {
public function __construct( string $p_str_file_type, string $p_str_file_name, string $p_str_extension = 'html' ) {
// No template file type and/or file name set.
if ( empty( $p_str_file_type ) || empty( $p_str_file_name ) ) {
return;
@ -102,13 +105,13 @@ class Template {
/**
* Replace all placeholders specified in array.
*
* @param array $p_arr_placeholders Placeholders (key = placeholder, value = value).
* @return bool `true` on Success, `false` if placeholders invalid.
*
* @since 1.5.0
* @todo Refactor templating.
*
* @param string[] $p_arr_placeholders Placeholders (key = placeholder, value = value).
* @return bool `true` on Success, `false` if placeholders invalid.
*/
public function replace( $p_arr_placeholders ) {
public function replace( array $p_arr_placeholders ): bool {
// No placeholders set.
if ( empty( $p_arr_placeholders ) ) {
return false;
@ -119,7 +122,7 @@ class Template {
}
// Iterate through each placeholder and replace it with its value.
foreach ( $p_arr_placeholders as $l_str_placeholder => $l_str_value ) {
$this->a_str_replaced_content = str_replace( '[[' . $l_str_placeholder . ']]', $l_str_value, $this->a_str_replaced_content );
$this->a_str_replaced_content = str_replace( '[[' . $l_str_placeholder . ']]', (string) $l_str_value, $this->a_str_replaced_content );
}
// Success.
return true;
@ -130,6 +133,8 @@ class Template {
*
* @since 1.5.0
* @todo Refactor templating.
*
* @return void
*/
public function reload() {
$this->a_str_replaced_content = $this->a_str_original_content;
@ -138,25 +143,25 @@ class Template {
/**
* Returns the content of the template file with replaced placeholders.
*
* @return string Template content with replaced placeholders.
*
* @since 1.5.0
* @todo Refactor templating.
*
* @return string Template content with replaced placeholders.
*/
public function get_content() {
public function get_content(): string {
return $this->a_str_replaced_content;
}
/**
* Process template file.
*
* @param string $template The template to be processed.
* @return void
*
* @since 2.4.0d3
* @todo Refactor templating.
*
* @param string $template The template to be processed.
* @return void
*/
public function process_template( $template ) {
public function process_template( string $template ) {
// phpcs:disable WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
$this->a_str_original_content = preg_replace( '#<!--.+?-->#s', '', file_get_contents( $template ) );
// phpcs:enable
@ -172,52 +177,43 @@ class Template {
/**
* Get the template.
*
* @since 2.5.0
* @todo Refactor templating.
* @todo Single return type.
*
* @param string $p_str_file_type The file type of the template.
* @param string $p_str_file_name The file name of the template.
* @param string $p_str_extension The file extension of the template.
* @return mixed `false` or the template path
*
* @since 2.5.0
* @todo Refactor templating.
* @return string|bool `false` or the template path
*/
public function get_template( $p_str_file_type, $p_str_file_name, $p_str_extension = 'html' ) {
public function get_template( string $p_str_file_type, string $p_str_file_name, string $p_str_extension = 'html' ) {
$located = false;
/**
/*
* The directory can be changed.
*
* @usage to change location of templates to 'template_parts/footnotes/':
* add_filter( 'template_directory', function( $directory ) {
* return 'template_parts/footnotes/';
* } );
*
* @todo Review.
* To change location of templates to 'template_parts/footnotes/':
* add_filter( 'template_directory', function( $directory ) {
* return 'template_parts/footnotes/';
* } );
*/
$template_directory = apply_filters( '', 'footnotes/' );
$custom_directory = apply_filters( 'custom_template_directory', 'footnotes-custom/' );
$template_name = $p_str_file_type . '/' . $p_str_file_name . '.' . $p_str_extension;
/**
* Look in active theme.
*/
// Look in active theme.
if ( file_exists( trailingslashit( get_stylesheet_directory() ) . $template_directory . $template_name ) ) {
$located = trailingslashit( get_stylesheet_directory() ) . $template_directory . $template_name;
/**
* Look in parent theme in case active is child.
*/
// Look in parent theme in case active is child.
} elseif ( file_exists( trailingslashit( get_template_directory() ) . $template_directory . $template_name ) ) {
$located = trailingslashit( get_template_directory() ) . $template_directory . $template_name;
/**
* Look in custom plugin directory.
*/
// Look in custom plugin directory.
} elseif ( file_exists( trailingslashit( WP_PLUGIN_DIR ) . $custom_directory . 'templates/' . $template_name ) ) {
$located = trailingslashit( WP_PLUGIN_DIR ) . $custom_directory . 'templates/' . $template_name;
/**
* Fall back to the templates shipped with the plugin.
*/
// Fall back to the templates shipped with the plugin.
} elseif ( file_exists( $this->plugin_directory . $template_name ) ) {
$located = $this->plugin_directory . $template_name;
}

View file

@ -6,6 +6,8 @@
* @since 2.8.0
*/
declare(strict_types=1);
namespace footnotes\general;
use footnotes\includes as Includes;
@ -29,7 +31,7 @@ class General {
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
private string $plugin_name;
/**
* The version of this plugin.
@ -39,7 +41,7 @@ class General {
* @access private
* @var string $version The current version of this plugin.
*/
private $version;
private string $version;
/**
* The reference container widget.
@ -48,17 +50,18 @@ class General {
*
* @var Widget\Reference_Container $reference_container_widget The reference container widget
*/
private $reference_container_widget;
private Widget\Reference_Container $reference_container_widget;
/**
* The footnote parser.
*
* @since 1.5.0
* @since 2.8.0 Moved from {@see Footnotes} to {@see Includes\Public}.
* @todo Review null init.
*
* @var Parser $task The Plugin task.
*/
public $a_obj_task = null;
public ?Parser $a_obj_task = null;
/**
* Flag for using tooltips.
@ -107,7 +110,7 @@ class General {
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version ) {
public function __construct( string $plugin_name, string $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
@ -132,7 +135,7 @@ class General {
*
* @since 2.8.0
*/
private function load_dependencies() {
private function load_dependencies(): void {
// TODO: neaten up and document once placements and names are settled.
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-config.php';
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-settings.php';
@ -156,7 +159,7 @@ class General {
* @since 2.5.5 Change stylesheet schema.
* @since 2.8.0 Moved from {@see Footnotes} to {@see Includes\Public}.
*/
public function enqueue_styles() {
public function enqueue_styles(): void {
if ( PRODUCTION_ENV ) {
// Set tooltip mode for use in stylesheet name.
if ( self::$a_bool_tooltips_enabled ) {
@ -204,11 +207,25 @@ class General {
array(),
( PRODUCTION_ENV ) ? $this->version : filemtime(
plugin_dir_path(
dirname( __FILE__ )
__FILE__
) . "css/footnotes-{$l_str_tooltip_mode_short}brpl{$l_str_layout_mode}.min.css"
),
'all'
);
} else {
foreach ( array( 'amp-tooltips', 'common', 'layout-entry-content', 'layout-main-content', 'layout-reference-container', 'tooltips', 'tooltips-alternative' ) as $val ) {
wp_enqueue_style(
"footnotes-$val",
plugin_dir_url( __FILE__ ) . "css/dev-$val.css",
array(),
filemtime(
plugin_dir_path(
__FILE__
) . "css/dev-$val.css"
),
'all'
);
}
}
}
@ -221,7 +238,7 @@ class General {
* @since 2.5.6 Add jQuery dependency.
* @since 2.8.0 Moved from {@see Footnotes} to {@see Includes\Public}.
*/
public function enqueue_scripts() {
public function enqueue_scripts(): void {
/*
* Enqueues the jQuery library registered by WordPress.
*
@ -270,7 +287,7 @@ class General {
* @since 1.5.0
* @since 2.8.0 Moved from {@see Footnotes} to {@see Includes\Public}.
*/
public function register_widgets() {
public function register_widgets(): void {
register_widget( $this->reference_container_widget );
}
}

File diff suppressed because it is too large Load diff

View file

@ -10,6 +10,8 @@
* @since 1.5.0
*/
declare(strict_types=1);
namespace footnotes\general\Widget;
use footnotes\includes as Includes;
@ -36,7 +38,7 @@ abstract class Base extends \WP_Widget {
*
* @return string
*/
abstract protected function get_id();
abstract protected function get_id(): string;
/**
* Returns the Public name of child Widget to be displayed in the Configuration page.
@ -46,7 +48,7 @@ abstract class Base extends \WP_Widget {
*
* @return string
*/
abstract protected function get_name();
abstract protected function get_name(): string;
/**
* Returns the Description of the child widget.
@ -56,7 +58,7 @@ abstract class Base extends \WP_Widget {
*
* @return string
*/
abstract protected function get_description();
abstract protected function get_description(): string;
/**
* Returns the width of the Widget. Default width is 250 pixel.
@ -65,7 +67,7 @@ abstract class Base extends \WP_Widget {
*
* @return int
*/
protected function get_widget_width() {
protected function get_widget_width(): int {
return 250;
}

View file

@ -10,6 +10,9 @@
* @since 1.5.0
*/
// TODO: Disabled pending WPWidget AP review.
/* declare(strict_types=1); */
namespace footnotes\general\Widget;
use footnotes\includes as Includes;
@ -34,7 +37,7 @@ class Reference_Container extends Base {
* @see Includes\Footnotes::$plugin_name
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
private string $plugin_name;
/**
* Initialize the class and set its properties.
@ -43,9 +46,9 @@ class Reference_Container extends Base {
*
* @param string $plugin_name The name of this plugin.
*/
public function __construct( $plugin_name ) {
parent::__construct();
public function __construct( string $plugin_name ) {
$this->plugin_name = $plugin_name;
parent::__construct();
}
/**
@ -56,7 +59,7 @@ class Reference_Container extends Base {
*
* @return string
*/
protected function get_id() {
protected function get_id(): string {
return 'footnotes_widget';
}
@ -68,7 +71,7 @@ class Reference_Container extends Base {
*
* @return string
*/
protected function get_name() {
protected function get_name(): string {
return $this->plugin_name;
}
@ -80,7 +83,7 @@ class Reference_Container extends Base {
*
* @return string
*/
protected function get_description() {
protected function get_description(): string {
return __( 'The widget defines the position of the reference container if set to &ldquo;widget area&rdquo;.', 'footnotes' );
}

View file

@ -16,6 +16,8 @@
* @since 2.8.0
*/
declare(strict_types=1);
// If uninstall not called from WordPress, then exit.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;