This repository has been archived on 2023-08-16. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
footnotes/src/admin/class-admin.php

158 lines
4 KiB
PHP
Raw Normal View History

<?php
/**
2021-05-01 21:34:46 +01:00
* Admin: Admin class
*
2021-05-01 21:34:46 +01:00
* The Admin. subpackage is initialised at runtime by the {@see Admin}
* class, which draws in the {@see WYSIWYG} class for WYSIWYG editor
* integration and the {@see footnotes\admin\layout} subpackage for rendering
2021-04-30 18:03:15 +01:00
* dashboard pages.
*
2021-05-01 21:34:46 +01:00
* @package footnotes
2021-04-30 18:03:15 +01:00
* @since 2.8.0
*/
2021-05-02 19:19:46 +01:00
declare(strict_types=1);
2021-05-01 21:34:46 +01:00
namespace footnotes\admin;
use footnotes\includes as Includes;
/**
2021-04-30 18:03:15 +01:00
* Class provide all admin-specific functionality of the plugin.
*
* Defines the plugin name, version, and enqueues all admin-specific stylesheets
* and JavaScript.
*
2021-05-01 21:34:46 +01:00
* @package footnotes
2021-04-30 18:03:15 +01:00
* @since 2.8.0
*/
2021-05-01 21:34:46 +01:00
class Admin {
/**
2021-05-02 19:58:40 +01:00
* The WYSIWYG editor integration object.
*
2021-04-30 18:03:15 +01:00
* @since 2.8.0
2021-05-02 19:58:40 +01:00
* @var WYSIWYG $wysiwyg The WYSIWYG editor integration object.
*/
2021-05-02 19:58:40 +01:00
public WYSIWYG $wysiwyg;
/**
2021-05-02 19:58:40 +01:00
* Initialize the class and set its properties.
*
2021-04-30 18:03:15 +01:00
* @since 2.8.0
*/
2021-05-02 19:58:40 +01:00
public function __construct( /**
2021-05-02 20:12:47 +01:00
* The ID of this plugin.
*
* @access private
* @since 2.8.0
* @see Includes\Footnotes::$plugin_name
* @var string $plugin_name The ID of this plugin.
*/
2021-05-02 19:58:40 +01:00
private string $plugin_name, /**
2021-05-02 20:12:47 +01:00
* The version of this plugin.
*
* @access private
* @since 2.8.0
* @see Includes\Footnotes::$version
* @var string $version The current version of this plugin.
*/
2021-05-02 19:58:40 +01:00
private string $version ) {
$this->load_dependencies();
}
/**
* Load the required admin-specific dependencies.
*
2021-04-30 18:03:15 +01:00
* Includes the following files that provide the admin-specific functionality
* of this plugin:
*
2021-05-01 21:34:46 +01:00
* - {@see WYSIWYG}: Provides plugin integration with the WYSIWYG editor.
* - {@see layout\Settings}: Defines the plugin dashboard page(s).
*
2021-04-30 18:03:15 +01:00
* @access private
*
* @since 2.8.0
*/
2021-05-02 19:19:46 +01:00
private function load_dependencies(): void {
2021-04-27 08:31:37 +01:00
/**
* The class responsible for WYSIWYG editor integration.
*/
2021-05-02 19:47:58 +01:00
require_once plugin_dir_path( __DIR__ ) . 'admin/class-wysiwyg.php';
2021-04-27 08:42:21 +01:00
2021-05-01 21:34:46 +01:00
$this->wysiwyg = new WYSIWYG( $this->plugin_name );
2021-04-27 09:54:07 +01:00
2021-04-27 08:31:37 +01:00
/**
* The class responsible for constructing the plugin dashboard page(s).
*/
2021-05-02 19:47:58 +01:00
require_once plugin_dir_path( __DIR__ ) . 'admin/layout/class-init.php';
2021-05-01 21:34:46 +01:00
new layout\Init( $this->plugin_name );
}
/**
* Register the stylesheets for the admin area.
*
2021-04-30 18:03:15 +01:00
* @since 2.8.0
*/
2021-05-02 19:19:46 +01:00
public function enqueue_styles(): void {
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(
2021-05-02 19:33:29 +01:00
__FILE__
) . 'css/settings.css'
),
'all'
);
2021-05-02 19:33:29 +01:00
}
/**
* Register the JavaScript for the admin area.
*
2021-04-30 18:03:15 +01:00
* @since 2.8.0
*/
2021-05-02 19:19:46 +01:00
public function enqueue_scripts(): void {
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(
2021-05-02 19:33:29 +01:00
__FILE__
) . 'js/wysiwyg-editor.js'
),
false
);
}
/**
* Appends the Plugin links for display in the dashboard Plugins page.
*
2021-05-01 21:34:46 +01:00
* @param string[] $plugin_links The default set of links to display.
2021-04-30 18:03:15 +01:00
* @return string[] The full set of links to display.
*
* @since 1.5.0
2021-05-01 21:34:46 +01:00
* @since 2.8.0 Moved from `Hooks` class to `Admin`.
*/
2021-05-01 21:34:46 +01:00
public function action_links( array $plugin_links ): array {
// Append link to the WordPress Plugin page.
2021-05-01 21:34:46 +01:00
$plugin_links[] = sprintf( '<a href="https://wordpress.org/support/plugin/footnotes" target="_blank">%s</a>', __( 'Support', 'footnotes' ) );
// Append link to the settings page.
2021-05-01 21:34:46 +01:00
$plugin_links[] = sprintf( '<a href="%s">%s</a>', esc_url( admin_url( 'options-general.php?page=footnotes' ) ), __( 'Settings', 'footnotes' ) );
// Append link to the PayPal donate function.
2021-05-01 21:34:46 +01:00
$plugin_links[] = sprintf( '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=6Z6CZDW8PPBBJ" target="_blank">%s</a>', __( 'Donate', 'footnotes' ) );
return $plugin_links;
}
}