*/ class _404_To_301_Admin { /** * The ID of this plugin. * * @since 2.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 2.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * The table name of this plugin. * * @since 2.0.0 * @access private * @var string $table The table name of this plugin in db. */ private $table; /** * The options from db. * * @since 2.0.0 * @access private * @var string $gnrl_options Get the options saved in db. */ private $gnrl_options; /** * The options from db. * * @since 2.1.0 * @access private * @var mixed $list_table Class object for listing table. */ private $list_table; /** * Initialize the class and set its properties. * * @since 2.0.0 * @var string $plugin_name The name of this plugin. * @var string $version The version of this plugin. * @var string $table The name of the database table of this plugin. */ public function __construct($plugin_name, $version, $table) { $this->plugin_name = $plugin_name; $this->version = $version; $this->table = $table; $this->gnrl_options = get_option('i4t3_gnrl_options'); } /** * Register the stylesheet for the Dashboard. * * This function is used to register all the required stylesheets for * dashboard. Styles will be registered only for i4t3 pages for performance. * * @since 2.0.0 * @uses wp_enqueue_style To register style */ public function enqueue_styles() { global $pagenow; if (( $pagenow == 'admin.php' ) && ( in_array($_GET['page'], array('i4t3-settings', 'i4t3-logs')))) { wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/min/admin.css', array(), $this->version, 'all'); } } /** * Register the scripts for the Dashboard. * * This function is used to register all the required scripts for * dashboard. Scripts will be registered only for i4t3 pages for performance. * * @since 2.0.0 * @uses wp_enqueue_script To register script */ public function enqueue_scripts() { global $pagenow; if (( $pagenow == 'admin.php' ) && ( in_array($_GET['page'], array('i4t3-settings')))) { wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/admin.js', array('jquery'), $this->version, false); } } /** * Run upgrade functions * * If 404 to 301 is upgraded, we may need to perform few updations in db * * @since 2.0.0 * @uses get_option() To get the activation redirect option from db. * @return void. */ public function i4t3_upgrade_if_new() { if (!get_option('i4t3_version_no') || ( get_option('i4t3_version_no') < I4T3_VERSION )) { if (class_exists('_404_To_301_Activator')) { _404_To_301_Activator::activate(); } update_option('i4t3_version_no', I4T3_VERSION); } } /** * Changing email notification recipient * * Using filter to change email notification recipient address from * default admin email. * * @since 2.0.7 * @uses get_option() To get the email address option from db. * @return $email Email address to be used for notification. */ public function i4t3_change_notify_email($email) { if (!empty($this->gnrl_options['email_notify_address'])) { $email_option = $this->gnrl_options['email_notify_address']; if (is_email($email_option)) { $email = $email_option; } } return $email; } /** * Creating admin menus for 404 to 301. * * @since 2.0.0 * @author Joel James * @uses action hook add_submenu_page Action hook to add new admin menu sub page. */ public function i4t3_create_404_to_301_menu() { // Error log menu $hook = add_menu_page( __('404 Error Logs', '404-to-301'), __('404 Error Logs', '404-to-301'), I4T3_ADMIN_PERMISSION, 'i4t3-logs', array($this, 'i4t3_render_list_page'), 'dashicons-redo', 90 ); add_action("load-$hook", array($this, 'screen_option')); // 404 to 301 settings menu add_submenu_page( 'i4t3-logs', __('404 to 301 Settings', '404-to-301'), __('404 Settings', '404-to-301'), I4T3_ADMIN_PERMISSION, 'i4t3-settings', array($this, 'i4t3_admin_page') ); do_action('i4t3_admin_page'); } /** * To set the screen of the error listing page. * * @since 2.1.0 * @author Joel James. */ public static function set_screen($status, $option, $value) { return $value; } /** * To make screen options for 404 to 301 listing. * * This function is used to show screen options like entries per page, * show/hide columns etc. * * @since 2.1.0 * @author Joel James. */ public function screen_option() { $option = 'per_page'; $args = array( 'label' => __('Error Logs', '404-to-301'), 'default' => 5, 'option' => 'logs_per_page' ); add_screen_option($option, $args); $this->list_table = new _404_To_301_Logs($this->table); } /** * Output buffer function * * To avoid header already sent issue * @link https://tommcfarlin.com/wp_redirect-headers-already-sent/ * @since 2.1.4 */ public function add_buffer() { ob_start(); } /** * Creating log table page. * * @since 2.0.0 * @author Joel James * @uses class _404_To_301_Logs To initialize and load the log listing table. */ public function i4t3_render_list_page() { ?>
';
foreach ($gnrl_options as $key => $option) {
$html .= $key . ' : ' . $option . '
';
}
$html .= '
' . __('WordPress Version', '404-to-301') . ' : ' . get_bloginfo('version') . '
' . __('PHP Version', '404-to-301') . ' : ' . PHP_VERSION . '
' . __('Plugin Version', '404-to-301') . ' : ' . $this->version . '
' . __('Home Page', '404-to-301') . ' : ' . home_url() . '
' . __('Name', '404-to-301') . ' : ' . $active_theme->get('Name') . '
' . __('Version', '404-to-301') . ' : ' . $active_theme->get('Version') . '
' . __('Theme URI', '404-to-301') . ' : ' . $active_theme->get('ThemeURI') . '
';
foreach ($active_plugins as $plugin) {
$html .= $plugin . '
';
}
$html .= '