wordpress/php-fpm/wordpress_files/plugins/fg-spip-to-wp/includes/class-fg-spip-to-wp.php

260 lines
7.4 KiB
PHP
Raw Normal View History

2020-05-22 03:40:23 +02:00
<?php
/**
* 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.
*
* @link https://wordpress.org/plugins/fg-spip-to-wp/
* @since 1.0.0
*
* @package FG_Spip_to_WordPress
* @subpackage FG_Spip_to_WordPress/includes
*/
/**
* The core plugin class.
*
* 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.0.0
* @package FG_Spip_to_WordPress
* @subpackage FG_Spip_to_WordPress/includes
* @author Frédéric GILLES
*/
class FG_Spip_to_WordPress {
/**
* The loader that's responsible for maintaining and registering all hooks that power
* the plugin.
*
* @since 1.0.0
* @access protected
* @var FG_Spip_to_WordPress_Loader $loader Maintains and registers all hooks for the plugin.
*/
protected $loader;
/**
* The unique identifier of this plugin.
*
* @since 1.0.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 1.0.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( 'FGS2WP_PLUGIN_VERSION' ) ) {
$this->version = FGS2WP_PLUGIN_VERSION;
} else {
$this->version = '1.0.0';
}
$this->plugin_name = 'fg-spip-to-wp';
$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:
*
* - FG_Spip_to_WordPress_Loader. Orchestrates the hooks of the plugin.
* - FG_Spip_to_WordPress_i18n. Defines internationalization functionality.
* - FG_Spip_to_WordPress_Admin. Defines all hooks for the admin area.
* - FG_Spip_to_WordPress_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 1.0.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-fg-spip-to-wp-loader.php';
/**
* The class responsible for defining internationalization functionality
* of the plugin.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-fg-spip-to-wp-i18n.php';
// Load Importer API
require_once ABSPATH . 'wp-admin/includes/import.php';
if ( !class_exists( 'WP_Importer' ) ) {
$class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
if ( file_exists( $class_wp_importer ) ) {
require_once $class_wp_importer;
}
}
/**
* The class responsible for defining all actions that occur in the admin area.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-fg-spip-to-wp-admin.php';
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-fg-spip-to-wp-tools.php';
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-fg-spip-to-wp-compatibility.php';
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-fg-spip-to-wp-progressbar.php';
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-fg-spip-to-wp-modules-check.php';
/**
* The class responsible for defining all actions that occur in the public-facing
* side of the site.
*/
$this->loader = new FG_Spip_to_WordPress_Loader();
}
/**
* Define the locale for this plugin for internationalization.
*
* Uses the FG_Spip_to_WordPress_i18n class in order to set the domain and to register the hook
* with WordPress.
*
* @since 1.0.0
* @access private
*/
private function set_locale() {
$plugin_i18n = new FG_Spip_to_WordPress_i18n();
$plugin_i18n->set_domain( $this->get_plugin_name() );
$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 1.0.0
* @access private
*/
private function define_admin_hooks() {
// Add links to the plugin page
$this->loader->add_filter( 'plugin_action_links_' . $this->plugin_name . '/' . $this->plugin_name . '.php', $this, 'plugin_action_links' );
/**
* The plugin is hooked to the WordPress importer
*/
if ( !defined('WP_LOAD_IMPORTERS') && !defined('DOING_AJAX') ) {
return;
}
$plugin_admin = new FG_Spip_to_WordPress_Admin( $this->get_plugin_name(), $this->get_version() );
$this->loader->add_action( 'admin_init', $plugin_admin, 'init' );
$this->loader->add_action( 'fgs2wp_post_test_database_connection', $plugin_admin, 'get_spip_info', 9 );
$this->loader->add_action( 'load-importer-fg-spip-to-wp', $plugin_admin, 'add_help_tab', 20 );
$this->loader->add_action( 'admin_footer', $plugin_admin, 'display_notices', 20 );
$this->loader->add_action( 'wp_ajax_fgs2wp_import', $plugin_admin, 'ajax_importer' );
$this->loader->add_filter( 'fgs2wp_pre_import_check', $plugin_admin, 'pre_import_check', 10, 1 );
/*
* Modules checker
*/
$plugin_modules_check = new FG_Spip_to_WordPress_Modules_Check( $plugin_admin );
$this->loader->add_action( 'fgs2wp_post_test_database_connection', $plugin_modules_check, 'check_modules' );
}
/**
* Register all of the hooks related to the public-facing functionality
* of the plugin.
*
* @since 1.0.0
* @access private
*/
private function define_public_hooks() {
}
/**
* Customize the links on the plugins list page
*
* @param array $links Links
* @return array Links
*/
public function plugin_action_links($links) {
// Add the import link
$import_link = '<a href="admin.php?import=fg-spip-to-wp">'. __('Import', $this->plugin_name) . '</a>';
array_unshift($links, $import_link);
return $links;
}
/**
* Run the loader to execute all of the hooks with WordPress.
*
* @since 1.0.0
*/
public function run() {
$this->loader->run();
}
/**
* The name of the plugin used to uniquely identify it within the context of
* WordPress and to define internationalization functionality.
*
* @since 1.0.0
* @return string The name of the plugin.
*/
public function get_plugin_name() {
return $this->plugin_name;
}
/**
* The reference to the class that orchestrates the hooks with the plugin.
*
* @since 1.0.0
* @return FG_Spip_to_WordPress_Loader Orchestrates the hooks of the plugin.
*/
public function get_loader() {
return $this->loader;
}
/**
* Retrieve the version number of the plugin.
*
* @since 1.0.0
* @return string The version number of the plugin.
*/
public function get_version() {
return $this->version;
}
}