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
137
src/admin/class-footnotes-admin.php
Normal file
137
src/admin/class-footnotes-admin.php
Normal file
|
@ -0,0 +1,137 @@
|
|||
<?php
|
||||
/**
|
||||
* The admin-specific functionality of the plugin.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*
|
||||
* @package footnotes
|
||||
* @subpackage footnotes/admin
|
||||
*/
|
||||
|
||||
/**
|
||||
* The admin-specific functionality of the plugin.
|
||||
*
|
||||
* Defines the plugin name, version, and enqueues all admin-specific stylesheets
|
||||
* and JavaScript.
|
||||
*
|
||||
* @package footnotes
|
||||
* @subpackage footnotes/admin
|
||||
*/
|
||||
class Footnotes_Admin {
|
||||
|
||||
/**
|
||||
* The ID of this plugin.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access private
|
||||
* @var string $plugin_name The ID of this plugin.
|
||||
*/
|
||||
private $plugin_name;
|
||||
|
||||
/**
|
||||
* The version of this plugin.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access private
|
||||
* @var string $version The current version of this plugin.
|
||||
*/
|
||||
private $version;
|
||||
|
||||
/**
|
||||
* Initialize the class and set its properties.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @param string $plugin_name The name of this plugin.
|
||||
* @param string $version The version of this plugin.
|
||||
*/
|
||||
public function __construct( $plugin_name, $version ) {
|
||||
|
||||
$this->plugin_name = $plugin_name;
|
||||
$this->version = $version;
|
||||
|
||||
$this->load_dependencies();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the required admin-specific dependencies.
|
||||
*
|
||||
* Include the following files that provide the admin-specific functionality
|
||||
* of this plugin:
|
||||
*
|
||||
* - `Footnotes_WYSIWYG`. TODO
|
||||
* - `Footnotes_Layout_Settings`. TODO
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access private
|
||||
*/
|
||||
private function load_dependencies() {
|
||||
// TODO: neaten up and document once placements and names are settled.
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-footnotes-wysiwyg.php';
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/layout/class-footnotes-layout-init.php';
|
||||
|
||||
new Footnotes_Layout_Init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the stylesheets for the admin area.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public function enqueue_styles() {
|
||||
|
||||
wp_enqueue_style(
|
||||
$this->plugin_name,
|
||||
plugin_dir_url( __FILE__ ) . 'css/settings' . ( ( PRODUCTION_ENV ) ? '.min' : '' ) . '.css',
|
||||
array(),
|
||||
( PRODUCTION_ENV ) ? $this->version : filemtime(
|
||||
plugin_dir_path(
|
||||
dirname( __FILE__ )
|
||||
) . 'css/settings.css'
|
||||
),
|
||||
'all'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the JavaScript for the admin area.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public function enqueue_scripts() {
|
||||
|
||||
wp_enqueue_script(
|
||||
$this->plugin_name,
|
||||
plugin_dir_url( __FILE__ ) . 'js/wysiwyg-editor' . ( ( PRODUCTION_ENV ) ? '.min' : '' ) . '.js',
|
||||
array(),
|
||||
( PRODUCTION_ENV ) ? $this->version : filemtime(
|
||||
plugin_dir_path(
|
||||
dirname( __FILE__ )
|
||||
) . 'js/wysiwyg-editor.js'
|
||||
),
|
||||
false
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the Plugin links for display in the dashboard Plugins page.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @since 2.8.0 Moved into `Footnote_Admin` class.
|
||||
* @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,15 +1,16 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName
|
||||
<?php // phpcs:disable Squiz.Commenting.FileComment.Missing
|
||||
/**
|
||||
* Includes the Class to handle the WYSIWYG-Buttons.
|
||||
* File provides WYSIWYG editor integration.
|
||||
*
|
||||
* @filesource
|
||||
* @package footnotes
|
||||
* @since 1.5.0
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @package footnotes
|
||||
* @subpackage footnotes/admin
|
||||
*/
|
||||
|
||||
require_once dirname( __FILE__ ) . '/config.php';
|
||||
require_once dirname( __FILE__ ) . '/settings.php';
|
||||
require_once dirname( __FILE__ ) . '/template.php';
|
||||
require_once dirname( __FILE__, 2 ) . '/includes/class-footnotes-config.php';
|
||||
require_once dirname( __FILE__, 2 ) . '/includes/class-footnotes-settings.php';
|
||||
require_once dirname( __FILE__, 2 ) . '/includes/class-footnotes-template.php';
|
||||
|
||||
/**
|
||||
* Handles the WSYIWYG-Buttons.
|
|
@ -1,4 +1,4 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
<?php // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
/**
|
||||
* Includes Layout Engine for the admin dashboard.
|
||||
*
|
||||
|
@ -13,11 +13,8 @@
|
|||
*
|
||||
* @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';
|
||||
|
||||
require_once dirname( __FILE__ ) . '/class-footnotes-layout-init.php';
|
||||
|
||||
/**
|
||||
* Layout Engine for the administration dashboard.
|
||||
|
@ -214,7 +211,7 @@ abstract class Footnotes_Layout_Engine {
|
|||
* 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 ) {
|
||||
/*if ( true === PRODUCTION_ENV ) {
|
||||
|
||||
wp_register_style( 'footnotes-admin', plugins_url( 'footnotes/css/settings.min.css' ), array(), C_STR_FOOTNOTES_VERSION );
|
||||
|
||||
|
@ -224,7 +221,7 @@ abstract class Footnotes_Layout_Engine {
|
|||
|
||||
}
|
||||
|
||||
wp_enqueue_style( 'footnotes-admin' );
|
||||
wp_enqueue_style( 'footnotes-admin' );*/
|
||||
}
|
||||
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
|
|
@ -1,4 +1,4 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
<?php // phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
/**
|
||||
* Includes the Plugin settings menu.
|
||||
*
|
||||
|
@ -7,8 +7,8 @@
|
|||
* @since 1.5.0
|
||||
*/
|
||||
|
||||
require_once dirname( __FILE__, 2) . '/settings.php';
|
||||
require_once dirname( __FILE__ ) . '/subpage-main.php';
|
||||
require_once dirname( __FILE__, 3 ) . '/includes/class-footnotes-settings.php';
|
||||
require_once dirname( __FILE__ ) . '/class-footnotes-layout-settings.php';
|
||||
|
||||
/**
|
||||
* Handles the Settings interface of the Plugin.
|
|
@ -1,4 +1,4 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName
|
||||
<?php // phpcs:disable Squiz.Commenting.FileComment.Missing
|
||||
/**
|
||||
* Includes the Plugin Class to display all Settings.
|
||||
*
|
||||
|
@ -40,12 +40,8 @@
|
|||
* @since 2.5.0 Shortcode syntax validation: add more information around the setting, thanks to @andreasra
|
||||
* @link https://wordpress.org/support/topic/warning-unbalanced-footnote-start-tag-short-code-before/
|
||||
*/
|
||||
|
||||
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__, 2) . '/template.php';
|
||||
require_once dirname( __FILE__ ) . '/layout.php';
|
||||
|
||||
require_once dirname( __FILE__ ) . '/class-footnotes-layout-engine.php';
|
||||
|
||||
/**
|
||||
* Displays and handles all Settings of the Plugin.
|
|
@ -28,8 +28,6 @@
|
|||
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
// If this file is called directly, abort.
|
||||
if ( ! defined( 'WPINC' ) ) {
|
||||
die;
|
||||
|
@ -89,9 +87,5 @@ function run_footnotes() {
|
|||
global $footnotes;
|
||||
$footnotes = new Footnotes();
|
||||
$footnotes->run();
|
||||
|
||||
// Add the links to the dashboard plugins page.
|
||||
// TODO: Move this somewhere more appropriate.
|
||||
add_filter( 'plugin_action_links_footnotes/footnotes.php', array( 'Footnotes_Hooks', 'get_plugin_links' ), 10, 2 );
|
||||
}
|
||||
run_footnotes();
|
||||
|
|
|
@ -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,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'
|
||||
);
|
||||
}
|
||||
}
|
275
src/public/class-footnotes-public.php
Normal file
275
src/public/class-footnotes-public.php
Normal file
|
@ -0,0 +1,275 @@
|
|||
<?php
|
||||
/**
|
||||
* The public-facing functionality of the plugin.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*
|
||||
* @package footnotes
|
||||
* @subpackage footnotes/public
|
||||
*/
|
||||
|
||||
/**
|
||||
* The public-facing functionality of the plugin.
|
||||
*
|
||||
* Defines the plugin name, version, and enqueues all public-facing stylesheets
|
||||
* and JavaScript.
|
||||
*
|
||||
* @package footnotes
|
||||
* @subpackage footnotes/public
|
||||
*/
|
||||
class Footnotes_Public {
|
||||
|
||||
/**
|
||||
* The ID of this plugin.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access private
|
||||
* @var string $plugin_name The ID of this plugin.
|
||||
*/
|
||||
private $plugin_name;
|
||||
|
||||
/**
|
||||
* The version of this plugin.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access private
|
||||
* @var string $version The current version of this plugin.
|
||||
*/
|
||||
private $version;
|
||||
|
||||
/**
|
||||
* The Plugin task.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @since 2.8.0 Moved to `Footnotes_Public` class.
|
||||
* @var Task $task The Plugin task.
|
||||
*/
|
||||
public $a_obj_task = null;
|
||||
|
||||
/**
|
||||
* Flag for using tooltips.
|
||||
*
|
||||
* @since 2.4.0
|
||||
* @since 2.8.0 Moved to `Footnotes_Public` class.
|
||||
* @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.
|
||||
*
|
||||
* @since 2.1.1
|
||||
* @since 2.8.0 Moved to `Footnotes_Public` class.
|
||||
* @var bool
|
||||
*/
|
||||
public static $a_bool_alternative_tooltips_enabled = false;
|
||||
|
||||
/**
|
||||
* Allows to determine whether AMP compatibility mode is enabled.
|
||||
*
|
||||
* @since 2.6.0 (release)
|
||||
* @since 2.8.0 Moved to `Footnotes_Public` class.
|
||||
* @var bool
|
||||
*/
|
||||
public static $a_bool_amp_enabled = false;
|
||||
|
||||
/**
|
||||
* Allows to determine the script mode among jQuery or plain JS.
|
||||
*
|
||||
* @since 2.5.6
|
||||
* @since 2.8.0 Moved to `Footnotes_Public` class.
|
||||
* @var str 'js' Plain JavaScript.
|
||||
* 'jquery' Use jQuery libraries.
|
||||
*/
|
||||
public static $a_str_script_mode = 'js';
|
||||
|
||||
/**
|
||||
* Initialize the class and set its properties.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @param string $plugin_name The name of this plugin.
|
||||
* @param string $version The version of this plugin.
|
||||
*/
|
||||
public function __construct( $plugin_name, $version ) {
|
||||
|
||||
$this->plugin_name = $plugin_name;
|
||||
$this->version = $version;
|
||||
|
||||
$this->load_dependencies();
|
||||
|
||||
// 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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the required public-facing dependencies.
|
||||
*
|
||||
* Include the following files that provide the public-facing functionality
|
||||
* of this plugin:
|
||||
*
|
||||
* - `Footnotes_Task`. TODO
|
||||
* - `Footnotes_Widget_Reference_Container`. TODO
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @access private
|
||||
*/
|
||||
private function load_dependencies() {
|
||||
// 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-settings.php';
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-footnotes-convert.php';
|
||||
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-footnotes-task.php';
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/widget/class-footnotes-widget-base.php';
|
||||
|
||||
$this->a_obj_task = new Footnotes_Task();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the stylesheets for the public-facing side of the site.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public function enqueue_styles() {
|
||||
/**
|
||||
* Enables enqueuing a new-scheme stylesheet.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* @since 2.5.5
|
||||
* @since 2.8.0 Moved into `Footnotes_Public` class.
|
||||
*/
|
||||
if ( PRODUCTION_ENV ) {
|
||||
|
||||
/**
|
||||
* Enqueues a minified united external stylesheet in production.
|
||||
*
|
||||
* The media scope argument 'all' is the default.
|
||||
* No need to use '-css' in the handle, as this is appended automatically.
|
||||
*
|
||||
* @since 2.5.5
|
||||
* @since 2.8.0 Moved into `Footnotes_Public` class.
|
||||
*/
|
||||
// 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}",
|
||||
plugin_dir_url( __FILE__ ) . "css/footnotes-{$l_str_tooltip_mode_short}brpl{$l_str_layout_mode}.min.css",
|
||||
array(),
|
||||
( PRODUCTION_ENV ) ? $this->version : filemtime(
|
||||
plugin_dir_path(
|
||||
dirname( __FILE__ )
|
||||
) . "css/footnotes-{$l_str_tooltip_mode_short}brpl{$l_str_layout_mode}.min.css"
|
||||
),
|
||||
'all'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the JavaScript for the public-facing side of the site.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public function enqueue_scripts() {
|
||||
/**
|
||||
* Enqueues the jQuery library registered by WordPress.
|
||||
*
|
||||
* As jQuery is also used for animated scrolling, 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.
|
||||
*
|
||||
* @since 2.5.6
|
||||
* @since 2.8.0 Moved into `Footnotes_Public` class.
|
||||
*/
|
||||
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 `public/js/jquery.tools.js`.
|
||||
* No '-js' in the handle, is appended automatically.
|
||||
* Deferring to the footer breaks jQuery tooltip display.
|
||||
*
|
||||
* Add versioning.
|
||||
*
|
||||
* @since 2.1.2
|
||||
* @since 2.8.0 Moved into `Footnotes_Public` class.
|
||||
*/
|
||||
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/jquery.tools' . ( ( PRODUCTION_ENV ) ? '.min' : '' ) . '.js', array(), '1.2.7.redacted.2', false );
|
||||
|
||||
/**
|
||||
* Enqueues some jQuery UI libraries registered by WordPress.
|
||||
*
|
||||
* If alternative tooltips are enabled, these libraries are not needed.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @since 2.8.0 Moved into `Footnotes_Public` class.
|
||||
*/
|
||||
wp_enqueue_script( 'jquery-ui-core' );
|
||||
wp_enqueue_script( 'jquery-ui-widget' );
|
||||
wp_enqueue_script( 'jquery-ui-position' );
|
||||
wp_enqueue_script( 'jquery-ui-tooltip' );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName, WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
<?php // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
/**
|
||||
* Includes the core function of the Plugin - Search and Replace the Footnotes.
|
||||
*
|
||||
|
@ -82,16 +82,6 @@
|
|||
* @since 2.5.14 Bugfix: Footnote delimiter short codes: fix numbering bug by cross-editor HTML escapement schema harmonization, thanks to @patrick_here @alifarahani8000 @gova bug reports.
|
||||
*/
|
||||
|
||||
// If called directly, abort.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
die;
|
||||
}
|
||||
|
||||
require_once dirname( __FILE__ ) . '/config.php';
|
||||
require_once dirname( __FILE__ ) . '/convert.php';
|
||||
require_once dirname( __FILE__ ) . '/settings.php';
|
||||
require_once dirname( __FILE__ ) . '/template.php';
|
||||
|
||||
/**
|
||||
* Searches and replaces the footnotes and generates the reference container.
|
||||
*
|
||||
|
@ -402,6 +392,22 @@ class Footnotes_Task {
|
|||
*/
|
||||
public static $a_bool_syntax_error_flag = true;
|
||||
|
||||
/**
|
||||
* Initialize the class and set its properties.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public function __construct() {
|
||||
// TODO: Reorg dependencies.
|
||||
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';
|
||||
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-footnotes-template.php';
|
||||
|
||||
// TODO: Move to `Footnotes_Loader`.
|
||||
$this->register_hooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register WordPress hooks to replace Footnotes in the content of a public page.
|
||||
*
|
||||
|
@ -421,7 +427,6 @@ class Footnotes_Task {
|
|||
* @since 2.5.1 Bugfix: Hooks: support footnotes in Popup Maker popups, thanks to @squatcher bug report.
|
||||
*/
|
||||
public function register_hooks() {
|
||||
|
||||
// Get values from settings.
|
||||
$l_int_the_title_priority = intval( Footnotes_Settings::instance()->get( Footnotes_Settings::C_INT_EXPERT_LOOKUP_THE_TITLE_PRIORITY_LEVEL ) );
|
||||
$l_int_the_content_priority = intval( Footnotes_Settings::instance()->get( Footnotes_Settings::C_INT_EXPERT_LOOKUP_THE_CONTENT_PRIORITY_LEVEL ) );
|
||||
|
@ -762,7 +767,7 @@ class Footnotes_Task {
|
|||
self::$a_bool_hard_links_enabled = Footnotes_Convert::to_bool( Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_FOOTNOTES_HARD_LINKS_ENABLE ) );
|
||||
|
||||
// Correct hard links enabled status depending on AMP compatible or alternative reference container enabled status.
|
||||
if ( Footnotes::$a_bool_amp_enabled || 'jquery' !== Footnotes::$a_str_script_mode ) {
|
||||
if ( Footnotes_Public::$a_bool_amp_enabled || 'jquery' !== Footnotes_Public::$a_str_script_mode ) {
|
||||
self::$a_bool_hard_links_enabled = true;
|
||||
}
|
||||
|
||||
|
@ -776,7 +781,7 @@ class Footnotes_Task {
|
|||
/*
|
||||
* Tooltips.
|
||||
*/
|
||||
if ( Footnotes::$a_bool_tooltips_enabled ) {
|
||||
if ( Footnotes_Public::$a_bool_tooltips_enabled ) {
|
||||
echo '.footnote_tooltip {';
|
||||
|
||||
/**
|
||||
|
@ -856,7 +861,7 @@ class Footnotes_Task {
|
|||
*
|
||||
* @since 2.2.5
|
||||
*/
|
||||
if ( ! Footnotes::$a_bool_alternative_tooltips_enabled && ! Footnotes::$a_bool_amp_enabled ) {
|
||||
if ( ! Footnotes_Public::$a_bool_alternative_tooltips_enabled && ! Footnotes_Public::$a_bool_amp_enabled ) {
|
||||
|
||||
/**
|
||||
* Dimensions of jQuery tooltips.
|
||||
|
@ -932,7 +937,7 @@ class Footnotes_Task {
|
|||
*
|
||||
* @see dev-amp-tooltips.css.
|
||||
*/
|
||||
if ( Footnotes::$a_bool_amp_enabled ) {
|
||||
if ( Footnotes_Public::$a_bool_amp_enabled ) {
|
||||
|
||||
echo 'span.footnote_referrer > span.footnote_tooltip {';
|
||||
echo 'transition-delay: ' . $l_int_fade_out_delay . 'ms;';
|
||||
|
@ -997,7 +1002,7 @@ class Footnotes_Task {
|
|||
* The script for alternative tooltips is printed formatted, not minified,
|
||||
* for transparency. It isn’t indented though (the PHP open tag neither).
|
||||
*/
|
||||
if ( Footnotes::$a_bool_alternative_tooltips_enabled ) {
|
||||
if ( Footnotes_Public::$a_bool_alternative_tooltips_enabled ) {
|
||||
|
||||
// Start internal script.
|
||||
?>
|
||||
|
@ -1727,7 +1732,7 @@ class Footnotes_Task {
|
|||
if ( ! $p_bool_hide_footnotes_text ) {
|
||||
|
||||
// Whether AMP compatibility mode is enabled.
|
||||
if ( Footnotes::$a_bool_amp_enabled ) {
|
||||
if ( Footnotes_Public::$a_bool_amp_enabled ) {
|
||||
|
||||
// Whether first clicking a referrer needs to expand the reference container.
|
||||
if ( Footnotes_Convert::to_bool( Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_REFERENCE_CONTAINER_COLLAPSE ) ) ) {
|
||||
|
@ -1740,7 +1745,7 @@ class Footnotes_Task {
|
|||
// Load 'public/partials/amp-footnote.html'.
|
||||
$l_obj_template = new Footnotes_Template( Footnotes_Template::C_STR_PUBLIC, 'amp-footnote' );
|
||||
}
|
||||
} elseif ( Footnotes::$a_bool_alternative_tooltips_enabled ) {
|
||||
} elseif ( Footnotes_Public::$a_bool_alternative_tooltips_enabled ) {
|
||||
|
||||
// Load 'public/partials/footnote-alternative.html'.
|
||||
$l_obj_template = new Footnotes_Template( Footnotes_Template::C_STR_PUBLIC, 'footnote-alternative' );
|
||||
|
@ -1964,7 +1969,7 @@ class Footnotes_Task {
|
|||
* This is equivalent to the WordPress default excerpt generation, i.e. without a
|
||||
* custom excerpt and without a delimiter. But WordPress does word count, usually 55.
|
||||
*/
|
||||
if ( Footnotes::$a_bool_tooltips_enabled && $l_bool_enable_excerpt ) {
|
||||
if ( Footnotes_Public::$a_bool_tooltips_enabled && $l_bool_enable_excerpt ) {
|
||||
$l_str_dummy_text = wp_strip_all_tags( $l_str_footnote_text );
|
||||
if ( is_int( $l_int_max_length ) && strlen( $l_str_dummy_text ) > $l_int_max_length ) {
|
||||
$l_str_excerpt_text = substr( $l_str_dummy_text, 0, $l_int_max_length );
|
||||
|
@ -1974,7 +1979,7 @@ class Footnotes_Task {
|
|||
$l_str_excerpt_text .= ' class="footnote_tooltip_continue" ';
|
||||
|
||||
// If AMP compatibility mode is enabled.
|
||||
if ( Footnotes::$a_bool_amp_enabled ) {
|
||||
if ( Footnotes_Public::$a_bool_amp_enabled ) {
|
||||
|
||||
// If the reference container is also collapsed by default.
|
||||
if ( Footnotes_Convert::to_bool( Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_REFERENCE_CONTAINER_COLLAPSE ) ) ) {
|
||||
|
@ -2097,7 +2102,7 @@ class Footnotes_Task {
|
|||
}
|
||||
|
||||
// Determine tooltip content.
|
||||
if ( Footnotes::$a_bool_tooltips_enabled ) {
|
||||
if ( Footnotes_Public::$a_bool_tooltips_enabled ) {
|
||||
$l_str_tooltip_content = $l_bool_has_tooltip_text ? $l_str_tooltip_text : $l_str_excerpt_text;
|
||||
/**
|
||||
* Ensures paragraph separation
|
||||
|
@ -2119,7 +2124,7 @@ class Footnotes_Task {
|
|||
* @since 2.5.6
|
||||
*/
|
||||
$l_str_tooltip_style = '';
|
||||
if ( Footnotes::$a_bool_alternative_tooltips_enabled && Footnotes::$a_bool_tooltips_enabled ) {
|
||||
if ( Footnotes_Public::$a_bool_alternative_tooltips_enabled && Footnotes_Public::$a_bool_tooltips_enabled ) {
|
||||
$l_int_tooltip_length = strlen( wp_strip_all_tags( $l_str_tooltip_content ) );
|
||||
if ( $l_int_tooltip_length < 70 ) {
|
||||
$l_str_tooltip_style = ' style="width: ';
|
||||
|
@ -2151,7 +2156,7 @@ class Footnotes_Task {
|
|||
$l_obj_template->reload();
|
||||
|
||||
// If tooltips are enabled but neither AMP nor alternative are.
|
||||
if ( Footnotes::$a_bool_tooltips_enabled && ! Footnotes::$a_bool_amp_enabled && ! Footnotes::$a_bool_alternative_tooltips_enabled ) {
|
||||
if ( Footnotes_Public::$a_bool_tooltips_enabled && ! Footnotes_Public::$a_bool_amp_enabled && ! Footnotes_Public::$a_bool_alternative_tooltips_enabled ) {
|
||||
|
||||
$l_int_offset_y = intval( Footnotes_Settings::instance()->get( Footnotes_Settings::C_INT_FOOTNOTES_MOUSE_OVER_BOX_OFFSET_Y ) );
|
||||
$l_int_offset_x = intval( Footnotes_Settings::instance()->get( Footnotes_Settings::C_INT_FOOTNOTES_MOUSE_OVER_BOX_OFFSET_X ) );
|
||||
|
@ -2418,7 +2423,7 @@ class Footnotes_Task {
|
|||
$l_bool_combine_identical_footnotes = Footnotes_Convert::to_bool( Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_COMBINE_IDENTICAL_FOOTNOTES ) );
|
||||
|
||||
// AMP compatibility requires a full set of AMP compatible table row templates.
|
||||
if ( Footnotes::$a_bool_amp_enabled ) {
|
||||
if ( Footnotes_Public::$a_bool_amp_enabled ) {
|
||||
|
||||
// When combining identical footnotes is turned on, another template is needed.
|
||||
if ( $l_bool_combine_identical_footnotes ) {
|
||||
|
@ -2802,7 +2807,7 @@ class Footnotes_Task {
|
|||
|
||||
// Select the reference container template.
|
||||
// Whether AMP compatibility mode is enabled.
|
||||
if ( Footnotes::$a_bool_amp_enabled ) {
|
||||
if ( Footnotes_Public::$a_bool_amp_enabled ) {
|
||||
|
||||
// Whether the reference container is collapsed by default.
|
||||
if ( Footnotes_Convert::to_bool( Footnotes_Settings::instance()->get( Footnotes_Settings::C_STR_REFERENCE_CONTAINER_COLLAPSE ) ) ) {
|
||||
|
@ -2815,7 +2820,7 @@ class Footnotes_Task {
|
|||
// Load 'public/partials/amp-reference-container.html'.
|
||||
$l_obj_template_container = new Footnotes_Template( Footnotes_Template::C_STR_PUBLIC, 'amp-reference-container' );
|
||||
}
|
||||
} elseif ( 'js' === Footnotes::$a_str_script_mode ) {
|
||||
} elseif ( 'js' === Footnotes_Public::$a_str_script_mode ) {
|
||||
|
||||
// Load 'public/partials/js-reference-container.html'.
|
||||
$l_obj_template_container = new Footnotes_Template( Footnotes_Template::C_STR_PUBLIC, 'js-reference-container' );
|
||||
|
@ -2832,7 +2837,7 @@ class Footnotes_Task {
|
|||
$l_int_scroll_up_delay = '';
|
||||
$l_int_scroll_up_duration = '';
|
||||
|
||||
if ( 'jquery' === Footnotes::$a_str_script_mode ) {
|
||||
if ( 'jquery' === Footnotes_Public::$a_str_script_mode ) {
|
||||
|
||||
$l_int_scroll_offset = ( self::$a_int_scroll_offset / 100 );
|
||||
$l_int_scroll_up_duration = intval( Footnotes_Settings::instance()->get( Footnotes_Settings::C_INT_FOOTNOTES_SCROLL_DURATION ) );
|
|
@ -1,4 +1,4 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName
|
||||
<?php
|
||||
/**
|
||||
* Widget base.
|
||||
*
|
|
@ -1,4 +1,4 @@
|
|||
<?php // phpcs:disable WordPress.Files.FileName.InvalidClassFileName, WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
<?php // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
/**
|
||||
* Includes the Plugin Widget to put the Reference Container to the Widget area.
|
||||
*
|
||||
|
@ -7,9 +7,7 @@
|
|||
* @since 1.5.0
|
||||
*/
|
||||
|
||||
require_once dirname( __FILE__, 2 ) . '/config.php';
|
||||
require_once dirname( __FILE__, 2 ) . '/settings.php';
|
||||
require_once dirname( __FILE__ ) . '/base.php';
|
||||
require_once dirname( __FILE__ ) . '/class-footnotes-widget-base.php';
|
||||
|
||||
/**
|
||||
* Registers a Widget to put the Reference Container to the widget area.
|
Reference in a new issue