Admin   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 73
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A output_admin_notices() 0 25 2
A add_plugin_page_row_action_links() 0 13 1
1
<?php
2
/**
3
 * WP PHP Console
4
 *
5
 * This source file is subject to the GNU General Public License v3.0
6
 * that is bundled with this package in the file license.txt.
7
 * It is also available through the world-wide-web at this URL:
8
 * http://www.gnu.org/licenses/gpl-3.0.html
9
 *
10
 * @author    Fulvio Notarstefano <[email protected]>
11
 * @copyright Copyright (c) 2014-2020 Fulvio Notarstefano
12
 * @license   http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
13
 */
14
15
namespace WP_PHP_Console;
16
17
defined( 'ABSPATH' ) or exit;
18
19
/**
20
 * WP PHP Console admin handler.
21
 *
22
 * @since 1.6.0
23
 */
24
class Admin {
25
26
27
	/**
28
	 * Initializes the plugin admin.
29
	 *
30
	 * @since 1.6.0
31
	 */
32
	public function __construct() {
33
34
		self::add_plugin_page_row_action_links();
35
		self::output_admin_notices();
36
37
		// init settings page
38
		if ( ! defined( 'DOING_AJAX' ) ) {
39
			new Admin\SettingsPage();
40
		}
41
	}
42
43
44
	/**
45
	 * Displays notices in admin.
46
	 *
47
	 * @since 1.6.0
48
	 */
49
	private static function output_admin_notices() {
50
51
		// display admin notice and abort if no password has been set
52
		add_action( 'all_admin_notices', static function() {
53
54
			if ( ! Settings::has_eval_terminal_password() ) :
55
56
				?>
57
				<div class="notice notice-warning">
58
					<p>
59
						<?php printf(
60
							/* translators: Placeholders: %1$s - WP PHP Console name, %2$s - opening HTML <a> link tag; %3$s closing HTML </a> link tag */
61
							__( '%1$s: Please remember to %2$sset a password%3$s if you want to enable the terminal.', 'wp-php-console' ),
62
							'<strong>' . Plugin::NAME . '</strong>',
63
							'<a href="' . esc_url( admin_url( 'options-general.php?page=wp_php_console' ) ) .'">',
64
							'</a>'
65
						); ?>
66
					</p>
67
				</div>
68
				<?php
69
70
			endif;
71
72
		}, -1000 );
73
	}
74
75
76
	/**
77
	 * Adds plugin page row action links.
78
	 *
79
	 * @since 1.6.0
80
	 */
81
	private static function add_plugin_page_row_action_links() {
82
83
		add_filter( 'plugin_action_links_wp-php-console/wp-php-console.php', static function( $actions ) {
84
85
			return array_merge( [
86
				'<a href="' . esc_url( admin_url( 'options-general.php?page=' . str_replace( '-', '_', Plugin::ID ) ) ) . '">' . esc_html__( 'Settings', 'wp-php-console' ) . '</a>',
87
				'<a href="' . esc_url( Plugin::get_wp_php_console_repository_url() ) . '">' . esc_html__( 'GitHub', 'wp-php-console' ) . '</a>',
88
				'<a href="' . esc_url( Plugin::get_support_page_url() ) . '">' . esc_html__( 'Support', 'wp-php-console' ) . '</a>',
89
				'<a href="' . esc_url( Plugin::get_reviews_page_url() ) . '">' . esc_html__( 'Review', 'wp-php-console' ) . '</a>',
90
			], $actions );
91
92
		} );
93
	}
94
95
96
}
97