refactor: rename files in line with WPCS, split into public/admin/includes (a.k.a. common)
This commit is contained in:
parent
11bb8a8377
commit
ca3b283356
19 changed files with 838 additions and 670 deletions
|
@ -1,4 +1,4 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName
|
||||
<?php
|
||||
/**
|
||||
* Includes the Plugin Constants class to load all Plugin constant vars like Plugin name, etc.
|
||||
*
|
|
@ -1,4 +1,4 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName
|
||||
<?php
|
||||
/**
|
||||
* Includes the Convert Class.
|
||||
*
|
44
src/includes/class-footnotes-i18n.php
Normal file
44
src/includes/class-footnotes-i18n.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php // phpcs:disable PEAR.NamingConventions.ValidClassName.Invalid
|
||||
/**
|
||||
* Define the internationalization functionality
|
||||
*
|
||||
* Loads and defines the internationalization files for this plugin
|
||||
* so that it is ready for translation.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @since 2.8.0 Renamed class to `Footnotes_i18n`.
|
||||
*
|
||||
* @package footnotes
|
||||
* @subpackage footnotes/includes
|
||||
*/
|
||||
|
||||
require_once dirname( __FILE__ ) . '/class-footnotes-config.php';
|
||||
|
||||
/**
|
||||
* Define the internationalization functionality.
|
||||
*
|
||||
* Loads and defines the internationalization files for this plugin
|
||||
* so that it is ready for translation.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @since 2.8.0 Renamed class to `Footnotes_i18n`.
|
||||
* @package footnotes
|
||||
* @subpackage footnotes/includes
|
||||
*/
|
||||
class Footnotes_i18n {
|
||||
|
||||
/**
|
||||
* Load the plugin text domain for translation.
|
||||
*
|
||||
* @since 1.5.1
|
||||
* @since 2.8.0 Rename from `load()` to `load_plugin_textdomain()`. Remove unused `$p_str_language_code` parameter.
|
||||
*/
|
||||
public function load_plugin_textdomain() {
|
||||
load_plugin_textdomain(
|
||||
'footnotes',
|
||||
false,
|
||||
dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
140
src/includes/class-footnotes-loader.php
Normal file
140
src/includes/class-footnotes-loader.php
Normal file
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
/**
|
||||
* Register all actions and filters for the plugin.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*
|
||||
* @package footnotes
|
||||
* @subpackage footnotes/includes
|
||||
*/
|
||||
|
||||
/**
|
||||
* Register all actions and filters for the plugin.
|
||||
*
|
||||
* Maintain a list of all hooks that are registered throughout
|
||||
* the plugin, and register them with the WordPress API. Call the
|
||||
* run function to execute the list of actions and filters.
|
||||
*
|
||||
* @package footnotes
|
||||
* @subpackage footnotes/includes
|
||||
*/
|
||||
class Footnotes_Loader {
|
||||
/**
|
||||
* The array of actions registered with WordPress.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access protected
|
||||
* @var array $actions The actions registered with WordPress to fire when the plugin loads.
|
||||
*/
|
||||
protected $actions;
|
||||
|
||||
/**
|
||||
* The array of filters registered with WordPress.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access protected
|
||||
* @var array $filters The filters registered with WordPress to fire when the plugin loads.
|
||||
*/
|
||||
protected $filters;
|
||||
|
||||
/**
|
||||
* Initialize the collections used to maintain the actions and filters.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$this->actions = array();
|
||||
$this->filters = array();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new action to the collection to be registered with WordPress.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @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.
|
||||
*/
|
||||
public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
|
||||
$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new filter to the collection to be registered with WordPress.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @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.
|
||||
*/
|
||||
public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
|
||||
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes all Widgets of the Plugin.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @since 2.8.0 Moved to `Footnotes_Loader` class.
|
||||
*/
|
||||
public function initialize_widgets() {
|
||||
// TODO: This probably shouldn't be necessary here.
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/widget/class-footnotes-widget-reference-container.php';
|
||||
|
||||
register_widget( 'Footnotes_Widget_Reference_Container' );
|
||||
}
|
||||
|
||||
/**
|
||||
* A utility function that is used to register the actions and hooks into a single
|
||||
* collection.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @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.
|
||||
*/
|
||||
private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
|
||||
|
||||
$hooks[] = array(
|
||||
'hook' => $hook,
|
||||
'component' => $component,
|
||||
'callback' => $callback,
|
||||
'priority' => $priority,
|
||||
'accepted_args' => $accepted_args,
|
||||
);
|
||||
|
||||
return $hooks;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the filters and actions with WordPress.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public function run() {
|
||||
|
||||
foreach ( $this->filters as $hook ) {
|
||||
add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
|
||||
}
|
||||
|
||||
foreach ( $this->actions as $hook ) {
|
||||
add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
|
||||
}
|
||||
|
||||
add_action( 'widgets_init', array( $this, 'initialize_widgets' ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName
|
||||
<?php // phpcs:disable Squiz.Commenting.FileComment.Missing
|
||||
/**
|
||||
* Includes the Settings class to handle all Plugin settings.
|
||||
*
|
||||
|
@ -13,7 +13,7 @@
|
|||
* @since 2.1.3 Bugfix: Hooks: disable the_excerpt hook by default to fix issues, thanks to @nikelaos bug report.
|
||||
*/
|
||||
|
||||
require_once dirname( __FILE__ ) . '/convert.php';
|
||||
require_once dirname( __FILE__ ) . '/class-footnotes-convert.php';
|
||||
|
||||
/**
|
||||
* Loads the settings values, sets to default values if undefined.
|
|
@ -1,4 +1,4 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName
|
||||
<?php
|
||||
/**
|
||||
* Includes the Template Engine to load and handle all Template files of the Plugin.
|
||||
*
|
||||
|
@ -198,7 +198,7 @@ class Footnotes_Template {
|
|||
* return 'template_parts/footnotes/';
|
||||
* } );
|
||||
*/
|
||||
$template_directory = apply_filters( 'footnotes_template_directory', 'footnotes/' );
|
||||
$template_directory = apply_filters( '', 'footnotes/' );
|
||||
$custom_directory = apply_filters( 'footnotes_custom_template_directory', 'footnotes-custom/' );
|
||||
$template_name = $p_str_file_type . '/' . $p_str_file_name . '.' . $p_str_extension;
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
<?php // phpcs:disable PEAR.Commenting.FileComment.Missing
|
||||
/**
|
||||
* Plugin initialiser.
|
||||
* The file that defines the core plugin class
|
||||
*
|
||||
* A class definition that includes attributes and functions used across both the
|
||||
* public-facing side of the site and the admin area.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
|
@ -8,466 +11,210 @@
|
|||
* @subpackage footnotes/includes
|
||||
*/
|
||||
|
||||
require_once dirname( __FILE__ ) . '/config.php';
|
||||
require_once dirname( __FILE__ ) . '/convert.php';
|
||||
require_once dirname( __FILE__ ) . '/hooks.php';
|
||||
require_once dirname( __FILE__ ) . '/language.php';
|
||||
require_once dirname( __FILE__ ) . '/settings.php';
|
||||
require_once dirname( __FILE__ ) . '/task.php';
|
||||
require_once dirname( __FILE__ ) . '/wysiwyg.php';
|
||||
require_once dirname( __FILE__ ) . '/dashboard/init.php';
|
||||
require_once dirname( __FILE__ ) . '/widgets/reference-container.php';
|
||||
|
||||
/**
|
||||
* Provides an entry point to the Plugin.
|
||||
* The core plugin class.
|
||||
*
|
||||
* Loads the dashboard and executes the task.
|
||||
* This is used to define internationalization, admin-specific hooks, and
|
||||
* public-facing site hooks.
|
||||
*
|
||||
* Also maintains the unique identifier of this plugin as well as the current
|
||||
* version of the plugin.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @package footnotes
|
||||
* @subpackage footnotes/includes
|
||||
*/
|
||||
class Footnotes {
|
||||
/**
|
||||
* The loader that's responsible for maintaining and registering all hooks that power
|
||||
* the plugin.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access protected
|
||||
* @var Footnotes_Loader $loader Maintains and registers all hooks for the plugin.
|
||||
*/
|
||||
protected $loader;
|
||||
|
||||
/**
|
||||
* The Plugin task.
|
||||
* The unique identifier of this plugin.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access protected
|
||||
* @var string $plugin_name The string used to uniquely identify this plugin.
|
||||
*/
|
||||
protected $plugin_name;
|
||||
|
||||
/**
|
||||
* The current version of the plugin.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access protected
|
||||
* @var string $version The current version of the plugin.
|
||||
*/
|
||||
protected $version;
|
||||
|
||||
/**
|
||||
* Define the core functionality of the plugin.
|
||||
*
|
||||
* Set the plugin name and the plugin version that can be used throughout the plugin.
|
||||
* Load the dependencies, define the locale, and set the hooks for the admin area and
|
||||
* the public-facing side of the site.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
if ( defined( 'C_STR_FOOTNOTES_VERSION' ) ) {
|
||||
$this->version = C_STR_FOOTNOTES_VERSION;
|
||||
} else {
|
||||
$this->version = '0.0.0';
|
||||
}
|
||||
$this->plugin_name = 'footnotes';
|
||||
|
||||
$this->load_dependencies();
|
||||
$this->set_locale();
|
||||
$this->define_admin_hooks();
|
||||
$this->define_public_hooks();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the required dependencies for this plugin.
|
||||
*
|
||||
* Include the following files that make up the plugin:
|
||||
*
|
||||
* - Footnotes_Loader. Orchestrates the hooks of the plugin.
|
||||
* - Footnotes_i18n. Defines internationalization functionality.
|
||||
* - Footnotes_Admin. Defines all hooks for the admin area.
|
||||
* - Footnotes_Public. Defines all hooks for the public side of the site.
|
||||
*
|
||||
* Create an instance of the loader which will be used to register the hooks
|
||||
* with WordPress.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access private
|
||||
*/
|
||||
private function load_dependencies() {
|
||||
|
||||
/**
|
||||
* The class responsible for orchestrating the actions and filters of the
|
||||
* core plugin.
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-footnotes-loader.php';
|
||||
|
||||
/**
|
||||
* The class responsible for defining internationalization functionality
|
||||
* of the plugin.
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-footnotes-i18n.php';
|
||||
// TODO: neaten up and document once placements and names are settled.
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-footnotes-config.php';
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-footnotes-convert.php';
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-footnotes-settings.php';
|
||||
|
||||
/**
|
||||
* The class responsible for defining all actions that occur in the admin area.
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-footnotes-admin.php';
|
||||
|
||||
/**
|
||||
* The class responsible for defining all actions that occur in the public-facing
|
||||
* side of the site.
|
||||
*/
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-footnotes-public.php';
|
||||
|
||||
$this->loader = new Footnotes_Loader();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the locale for this plugin for internationalization.
|
||||
*
|
||||
* Uses the `Footnotes_i18n` class in order to set the domain and to register the hook
|
||||
* with WordPress.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access private
|
||||
*/
|
||||
private function set_locale() {
|
||||
|
||||
$plugin_i18n = new Footnotes_i18n();
|
||||
|
||||
$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register all of the hooks related to the admin area functionality
|
||||
* of the plugin.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access private
|
||||
*/
|
||||
private function define_admin_hooks() {
|
||||
|
||||
$plugin_admin = new Footnotes_Admin( $this->get_plugin_name(), $this->get_version() );
|
||||
|
||||
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
|
||||
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
|
||||
|
||||
$this->loader->add_filter( 'admin_get_plugin_links', $plugin_admin, 'get_plugin_links', 10, 1 );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register all of the hooks related to the public-facing functionality
|
||||
* of the plugin.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access private
|
||||
*/
|
||||
private function define_public_hooks() {
|
||||
|
||||
$plugin_public = new Footnotes_Public( $this->get_plugin_name(), $this->get_version() );
|
||||
|
||||
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
|
||||
$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the loader to execute all of the hooks with WordPress.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @var Task $task The Plugin task.
|
||||
*/
|
||||
public $a_obj_task = null;
|
||||
|
||||
/**
|
||||
* Flag for using tooltips.
|
||||
*
|
||||
* @since 2.4.0
|
||||
*
|
||||
* @var bool $tooltips_enabled Whether tooltips are enabled or not.
|
||||
*/
|
||||
public static $a_bool_tooltips_enabled = false;
|
||||
|
||||
/**
|
||||
* Allows to determine whether alternative tooltips are enabled.
|
||||
*
|
||||
* - Bugfix: Tooltips: optional alternative JS implementation with CSS transitions to fix configuration-related outage, thanks to @andreasra feedback.
|
||||
*
|
||||
* @since 2.1.1
|
||||
*
|
||||
* @reporter @andreasra
|
||||
* @link https://wordpress.org/support/topic/footnotes-appearing-in-header/page/2/#post-13632566
|
||||
*
|
||||
* @since 2.4.0
|
||||
* @contributor Patrizia Lutz @misfist
|
||||
* @var bool
|
||||
*/
|
||||
public static $a_bool_alternative_tooltips_enabled = false;
|
||||
|
||||
/**
|
||||
* Allows to determine whether AMP compatibility mode is enabled.
|
||||
*
|
||||
* - Adding: Tooltips: make display work purely by style rules for AMP compatibility, thanks to @milindmore22 code contribution.
|
||||
* - Bugfix: Tooltips: enable accessibility by keyboard navigation, thanks to @westonruter code contribution.
|
||||
* - Adding: Reference container: get expanding and collapsing to work also in AMP compatibility mode, thanks to @westonruter code contribution.
|
||||
*
|
||||
* @since 2.5.11 (draft)
|
||||
* @since 2.6.0 (release)
|
||||
*
|
||||
* @contributor @milindmore22
|
||||
* @link https://github.com/ampproject/amp-wp/issues/5913#issuecomment-785306933
|
||||
*
|
||||
* @contributor @westonruter
|
||||
* @link https://github.com/ampproject/amp-wp/issues/5913#issuecomment-785419655
|
||||
* @link https://github.com/markcheret/footnotes/issues/48#issuecomment-799580854
|
||||
* @link https://github.com/markcheret/footnotes/issues/48#issuecomment-799582394
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public static $a_bool_amp_enabled = false;
|
||||
|
||||
/**
|
||||
* Allows to determine the script mode among jQuery or plain JS.
|
||||
*
|
||||
* - Bugfix: Reference container: optional alternative expanding and collapsing without jQuery for use with hard links, thanks to @hopper87it @pkverma99 issue reports.
|
||||
*
|
||||
* @since 2.5.6
|
||||
*
|
||||
* @reporter @hopper87it
|
||||
* @link https://wordpress.org/support/topic/footnotes-wp-rocket/
|
||||
*
|
||||
* @reporter @pkverma99
|
||||
* @link https://wordpress.org/support/topic/footnotes-wp-rocket/#post-14076188
|
||||
*
|
||||
* @var str 'js' Plain JavaScript.
|
||||
* 'jquery' Use jQuery libraries.
|
||||
*/
|
||||
public static $a_str_script_mode = 'js';
|
||||
|
||||
/**
|
||||
* Executes the Plugin.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* - Bugfix: Improve widgets registration, thanks to @felipelavinz code contribution.
|
||||
*
|
||||
* @since 1.6.5
|
||||
*
|
||||
* @contributor @felipelavinz
|
||||
* @link https://github.com/benleyjyc/footnotes/commit/87173d2980c7ff90e12ffee94ca7153e11163793
|
||||
* @link https://github.com/media-competence-institute/footnotes/commit/87173d2980c7ff90e12ffee94ca7153e11163793
|
||||
*
|
||||
* @see self::initialize_widgets()
|
||||
*/
|
||||
public function run() {
|
||||
// Register language.
|
||||
Footnotes_Language::register_hooks();
|
||||
// Register Button hooks.
|
||||
Footnotes_WYSIWYG::register_hooks();
|
||||
// Register general hooks.
|
||||
Footnotes_Hooks::register_hooks();
|
||||
|
||||
// Initialize the Plugin Dashboard.
|
||||
$this->initialize_dashboard();
|
||||
// Initialize the Plugin Task.
|
||||
$this->initialize_task();
|
||||
|
||||
// Register all Public Stylesheets and Scripts.
|
||||
add_action( 'init', array( $this, 'register_public' ) );
|
||||
// Enqueue all Public Stylesheets and Scripts.
|
||||
add_action( 'wp_enqueue_scripts', array( $this, 'register_public' ) );
|
||||
// Register all Widgets of the Plugin..
|
||||
add_action( 'widgets_init', array( $this, 'initialize_widgets' ) );
|
||||
$this->loader->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes all Widgets of the Plugin.
|
||||
* The name of the plugin used to uniquely identify it within the context of
|
||||
* WordPress and to define internationalization functionality.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* - Update: Fix for deprecated PHP function create_function(), thanks to @psykonevro @daliasued bug reports, thanks to @felipelavinz code contribution
|
||||
*
|
||||
* @since 1.6.5
|
||||
*
|
||||
* @contributor @felipelavinz
|
||||
* @link https://github.com/media-competence-institute/footnotes/commit/87173d2980c7ff90e12ffee94ca7153e11163793
|
||||
*
|
||||
* @reporter @psykonevro
|
||||
* @link https://wordpress.org/support/topic/bug-function-create_function-is-deprecated/
|
||||
* @link https://wordpress.org/support/topic/deprecated-function-create_function-14/
|
||||
*
|
||||
* @reporter @daliasued
|
||||
* @link https://wordpress.org/support/topic/deprecated-function-create_function-14/#post-13312853
|
||||
*
|
||||
* create_function() was deprecated in PHP 7.2.0 and removed in PHP 8.0.0.
|
||||
* @link https://www.php.net/manual/en/function.create-function.php
|
||||
*
|
||||
* The fix is to move add_action() above into run(),
|
||||
* and use the bare register_widget() here.
|
||||
* @see self::run()
|
||||
*
|
||||
* Also, the visibility of initialize_widgets() is not private any longer.
|
||||
* @since 1.0.0
|
||||
* @return string The name of the plugin.
|
||||
*/
|
||||
public function initialize_widgets() {
|
||||
register_widget( 'Footnotes_Widget_Reference_Container' );
|
||||
public function get_plugin_name() {
|
||||
return $this->plugin_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the Dashboard of the Plugin and loads them.
|
||||
* The reference to the class that orchestrates the hooks with the plugin.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @since 1.0.0
|
||||
* @return Footnotes_Loader Orchestrates the hooks of the plugin.
|
||||
*/
|
||||
private function initialize_dashboard() {
|
||||
new Footnotes_Layout_Init();
|
||||
public function get_loader() {
|
||||
return $this->loader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the Plugin Task and registers the Task hooks.
|
||||
* Retrieve the version number of the plugin.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @since 1.0.0
|
||||
* @return string The version number of the plugin.
|
||||
*/
|
||||
private function initialize_task() {
|
||||
$this->a_obj_task = new Footnotes_Task();
|
||||
$this->a_obj_task->register_hooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers and enqueues scripts and stylesheets to the public pages.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @since 2.0.0 Update: Tooltips: fix disabling bug by loading jQuery UI library, thanks to @rajinderverma @ericcorbett2 @honlapdavid @mmallett bug reports, thanks to @vonpiernik code contribution.
|
||||
* @since 2.0.3 add versioning of public.css for cache busting
|
||||
* @since 2.0.4 add jQuery UI from WordPress
|
||||
* @since 2.1.4 automate passing version number for cache busting
|
||||
* @since 2.1.4 optionally enqueue an extra stylesheet
|
||||
*/
|
||||
public function register_public() {
|
||||
|
||||
/**
|
||||
* Enqueues external scripts.
|
||||
*
|
||||
* - Bugfix: Libraries: optimize processes by loading external and internal scripts only if needed, thanks to @docteurfitness issue report.
|
||||
*
|
||||
* @since 2.5.5
|
||||
* @reporter @docteurfitness
|
||||
* @link https://wordpress.org/support/topic/simply-speed-optimisation/
|
||||
*
|
||||
* The condition about tooltips was missing, only the not-alternative-tooltips part was present.
|
||||
*/
|
||||
// Set conditions re-used for stylesheet enqueuing and in class/task.php.
|
||||
self::$a_bool_amp_enabled = Footnotes_Convert::to_bool( Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_AMP_COMPATIBILITY_ENABLE ) );
|
||||
self::$a_bool_tooltips_enabled = Footnotes_Convert::to_bool( Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_MOUSE_OVER_BOX_ENABLED ) );
|
||||
self::$a_bool_alternative_tooltips_enabled = Footnotes_Convert::to_bool( Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_MOUSE_OVER_BOX_ALTERNATIVE ) );
|
||||
self::$a_str_script_mode = Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_REFERENCE_CONTAINER_SCRIPT_MODE );
|
||||
|
||||
/**
|
||||
* Enqueues the jQuery library registered by WordPress.
|
||||
*
|
||||
* - Bugfix: Reference container: optional alternative expanding and collapsing without jQuery for use with hard links, thanks to @hopper87it @pkverma99 issue reports.
|
||||
*
|
||||
* @since 2.5.6
|
||||
*
|
||||
* @reporter @hopper87it
|
||||
* @link https://wordpress.org/support/topic/footnotes-wp-rocket/
|
||||
*
|
||||
* jQuery is also used for animated scrolling, so it was loaded by default.
|
||||
* The function wp_enqueue_script() avoids loading the same library multiple times.
|
||||
* After adding the alternative reference container, jQuery has become optional,
|
||||
* but still enabled by default.
|
||||
*/
|
||||
if ( ! self::$a_bool_amp_enabled ) {
|
||||
|
||||
if ( 'jquery' === self::$a_str_script_mode || ( self::$a_bool_tooltips_enabled && ! self::$a_bool_alternative_tooltips_enabled ) ) {
|
||||
|
||||
wp_enqueue_script( 'jquery' );
|
||||
|
||||
}
|
||||
|
||||
if ( self::$a_bool_tooltips_enabled && ! self::$a_bool_alternative_tooltips_enabled ) {
|
||||
|
||||
/**
|
||||
* Enqueues the jQuery Tools library shipped with the plugin.
|
||||
*
|
||||
* Redacted jQuery.browser, completed minification;
|
||||
* see full header in js/jquery.tools.js.
|
||||
*
|
||||
* Add versioning.
|
||||
*
|
||||
* @since 2.1.2
|
||||
*
|
||||
* No '-js' in the handle, is appended automatically.
|
||||
*
|
||||
* Deferring to the footer breaks jQuery tooltip display.
|
||||
*/
|
||||
wp_enqueue_script(
|
||||
'footnotes-jquery-tools',
|
||||
plugins_url( 'footnotes/public/js/jquery.tools' . ( ( PRODUCTION_ENV ) ? '.min' : '' ) . '.js' ),
|
||||
array(),
|
||||
'1.2.7.redacted.2',
|
||||
false
|
||||
);
|
||||
|
||||
/**
|
||||
* Enqueues some jQuery UI libraries registered by WordPress.
|
||||
*
|
||||
* - Update: Tooltips: fix disabling bug by loading jQuery UI library, thanks to @rajinderverma @ericcorbett2 @honlapdavid @mmallett bug reports, thanks to @vonpiernik code contribution.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @reporter @rajinderverma
|
||||
* @link https://wordpress.org/support/topic/tooltip-hover-not-showing/
|
||||
*
|
||||
* @reporter @ericcorbett2
|
||||
* @link https://wordpress.org/support/topic/tooltip-hover-not-showing/#post-13324142
|
||||
*
|
||||
* @reporter @honlapdavid
|
||||
* @link https://wordpress.org/support/topic/tooltip-hover-not-showing/#post-13355421
|
||||
*
|
||||
* @reporter @mmallett
|
||||
* @link https://wordpress.org/support/topic/tooltip-hover-not-showing/#post-13445437
|
||||
*
|
||||
* Fetch jQuery UI from cdnjs.cloudflare.com.
|
||||
* @since 2.0.0
|
||||
* @contributor @vonpiernik
|
||||
* @link https://wordpress.org/support/topic/tooltip-hover-not-showing/#post-13456762
|
||||
*
|
||||
* jQueryUI re-enables the tooltip infobox disabled when WPv5.5 was released. * @since 2.1.2
|
||||
*
|
||||
* - Update: Libraries: Load jQuery UI from WordPress, thanks to @check2020de issue report.
|
||||
*
|
||||
* @since 2.0.4
|
||||
* @reporter @check2020de
|
||||
* @link https://wordpress.org/support/topic/gdpr-issue-with-jquery/
|
||||
* @link https://wordpress.stackexchange.com/questions/273986/correct-way-to-enqueue-jquery-ui
|
||||
*
|
||||
* If alternative tooltips are enabled, these libraries are not needed.
|
||||
*/
|
||||
wp_enqueue_script( 'jquery-ui-core' );
|
||||
wp_enqueue_script( 'jquery-ui-widget' );
|
||||
wp_enqueue_script( 'jquery-ui-position' );
|
||||
wp_enqueue_script( 'jquery-ui-tooltip' );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables enqueuing a new-scheme stylesheet.
|
||||
*
|
||||
* @since 2.5.5
|
||||
*
|
||||
* Enables enqueuing the formatted individual stylesheets if false.
|
||||
* WARNING: This facility is designed for development and must NOT be used in production.
|
||||
*
|
||||
* The Boolean may be set at the bottom of the plugin’s main PHP file.
|
||||
* @see footnotes.php
|
||||
*/
|
||||
if ( PRODUCTION_ENV ) {
|
||||
|
||||
/**
|
||||
* Enqueues a minified united external stylesheet in production.
|
||||
*
|
||||
* - Update: Stylesheets: increase speed and energy efficiency by tailoring stylesheets to the needs of the instance, thanks to @docteurfitness design contribution.
|
||||
* - Bugfix: Stylesheets: minify to shrink the carbon footprint, increase speed and implement best practice, thanks to @docteurfitness issue report.
|
||||
*
|
||||
* @since 2.5.5
|
||||
*
|
||||
* @contributor @docteurfitness
|
||||
* @link https://wordpress.org/support/topic/simply-speed-optimisation/
|
||||
*
|
||||
* @reporter @docteurfitness
|
||||
* @link https://wordpress.org/support/topic/simply-speed-optimisation/
|
||||
*
|
||||
* The dashboard stylesheet is minified as-is.
|
||||
* @see class/dashboard/layout.php
|
||||
*
|
||||
* @since 2.0.3 add versioning of public.css for cache busting.
|
||||
* Plugin version number is needed for busting browser caches after each plugin update.
|
||||
*
|
||||
* @since 2.1.4 automate passing version number for cache busting.
|
||||
* The constant C_STR_FOOTNOTES_VERSION is defined at start of footnotes.php.
|
||||
*
|
||||
* The media scope argument 'all' is the default.
|
||||
* No need to use '-css' in the handle, as this is appended automatically.
|
||||
*/
|
||||
// Set tooltip mode for use in stylesheet name.
|
||||
if ( self::$a_bool_tooltips_enabled ) {
|
||||
|
||||
if ( self::$a_bool_amp_enabled ) {
|
||||
$l_str_tooltip_mode_short = 'ampt';
|
||||
$l_str_tooltip_mode_long = 'amp-tooltips';
|
||||
|
||||
} elseif ( self::$a_bool_alternative_tooltips_enabled ) {
|
||||
$l_str_tooltip_mode_short = 'altt';
|
||||
$l_str_tooltip_mode_long = 'alternative-tooltips';
|
||||
|
||||
} else {
|
||||
$l_str_tooltip_mode_short = 'jqtt';
|
||||
$l_str_tooltip_mode_long = 'jquery-tooltips';
|
||||
|
||||
}
|
||||
} else {
|
||||
$l_str_tooltip_mode_short = 'nott';
|
||||
$l_str_tooltip_mode_long = 'no-tooltips';
|
||||
}
|
||||
|
||||
// Set basic responsive page layout mode for use in stylesheet name.
|
||||
$l_str_page_layout_option = Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_PAGE_LAYOUT_SUPPORT );
|
||||
switch ( $l_str_page_layout_option ) {
|
||||
case 'reference-container':
|
||||
$l_str_layout_mode = '1';
|
||||
break;
|
||||
case 'entry-content':
|
||||
$l_str_layout_mode = '2';
|
||||
break;
|
||||
case 'main-content':
|
||||
$l_str_layout_mode = '3';
|
||||
break;
|
||||
case 'none':
|
||||
default:
|
||||
$l_str_layout_mode = '0';
|
||||
break;
|
||||
}
|
||||
|
||||
// Enqueue the tailored united minified stylesheet.
|
||||
wp_enqueue_style(
|
||||
'footnotes-' . $l_str_tooltip_mode_long . '-pagelayout-' . $l_str_page_layout_option,
|
||||
plugins_url(
|
||||
Footnotes_Config::C_STR_PLUGIN_NAME . '/css/footnotes-' . $l_str_tooltip_mode_short . 'brpl' . $l_str_layout_mode . '.min.css'
|
||||
),
|
||||
array(),
|
||||
C_STR_FOOTNOTES_VERSION,
|
||||
'all'
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
/**
|
||||
* Enqueues external stylesheets, ONLY in development now.
|
||||
*
|
||||
* @since 2.1.4 optionally enqueue an extra stylesheet.
|
||||
*
|
||||
* This optional layout fix is useful by lack of layout support.
|
||||
*/
|
||||
wp_enqueue_style(
|
||||
'footnotes-common',
|
||||
plugins_url( Footnotes_Config::C_STR_PLUGIN_NAME . '/css/dev-common.css' ),
|
||||
array(),
|
||||
filemtime(
|
||||
plugin_dir_path(
|
||||
dirname( __FILE__, 1 )
|
||||
) . 'css/dev-common.css'
|
||||
)
|
||||
);
|
||||
wp_enqueue_style(
|
||||
'footnotes-tooltips',
|
||||
plugins_url( Footnotes_Config::C_STR_PLUGIN_NAME . '/css/dev-tooltips.css' ),
|
||||
array(),
|
||||
filemtime(
|
||||
plugin_dir_path(
|
||||
dirname( __FILE__, 1 )
|
||||
) . 'css/dev-tooltips.css'
|
||||
)
|
||||
);
|
||||
|
||||
if ( self::$a_bool_amp_enabled ) {
|
||||
wp_enqueue_style(
|
||||
'footnotes-amp',
|
||||
plugins_url( Footnotes_Config::C_STR_PLUGIN_NAME . '/css/dev-amp-tooltips.css' ),
|
||||
array(),
|
||||
filemtime(
|
||||
plugin_dir_path(
|
||||
dirname( __FILE__, 1 )
|
||||
) . 'css/dev-amp-tooltips.css'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( self::$a_bool_alternative_tooltips_enabled ) {
|
||||
wp_enqueue_style(
|
||||
'footnotes-alternative',
|
||||
plugins_url( Footnotes_Config::C_STR_PLUGIN_NAME . '/css/dev-tooltips-alternative.css' ),
|
||||
array(),
|
||||
filemtime(
|
||||
plugin_dir_path(
|
||||
dirname( __FILE__, 1 )
|
||||
) . 'css/dev-tooltips-alternative.css'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$l_str_page_layout_option = Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_PAGE_LAYOUT_SUPPORT );
|
||||
if ( 'none' !== $l_str_page_layout_option ) {
|
||||
wp_enqueue_style(
|
||||
'footnotes-layout-' . $l_str_page_layout_option,
|
||||
plugins_url(
|
||||
Footnotes_Config::C_STR_PLUGIN_NAME . '/css/dev-layout-' . $l_str_page_layout_option . '.css'
|
||||
),
|
||||
array(),
|
||||
filemtime(
|
||||
plugin_dir_path(
|
||||
dirname( __FILE__, 1 )
|
||||
) . 'css/dev-layout-' . $l_str_page_layout_option . '.css'
|
||||
),
|
||||
'all'
|
||||
);
|
||||
}
|
||||
}
|
||||
public function get_version() {
|
||||
return $this->version;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,151 +0,0 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
/**
|
||||
* Includes the Plugin settings menu.
|
||||
*
|
||||
* @filesource
|
||||
* @package footnotes
|
||||
* @since 1.5.0
|
||||
*/
|
||||
|
||||
require_once dirname( __FILE__, 2) . '/settings.php';
|
||||
require_once dirname( __FILE__ ) . '/subpage-main.php';
|
||||
|
||||
/**
|
||||
* Handles the Settings interface of the Plugin.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class Footnotes_Layout_Init {
|
||||
|
||||
/**
|
||||
* Slug for the Plugin main menu.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @var string
|
||||
*/
|
||||
const C_STR_MAIN_MENU_SLUG = 'footnotes';
|
||||
|
||||
/**
|
||||
* Plugin main menu name.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @var string
|
||||
*/
|
||||
const C_STR_MAIN_MENU_TITLE = 'ManFisher';
|
||||
|
||||
/**
|
||||
* Contains the settings layoutEngine
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @var array
|
||||
*/
|
||||
private $settings_page;
|
||||
|
||||
/**
|
||||
* Class Constructor. Initializes all WordPress hooks for the Plugin Settings.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->settings_page = new Footnotes_Layout_Settings();
|
||||
|
||||
// Register hooks/actions.
|
||||
add_action( 'admin_menu', array( $this, 'register_options_submenu' ) );
|
||||
add_action( 'admin_init', array( $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' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the settings and initialises the settings page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public function initialize_settings() {
|
||||
Footnotes_Settings::instance()->register_settings();
|
||||
$this->settings_page->register_sections();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the footnotes submenu page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @see http://codex.wordpress.org/Function_Reference/add_menu_page
|
||||
*/
|
||||
public function register_options_submenu() {
|
||||
add_submenu_page(
|
||||
'options-general.php',
|
||||
'footnotes Settings',
|
||||
self::C_STR_MAIN_MENU_SLUG,
|
||||
'manage_options',
|
||||
'footnotes',
|
||||
array( $this->settings_page, 'display_content' )
|
||||
);
|
||||
$this->settings_page->register_sub_page();
|
||||
}
|
||||
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Missing
|
||||
/**
|
||||
* AJAX call. returns a JSON string containing meta information about a specific WordPress Plugin.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public function get_plugin_meta_information() {
|
||||
// TODO: add nonce verification.
|
||||
|
||||
// Get plugin internal name from POST data.
|
||||
if ( isset( $_POST['plugin'] ) ) {
|
||||
$l_str_plugin_name = wp_unslash( $_POST['plugin'] );
|
||||
}
|
||||
|
||||
if ( empty( $l_str_plugin_name ) ) {
|
||||
echo wp_json_encode( array( 'error' => 'Plugin name invalid.' ) );
|
||||
exit;
|
||||
}
|
||||
$l_str_url = 'https://api.wordpress.org/plugins/info/1.0/' . $l_str_plugin_name . '.json';
|
||||
// Call URL and collect data.
|
||||
$l_arr_response = wp_remote_get( $l_str_url );
|
||||
// Check if response is valid.
|
||||
if ( is_wp_error( $l_arr_response ) ) {
|
||||
echo wp_json_encode( array( 'error' => 'Error receiving Plugin Information from WordPress.' ) );
|
||||
exit;
|
||||
}
|
||||
if ( ! array_key_exists( 'body', $l_arr_response ) ) {
|
||||
echo wp_json_encode( array( 'error' => 'Error reading WordPress API response message.' ) );
|
||||
exit;
|
||||
}
|
||||
// Get the body of the response.
|
||||
$l_str_response = $l_arr_response['body'];
|
||||
// Get plugin object.
|
||||
$l_arr_plugin = json_decode( $l_str_response, true );
|
||||
if ( empty( $l_arr_plugin ) ) {
|
||||
echo wp_json_encode( array( 'error' => 'Error reading Plugin meta information.<br/>URL: ' . $l_str_url . '<br/>Response: ' . $l_str_response ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
$l_int_num_ratings = array_key_exists( 'num_ratings', $l_arr_plugin ) ? intval( $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 );
|
||||
|
||||
// Return Plugin information as JSON encoded string.
|
||||
echo wp_json_encode(
|
||||
array(
|
||||
'error' => '',
|
||||
'PluginDescription' => array_key_exists( 'short_description', $l_arr_plugin ) ? html_entity_decode( $l_arr_plugin['short_description'] ) : 'Error reading Plugin information',
|
||||
'PluginAuthor' => array_key_exists( 'author', $l_arr_plugin ) ? html_entity_decode( $l_arr_plugin['author'] ) : 'unknown',
|
||||
'PluginRatingText' => $l_int_stars . ' ' . __( 'rating based on', 'footnotes' ) . ' ' . $l_int_num_ratings . ' ' . __( 'ratings', 'footnotes' ),
|
||||
'PluginRating1' => $l_int_stars >= 0.5 ? 'star-full' : 'star-empty',
|
||||
'PluginRating2' => $l_int_stars >= 1.5 ? 'star-full' : 'star-empty',
|
||||
'PluginRating3' => $l_int_stars >= 2.5 ? 'star-full' : 'star-empty',
|
||||
'PluginRating4' => $l_int_stars >= 3.5 ? 'star-full' : 'star-empty',
|
||||
'PluginRating5' => $l_int_stars >= 4.5 ? 'star-full' : 'star-empty',
|
||||
'PluginRating' => $l_int_num_ratings,
|
||||
'PluginLastUpdated' => array_key_exists( 'last_updated', $l_arr_plugin ) ? $l_arr_plugin['last_updated'] : 'unknown',
|
||||
'PluginDownloads' => array_key_exists( 'downloaded', $l_arr_plugin ) ? $l_arr_plugin['downloaded'] : '---',
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Missing
|
||||
}
|
|
@ -1,592 +0,0 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
/**
|
||||
* Includes Layout Engine for the admin dashboard.
|
||||
*
|
||||
* @filesource
|
||||
* @package footnotes
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @since 2.1.2 add versioning of settings.css for cache busting
|
||||
* @since 2.1.4 automate passing version number for cache busting
|
||||
* @since 2.1.4 optional step argument and support for floating in numbox
|
||||
* @since 2.1.6 fix punctuation-related localization issue in dashboard labels
|
||||
*
|
||||
* @since 2.5.5 Bugfix: Stylesheets: minify to shrink the carbon footprint, increase speed and implement best practice, thanks to @docteurfitness issue report.
|
||||
*/
|
||||
|
||||
require_once dirname( __FILE__, 2) . '/config.php';
|
||||
require_once dirname( __FILE__, 2) . '/convert.php';
|
||||
require_once dirname( __FILE__, 2) . '/settings.php';
|
||||
require_once dirname( __FILE__ ) . '/init.php';
|
||||
|
||||
/**
|
||||
* Layout Engine for the administration dashboard.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
abstract class Footnotes_Layout_Engine {
|
||||
|
||||
/**
|
||||
* Stores the Hook connection string for the child sub page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @var null|string
|
||||
*/
|
||||
protected $a_str_sub_page_hook = null;
|
||||
|
||||
/**
|
||||
* Stores all Sections for the child sub page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @var array
|
||||
*/
|
||||
protected $a_arr_sections = array();
|
||||
|
||||
/**
|
||||
* Returns a Priority index. Lower numbers have a higher Priority.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return int
|
||||
*/
|
||||
abstract public function get_priority();
|
||||
|
||||
/**
|
||||
* Returns the unique slug of the child sub page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function get_sub_page_slug();
|
||||
|
||||
/**
|
||||
* Returns the title of the child sub page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function get_sub_page_title();
|
||||
|
||||
/**
|
||||
* Returns an array of all registered sections for a sub page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function get_sections();
|
||||
|
||||
/**
|
||||
* Returns an array of all registered meta boxes.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function get_meta_boxes();
|
||||
|
||||
/**
|
||||
* Returns an array describing a sub page section.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param string $p_str_id Unique ID suffix.
|
||||
* @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 Should a Submit Button be displayed for this section, default: true.
|
||||
* @return array Array describing the section.
|
||||
*/
|
||||
protected function add_section( $p_str_id, $p_str_title, $p_int_settings_container_index, $p_bool_has_submit_button = true ) {
|
||||
return array(
|
||||
'id' => Footnotes_Config::C_STR_PLUGIN_NAME . '-' . $p_str_id,
|
||||
'title' => $p_str_title,
|
||||
'submit' => $p_bool_has_submit_button,
|
||||
'container' => $p_int_settings_container_index,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array describing a meta box.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param string $p_str_section_id Parent Section ID.
|
||||
* @param string $p_str_id Unique ID suffix.
|
||||
* @param string $p_str_title Title for the meta box.
|
||||
* @param string $p_str_callback_function_name Class method name for callback.
|
||||
* @return array meta box description to be able to append a meta box to the output.
|
||||
*/
|
||||
protected function add_meta_box( $p_str_section_id, $p_str_id, $p_str_title, $p_str_callback_function_name ) {
|
||||
return array(
|
||||
'parent' => Footnotes_Config::C_STR_PLUGIN_NAME . '-' . $p_str_section_id,
|
||||
'id' => $p_str_id,
|
||||
'title' => $p_str_title,
|
||||
'callback' => $p_str_callback_function_name,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a sub page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public function register_sub_page() {
|
||||
global $submenu;
|
||||
|
||||
if ( array_key_exists( plugin_basename( Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG ), $submenu ) ) {
|
||||
foreach ( $submenu[ plugin_basename( Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG ) ] as $l_arr_sub_menu ) {
|
||||
if ( plugin_basename( Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG . $this->get_sub_page_slug() ) === $l_arr_sub_menu[2] ) {
|
||||
remove_submenu_page( Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG, Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG . $this->get_sub_page_slug() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->a_str_sub_page_hook = add_submenu_page(
|
||||
Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG,
|
||||
$this->get_sub_page_title(),
|
||||
$this->get_sub_page_title(),
|
||||
'manage_options',
|
||||
Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG . $this->get_sub_page_slug(),
|
||||
array( $this, 'display_content' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers all sections for a sub page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public function register_sections() {
|
||||
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' ),
|
||||
$l_arr_section['id']
|
||||
);
|
||||
$this->register_meta_boxes( $l_arr_section['id'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers all Meta boxes for a sub page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param string $p_str_parent_id Parent section unique id.
|
||||
*/
|
||||
private function register_meta_boxes( $p_str_parent_id ) {
|
||||
// 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'] ) {
|
||||
continue;
|
||||
}
|
||||
add_meta_box(
|
||||
$p_str_parent_id . '-' . $l_arr_meta_box['id'],
|
||||
$l_arr_meta_box['title'],
|
||||
array( $this, $l_arr_meta_box['callback'] ),
|
||||
$p_str_parent_id,
|
||||
'main'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append javascript and css files for specific sub page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
private function append_scripts() {
|
||||
wp_enqueue_script( 'postbox' );
|
||||
wp_enqueue_style( 'wp-color-picker' );
|
||||
wp_enqueue_script( 'wp-color-picker' );
|
||||
|
||||
/**
|
||||
* Registers and enqueues the dashboard stylesheet.
|
||||
*
|
||||
* - Bugfix: Stylesheets: minify to shrink the carbon footprint, increase speed and implement best practice, thanks to @docteurfitness issue report.
|
||||
*
|
||||
* @since 2.5.5
|
||||
*
|
||||
* @reporter @docteurfitness
|
||||
* @link https://wordpress.org/support/topic/simply-speed-optimisation/
|
||||
*
|
||||
* See the public stylesheet enqueuing:
|
||||
* @see class/init.php
|
||||
*
|
||||
* added version # after changes started to settings.css from 2.1.2 on.
|
||||
* automated update of version number for cache busting.
|
||||
* No need to use '-styles' in the handle, as '-css' is appended automatically.
|
||||
*/
|
||||
if ( true === PRODUCTION_ENV ) {
|
||||
|
||||
wp_register_style( 'footnotes-admin', plugins_url( 'footnotes/css/settings.min.css' ), array(), C_STR_FOOTNOTES_VERSION );
|
||||
|
||||
} else {
|
||||
|
||||
wp_register_style( 'footnotes-admin', plugins_url( 'footnotes/css/settings.css' ), array(), C_STR_FOOTNOTES_VERSION );
|
||||
|
||||
}
|
||||
|
||||
wp_enqueue_style( 'footnotes-admin' );
|
||||
}
|
||||
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
|
||||
/**
|
||||
* Displays the content of specific sub page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public function display_content() {
|
||||
$this->append_scripts();
|
||||
|
||||
// TODO: add nonce verification.
|
||||
|
||||
// Get the current section.
|
||||
reset( $this->a_arr_sections );
|
||||
$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 ];
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
// 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->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' : '',
|
||||
Footnotes_Layout_Init::C_STR_MAIN_MENU_SLUG,
|
||||
$l_str_id,
|
||||
$l_arr_description['title']
|
||||
);
|
||||
}
|
||||
echo '</h2><br/>';
|
||||
|
||||
if ( $l_bool_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( $l_arr_active_section['id'] );
|
||||
do_meta_boxes( $l_arr_active_section['id'], 'main', null );
|
||||
|
||||
// Add submit button to active section if defined.
|
||||
if ( $l_arr_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->a_str_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.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return bool
|
||||
*/
|
||||
private function save_settings() {
|
||||
$l_arr_new_settings = array();
|
||||
|
||||
// TODO: add nonce verification.
|
||||
|
||||
// Get current section.
|
||||
reset( $this->a_arr_sections );
|
||||
$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 ( Footnotes_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 ] = '';
|
||||
}
|
||||
}
|
||||
// Update settings.
|
||||
return Footnotes_Settings::instance()->save_options( $l_arr_active_section['container'], $l_arr_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
|
||||
*/
|
||||
public function description() {
|
||||
// Default no description will be displayed.
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads specific setting and returns an array with the keys [id, name, value].
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param string $p_str_setting_key_name Settings Array key name.
|
||||
* @return array Contains Settings ID, Settings Name and Settings Value.
|
||||
*
|
||||
* @since 2.5.11 Remove escapement function.
|
||||
* When refactoring the codebase after 2.5.8, all and every output was escaped.
|
||||
* After noticing that the plugin was broken, all escapement functions were removed.
|
||||
* @link https://github.com/markcheret/footnotes/pull/50/commits/25c3f2f12eb5de1079e9215bf624ec4289b095a5
|
||||
* @link https://github.com/markcheret/footnotes/pull/50#issuecomment-787624123
|
||||
* In that process, this instance of esc_attr() was removed too, so the plugin was
|
||||
* broken again.
|
||||
* @link https://github.com/markcheret/footnotes/pull/50/commits/25c3f2f12eb5de1079e9215bf624ec4289b095a5#diff-a8ed6e859c32a18fc10bbbad3b4dd8ce7f43f2378d29471c7638e314ab30f1bdL349-L354
|
||||
*
|
||||
* @since 2.5.15 To fix it, the data was escaped in add_select_box() instead.
|
||||
* @since 2.6.1 Restore esc_attr() in load_setting().
|
||||
* @see add_select_box()
|
||||
* This is the only instance of esc_|kses|sanitize in the pre-2.5.11 codebase.
|
||||
* Removing this did not fix the quotation mark backslash escapement bug.
|
||||
*/
|
||||
protected function load_setting( $p_str_setting_key_name ) {
|
||||
// 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['value'] = esc_attr( Footnotes_Settings::instance()->get( $p_str_setting_key_name ) );
|
||||
return $p_arr_return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a line break to start a new line.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string
|
||||
*/
|
||||
protected function add_newline() {
|
||||
return '<br/>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a line break to have a space between two lines.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string
|
||||
*/
|
||||
protected function add_line_space() {
|
||||
return '<br/><br/>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a simple text inside html <span> text.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param string $p_str_text Message to be surrounded with simple html tag (span).
|
||||
* @return string
|
||||
*/
|
||||
protected function add_text( $p_str_text ) {
|
||||
return sprintf( '<span>%s</span>', $p_str_text );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html tag for an input/select label.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param string $p_str_setting_name Name of the Settings key to connect the Label with the input/select field.
|
||||
* @param string $p_str_caption Label caption.
|
||||
* @return string
|
||||
*/
|
||||
protected function add_label( $p_str_setting_name, $p_str_caption ) {
|
||||
if ( empty( $p_str_caption ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove the colon causing localization issues with French, and with
|
||||
* languages not using punctuation at all, and with languages using other
|
||||
* punctuation marks instead of colon, e.g. Greek using a raised dot.
|
||||
* In French, colon is preceded by a space, forcibly non-breaking, and
|
||||
* narrow per new school.
|
||||
* Add colon to label strings for inclusion in localization. Colon after
|
||||
* label is widely preferred best practice, mandatory per
|
||||
* [style guides](https://softwareengineering.stackexchange.com/questions/234546/colons-in-internationalized-ui).
|
||||
*/
|
||||
return sprintf( '<label for="%s">%s</label>', $p_str_setting_name, $p_str_caption );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html tag for an input [type = text].
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param string $p_str_setting_name Name of the Settings key to pre load the input field.
|
||||
* @param int $p_str_max_length Maximum length of the input, default 999 characters.
|
||||
* @param bool $p_bool_readonly Set the input to be read only, default false.
|
||||
* @param bool $p_bool_hidden Set the input to be hidden, default false.
|
||||
* @return string
|
||||
*/
|
||||
protected function add_text_box( $p_str_setting_name, $p_str_max_length = 999, $p_bool_readonly = false, $p_bool_hidden = false ) {
|
||||
$l_str_style = '';
|
||||
// Collect data for given settings field.
|
||||
$l_arr_data = $this->load_setting( $p_str_setting_name );
|
||||
if ( $p_bool_hidden ) {
|
||||
$l_str_style .= 'display:none;';
|
||||
}
|
||||
return sprintf(
|
||||
'<input type="text" name="%s" id="%s" maxlength="%d" style="%s" value="%s" %s/>',
|
||||
$l_arr_data['name'],
|
||||
$l_arr_data['id'],
|
||||
$p_str_max_length,
|
||||
$l_str_style,
|
||||
$l_arr_data['value'],
|
||||
$p_bool_readonly ? 'readonly="readonly"' : ''
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html tag for an input [type = checkbox].
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param string $p_str_setting_name Name of the Settings key to pre load the input field.
|
||||
* @return string
|
||||
*/
|
||||
protected function add_checkbox( $p_str_setting_name ) {
|
||||
// Collect data for given settings field.
|
||||
$l_arr_data = $this->load_setting( $p_str_setting_name );
|
||||
return sprintf(
|
||||
'<input type="checkbox" name="%s" id="%s" %s/>',
|
||||
$l_arr_data['name'],
|
||||
$l_arr_data['id'],
|
||||
Footnotes_Convert::to_bool( $l_arr_data['value'] ) ? 'checked="checked"' : ''
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html tag for a select box.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* - Bugfix: Dashboard: Referrers and tooltips: Backlink symbol: debug select box by reverting identity check to equality check, thanks to @lolzim bug report.
|
||||
*
|
||||
* @reporter @lolzim
|
||||
*
|
||||
* @since 2.5.13
|
||||
* @param string $p_str_setting_name Name of the Settings key to pre select the current value.
|
||||
* @param array $p_arr_options Possible options to be selected.
|
||||
* @return string
|
||||
*
|
||||
* @since 2.5.15 Bugfix: Dashboard: General settings: Footnote start and end short codes: debug select box for shortcodes with pointy brackets.
|
||||
* @since 2.6.1 Restore esc_attr() in load_setting(), remove htmlspecialchars() here.
|
||||
*/
|
||||
protected function add_select_box( $p_str_setting_name, $p_arr_options ) {
|
||||
// Collect data for given settings field.
|
||||
$l_arr_data = $this->load_setting( $p_str_setting_name );
|
||||
$l_str_options = '';
|
||||
|
||||
// Loop through all array keys.
|
||||
foreach ( $p_arr_options as $l_str_value => $l_str_caption ) {
|
||||
$l_str_options .= sprintf(
|
||||
'<option value="%s" %s>%s</option>',
|
||||
$l_str_value,
|
||||
// Only check for equality, not identity, WRT backlink symbol arrows.
|
||||
// phpcs:disable WordPress.PHP.StrictComparisons.LooseComparison
|
||||
$l_str_value == $l_arr_data['value'] ? 'selected' : '',
|
||||
// phpcs:enable WordPress.PHP.StrictComparisons.LooseComparison
|
||||
$l_str_caption
|
||||
);
|
||||
}
|
||||
return sprintf(
|
||||
'<select name="%s" id="%s">%s</select>',
|
||||
$l_arr_data['name'],
|
||||
$l_arr_data['id'],
|
||||
$l_str_options
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html tag for a text area.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param string $p_str_setting_name Name of the Settings key to pre fill the text area.
|
||||
* @return string
|
||||
*/
|
||||
protected function add_textarea( $p_str_setting_name ) {
|
||||
// Collect data for given settings field.
|
||||
$l_arr_data = $this->load_setting( $p_str_setting_name );
|
||||
return sprintf(
|
||||
'<textarea name="%s" id="%s">%s</textarea>',
|
||||
$l_arr_data['name'],
|
||||
$l_arr_data['id'],
|
||||
$l_arr_data['value']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html tag for an input [type = text] with color selection class.
|
||||
*
|
||||
* @since 1.5.6
|
||||
* @param string $p_str_setting_name Name of the Settings key to pre load the input field.
|
||||
* @return string
|
||||
*/
|
||||
protected function add_color_selection( $p_str_setting_name ) {
|
||||
// Collect data for given settings field.
|
||||
$l_arr_data = $this->load_setting( $p_str_setting_name );
|
||||
return sprintf(
|
||||
'<input type="text" name="%s" id="%s" class="footnotes-color-picker" value="%s"/>',
|
||||
$l_arr_data['name'],
|
||||
$l_arr_data['id'],
|
||||
$l_arr_data['value']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the html tag for an input [type = num].
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param string $p_str_setting_name Name of the Settings key to pre load the input field.
|
||||
* @param int $p_in_min Minimum value.
|
||||
* @param int $p_int_max Maximum value.
|
||||
* @param bool $p_bool_deci true if 0.1 steps and floating to string, false if integer (default).
|
||||
* @return string
|
||||
*
|
||||
* Edited:
|
||||
* @since 2.1.4 step argument and number_format() to allow decimals ..
|
||||
*/
|
||||
protected function add_num_box( $p_str_setting_name, $p_in_min, $p_int_max, $p_bool_deci = false ) {
|
||||
// Collect data for given settings field.
|
||||
$l_arr_data = $this->load_setting( $p_str_setting_name );
|
||||
|
||||
if ( $p_bool_deci ) {
|
||||
$l_str_value = number_format( floatval( $l_arr_data['value'] ), 1 );
|
||||
return sprintf(
|
||||
'<input type="number" name="%s" id="%s" value="%s" step="0.1" min="%d" max="%d"/>',
|
||||
$l_arr_data['name'],
|
||||
$l_arr_data['id'],
|
||||
$l_str_value,
|
||||
$p_in_min,
|
||||
$p_int_max
|
||||
);
|
||||
} else {
|
||||
return sprintf(
|
||||
'<input type="number" name="%s" id="%s" value="%d" min="%d" max="%d"/>',
|
||||
$l_arr_data['name'],
|
||||
$l_arr_data['id'],
|
||||
$l_arr_data['value'],
|
||||
$p_in_min,
|
||||
$p_int_max
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,67 +0,0 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName, WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
/**
|
||||
* Footnotes_Hooks class
|
||||
*
|
||||
* @package footnotes
|
||||
* @subpackage WPDashboard
|
||||
* @since 1.5.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Registers all WordPress hooks and executes them on demand.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class Footnotes_Hooks {
|
||||
|
||||
/**
|
||||
* Registers all WordPress hooks.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static function register_hooks() {
|
||||
register_activation_hook( dirname( __FILE__ ) . '/../footnotes.php', array( 'Footnotes_Hooks', 'activate_plugin' ) );
|
||||
register_deactivation_hook( dirname( __FILE__ ) . '/../footnotes.php', array( 'Footnotes_Hooks', 'deactivate_plugin' ) );
|
||||
register_uninstall_hook( dirname( __FILE__ ) . '/../footnotes.php', array( 'Footnotes_Hooks', 'uninstall_plugin' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes when the Plugin is activated.
|
||||
*
|
||||
* Currently a no-op placeholder.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static function activate_plugin() {
|
||||
// Currently unused.
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes when the Plugin is deactivated.
|
||||
*
|
||||
* Currently a no-op placeholder.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static function deactivate_plugin() {
|
||||
// Currently unused.
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the Plugin links for display in the dashboard “Plugins” page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param array $plugin_links The WP-default set of links to display.
|
||||
* @return string[] The full set of links to display.
|
||||
*/
|
||||
public static function get_plugin_links( array $plugin_links ): array {
|
||||
// Append link to the WordPress Plugin page.
|
||||
$plugin_links[] = sprintf( '<a href="https://wordpress.org/support/plugin/footnotes" target="_blank">%s</a>', __( 'Support', 'footnotes' ) );
|
||||
// Append link to the settings page.
|
||||
$plugin_links[] = sprintf( '<a href="%s">%s</a>', admin_url( 'options-general.php?page=footnotes' ), __( 'Settings', 'footnotes' ) );
|
||||
// Append link to the PayPal donate function.
|
||||
$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 new links.
|
||||
return $plugin_links;
|
||||
}
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName
|
||||
/**
|
||||
* Loads text domain of current or default language for localization.
|
||||
*
|
||||
* @filesource
|
||||
* @package footnotes
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @since 2.0.0 Bugfix: Localization: correct function call apply_filters() with all required arguments after PHP 7.1 promoted warning to error, thanks to @matkus2 bug report and code contribution.
|
||||
* @since 2.1.6 Bugfix: Localization: conform to WordPress plugin language file name scheme, thanks to @nikelaos bug report.
|
||||
*/
|
||||
|
||||
require_once dirname( __FILE__ ) . '/config.php';
|
||||
|
||||
/**
|
||||
* Loads text domain of current or default language for localization.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class Footnotes_Language {
|
||||
|
||||
/**
|
||||
* Register WordPress Hook.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static function register_hooks() {
|
||||
add_action( 'plugins_loaded', array( 'Footnotes_Language', 'load_text_domain' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the text domain for current WordPress language if exists.
|
||||
* Otherwise fallback "en_GB" will be loaded.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
*
|
||||
* - Bugfix: Correct function call apply_filters() with all required arguments after PHP 7.1 promoted warning to error, thanks to @matkus2 bug report and code contribution.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @contributor @matkus2
|
||||
* @link https://wordpress.org/support/topic/error-missing-parameter-if-using-php-7-1-or-later/
|
||||
*
|
||||
* Add 3rd (empty) argument in apply_filters() to prevent PHP from throwing an error.
|
||||
* “Fatal error: Uncaught ArgumentCountError: Too few arguments to function apply_filters()”
|
||||
*
|
||||
* Yet get_locale() is defined w/o parameters in wp-includes/l10n.php:30, and
|
||||
* apply_filters() is defined as apply_filters( $tag, $value ) in wp-includes/plugin.php:181.
|
||||
* @link https://developer.wordpress.org/reference/functions/apply_filters/
|
||||
*
|
||||
* But apply_filters() is defined with a 3rd parameter (and w/o the first one) in
|
||||
* wp-includes/class-wp-hook.php:264, as public function apply_filters( $value, $args ).
|
||||
*
|
||||
* Taking it all together, probably the full function definition would be
|
||||
* public function apply_filters( $tag, $value, $args ).
|
||||
* In the case of get_locale(), $args is empty.
|
||||
*
|
||||
* The bug was lurking in WP. PHP 7.1 promoted the warning to an error.
|
||||
* @link https://www.php.net/manual/en/migration71.incompatible.php
|
||||
* @link https://www.php.net/manual/en/migration71.incompatible.php#migration71.incompatible.too-few-arguments-exception
|
||||
*/
|
||||
public static function load_text_domain() {
|
||||
|
||||
// If language file with localization exists.
|
||||
if ( self::load( apply_filters( 'plugin_locale', get_locale(), '' ) ) ) {
|
||||
return;
|
||||
}
|
||||
// Else fall back to British English.
|
||||
self::load( 'en_GB' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a specific text domain.
|
||||
*
|
||||
* @since 1.5.1
|
||||
* @param string $p_str_language_code Language Code to load a specific text domain.
|
||||
* @return bool
|
||||
*
|
||||
*
|
||||
* - Bugfix: Localization: conform to WordPress plugin language file name scheme, thanks to @nikelaos bug report.
|
||||
*
|
||||
* @since 2.1.6
|
||||
*
|
||||
* @reporter @nikelaos
|
||||
* @link https://wordpress.org/support/topic/more-feature-ideas/
|
||||
*
|
||||
* That is done by using load_plugin_textdomain().
|
||||
* “The .mo file should be named based on the text domain with a dash, and then the locale exactly.”
|
||||
* @see wp-includes/l10n.php:857
|
||||
*/
|
||||
private static function load( $p_str_language_code ) {
|
||||
return load_plugin_textdomain(
|
||||
Footnotes_Config::C_STR_PLUGIN_NAME,
|
||||
false,
|
||||
Footnotes_Config::C_STR_PLUGIN_NAME . '/languages'
|
||||
);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,86 +0,0 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName
|
||||
/**
|
||||
* Widget base.
|
||||
*
|
||||
* @filesource
|
||||
* @package footnotes
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @since 1.6.4 Update: replace deprecated function WP_Widget() with recommended __construct(), thanks to @dartiss code contribution.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base Class for all Plugin Widgets. Registers each Widget to WordPress.
|
||||
* The following Methods MUST be overwritten in each sub class:
|
||||
* **public function widget($args, $instance)** -> echo the Widget Content
|
||||
* **public function form($instance)** -> echo the Settings of the Widget
|
||||
*
|
||||
* @author Stefan Herndler
|
||||
* @since 1.5.0
|
||||
*/
|
||||
abstract class Footnotes_Widget_Base extends WP_Widget {
|
||||
|
||||
/**
|
||||
* Returns an unique ID as string used for the Widget Base ID.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function get_id();
|
||||
|
||||
/**
|
||||
* Returns the Public name of child Widget to be displayed in the Configuration page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function get_name();
|
||||
|
||||
/**
|
||||
* Returns the Description of the child widget.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function get_description();
|
||||
|
||||
/**
|
||||
* Returns the width of the Widget. Default width is 250 pixel.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return int
|
||||
*/
|
||||
protected function get_widget_width() {
|
||||
return 250;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Constructor. Registers the child Widget to WordPress.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* - Update: replace deprecated function WP_Widget() with recommended __construct(), thanks to @dartiss code contribution.
|
||||
*
|
||||
* @since 1.6.4
|
||||
* @contributor @dartiss
|
||||
* @link https://plugins.trac.wordpress.org/browser/footnotes/trunk/class/widgets/base.php?rev=1445720
|
||||
* “The called constructor method for WP_Widget in Footnotes_Widget_ReferenceContainer is deprecated since version 4.3.0! Use __construct() instead.”
|
||||
*/
|
||||
public function __construct() {
|
||||
$l_arr_widget_options = array(
|
||||
'classname' => __CLASS__,
|
||||
'description' => $this->get_description(),
|
||||
);
|
||||
$l_arr_control_options = array(
|
||||
'id_base' => strtolower( $this->get_id() ),
|
||||
'width' => $this->get_widget_width(),
|
||||
);
|
||||
// Registers the Widget.
|
||||
parent::__construct(
|
||||
strtolower( $this->get_id() ), // Unique ID for the widget, has to be lowercase.
|
||||
$this->get_name(), // Plugin name to be displayed.
|
||||
$l_arr_widget_options, // Optional Widget Options.
|
||||
$l_arr_control_options // Optional Widget Control Options.
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName, WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
/**
|
||||
* Includes the Plugin Widget to put the Reference Container to the Widget area.
|
||||
*
|
||||
* @filesource
|
||||
* @package footnotes
|
||||
* @since 1.5.0
|
||||
*/
|
||||
|
||||
require_once dirname( __FILE__, 2 ) . '/config.php';
|
||||
require_once dirname( __FILE__, 2 ) . '/settings.php';
|
||||
require_once dirname( __FILE__ ) . '/base.php';
|
||||
|
||||
/**
|
||||
* Registers a Widget to put the Reference Container to the widget area.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class Footnotes_Widget_Reference_Container extends Footnotes_Widget_Base {
|
||||
|
||||
/**
|
||||
* Returns an unique ID as string used for the Widget Base ID.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string
|
||||
*/
|
||||
protected function get_id() {
|
||||
return 'footnotes_widget';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Public name of the Widget to be displayed in the Configuration page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string
|
||||
*/
|
||||
protected function get_name() {
|
||||
return Footnotes_Config::C_STR_PLUGIN_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Description of the child widget.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @return string
|
||||
*
|
||||
* Edit: curly quotes 2.2.0
|
||||
*/
|
||||
protected function get_description() {
|
||||
return __( 'The widget defines the position of the reference container if set to “widget area”.', 'footnotes' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the Settings of the Widget.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param mixed $instance The instance of the widget.
|
||||
* @return void
|
||||
*
|
||||
* Edit: curly quotes 2.2.0
|
||||
*/
|
||||
public function form( $instance ) {
|
||||
echo __( 'The widget defines the position of the reference container if set to “widget area”.', 'footnotes' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the Content of the Widget.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param mixed $args The widget's arguments.
|
||||
* @param mixed $instance The instance of the widget.
|
||||
*/
|
||||
public function widget( $args, $instance ) {
|
||||
global $footnotes;
|
||||
// Reference container positioning is set to "widget area".
|
||||
if ( 'widget' === Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_REFERENCE_CONTAINER_POSITION ) ) {
|
||||
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo $footnotes->a_obj_task->reference_container();
|
||||
// phpcs:enable
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName
|
||||
/**
|
||||
* Includes the Class to handle the WYSIWYG-Buttons.
|
||||
*
|
||||
* @filesource
|
||||
* @package footnotes
|
||||
* @since 1.5.0
|
||||
*/
|
||||
|
||||
require_once dirname( __FILE__ ) . '/config.php';
|
||||
require_once dirname( __FILE__ ) . '/settings.php';
|
||||
require_once dirname( __FILE__ ) . '/template.php';
|
||||
|
||||
/**
|
||||
* Handles the WSYIWYG-Buttons.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
class Footnotes_WYSIWYG {
|
||||
|
||||
/**
|
||||
* Registers Button hooks.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* - Bugfix: Editor buttons: debug button by reverting name change in PHP file while JS file and HTML template remained unsynced, thanks to @gova bug report.
|
||||
*
|
||||
* @reporter @gova
|
||||
* @link https://wordpress.org/support/topic/back-end-footnotes-not-working-400-bad-erro/
|
||||
*
|
||||
* @since 2.6.5
|
||||
* @return void
|
||||
*/
|
||||
public static function register_hooks() {
|
||||
add_filter( 'mce_buttons', array( 'Footnotes_WYSIWYG', 'new_visual_editor_button' ) );
|
||||
add_action( 'admin_print_footer_scripts', array( 'Footnotes_WYSIWYG', 'new_plain_text_editor_button' ) );
|
||||
|
||||
add_filter( 'mce_external_plugins', array( 'Footnotes_WYSIWYG', 'include_scripts' ) );
|
||||
|
||||
// phpcs:disable
|
||||
// 'footnotes_getTags' must match its instance in wysiwyg-editor.js.
|
||||
// 'footnotes_getTags' must match its instance in editor-button.html.
|
||||
add_action( 'wp_ajax_nopriv_footnotes_getTags', array( 'Footnotes_WYSIWYG', 'ajax_callback' ) );
|
||||
add_action( 'wp_ajax_footnotes_getTags', array( 'Footnotes_WYSIWYG', 'ajax_callback' ) );
|
||||
// phpcs:enable
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Append a new Button to the WYSIWYG editor of Posts and Pages.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param array $p_arr_buttons pre defined Buttons from WordPress.
|
||||
* @return array
|
||||
*/
|
||||
public static function new_visual_editor_button( $p_arr_buttons ) {
|
||||
array_push( $p_arr_buttons, Footnotes_Config::C_STR_PLUGIN_NAME );
|
||||
return $p_arr_buttons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new button to the plain text editor.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static function new_plain_text_editor_button() {
|
||||
$l_obj_template = new Footnotes_Template( Footnotes_Template::C_STR_DASHBOARD, 'editor-button' );
|
||||
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo $l_obj_template->get_content();
|
||||
// phpcs:enable
|
||||
}
|
||||
|
||||
/**
|
||||
* Includes the Plugins WYSIWYG editor script.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @param array $p_arr_plugins Scripts to be included to the editor.
|
||||
* @return array
|
||||
*/
|
||||
public static function include_scripts( $p_arr_plugins ) {
|
||||
$p_arr_plugins[ Footnotes_Config::C_STR_PLUGIN_NAME ] = plugins_url( '/../admin/js/wysiwyg-editor' . ( ( PRODUCTION_ENV ) ? '.min' : '' ) . '.js', __FILE__ );
|
||||
return $p_arr_plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX Callback function when the Footnotes Button is clicked. Either in the Plain text or Visual editor.
|
||||
* Returns an JSON encoded array with the Footnotes start and end short code.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public static function ajax_callback() {
|
||||
// Get start and end tag for the footnotes short code.
|
||||
$l_str_starting_tag = Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_START );
|
||||
$l_str_ending_tag = Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_END );
|
||||
if ( 'userdefined' === $l_str_starting_tag || 'userdefined' === $l_str_ending_tag ) {
|
||||
$l_str_starting_tag = Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_START_USER_DEFINED );
|
||||
$l_str_ending_tag = Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_SHORT_CODE_END_USER_DEFINED );
|
||||
}
|
||||
echo wp_json_encode(
|
||||
array(
|
||||
'start' => htmlspecialchars( $l_str_starting_tag ),
|
||||
'end' => htmlspecialchars( $l_str_ending_tag ),
|
||||
)
|
||||
);
|
||||
exit;
|
||||
}
|
||||
}
|
Reference in a new issue