PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.3.1
Defender Security – Malware Scanner, Login Security & Firewall v5.3.1
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / src / controller / class-tutorial.php

class-tutorial.php in Defender Security – Malware Scanner, Login Security & Firewall 5.3.1, at src/controller/class-tutorial.php

156 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handle tutorials page.
4 *
5 * @package WP_Defender\Controller
6 */
7
8 namespace WP_Defender\Controller;
9
10 use Calotes\Helper\Route;
11 use WP_Defender\Controller;
12 use Calotes\Component\Response;
13
14 /**
15 * Handles tutorials page.
16 */
17 class Tutorial extends Controller {
18
19 /**
20 * The slug identifier for this controller.
21 *
22 * @var string
23 */
24 public $slug = 'wdf-tutorial';
25
26 /**
27 * Initializes the model and service, registers routes, and sets up scheduled events if the model is active.
28 */
29 public function __construct() {
30 // Check if tutorials should be hidden.
31 $hide = apply_filters( 'wpmudev_branding_hide_doc_link', false );
32 if ( ! $hide ) {
33 $this->register_page(
34 esc_html__( 'Tutorials', 'defender-security' ),
35 $this->slug,
36 array( $this, 'main_view' ),
37 $this->parent_slug
38 );
39 add_action( 'defender_enqueue_assets', array( $this, 'enqueue_assets' ) );
40 $this->register_routes();
41 }
42 }
43
44 /**
45 * Enqueue assets & output data.
46 */
47 public function enqueue_assets(): void {
48 if ( $this->is_page_active() ) {
49 wp_localize_script( 'def-tutorial', 'tutorial', $this->data_frontend() );
50 wp_enqueue_script( 'def-tutorial' );
51 $this->enqueue_main_assets();
52 }
53 }
54
55 /**
56 * Renders the main view for this page.
57 */
58 public function main_view() {
59 $this->render( 'main' );
60 }
61
62 /**
63 * Checks if the tutorial page should be shown.
64 *
65 * @return bool True if the page should be shown, false otherwise.
66 */
67 public function is_show(): bool {
68 return ! get_site_option( 'wp_defender_hide_tutorials' ) && ! apply_filters(
69 'wpmudev_branding_hide_doc_link',
70 false
71 );
72 }
73
74 /**
75 * Converts the current object state to an array.
76 *
77 * @return array The array representation of the object.
78 */
79 public function to_array(): array {
80 [ $routes, $nonces ] = Route::export_routes( 'tutorial' );
81
82 return array(
83 'show' => $this->is_show(),
84 'endpoints' => $routes,
85 'nonces' => $nonces,
86 );
87 }
88
89 /**
90 * Hide tutorials.
91 *
92 * @return Response
93 * @defender_route
94 */
95 public function hide(): Response {
96 update_site_option( 'wp_defender_hide_tutorials', true );
97
98 return new Response(
99 true,
100 array(
101 'message' => sprintf(
102 /* translators: %s: Tutorial link. */
103 __(
104 'The widget has been removed. You can check all defender tutorials at the <a href="%s">tutorials\' tab</a> at any time.',
105 'defender-security'
106 ),
107 network_admin_url( 'admin.php?page=wdf-tutorial' )
108 ),
109 )
110 );
111 }
112
113 /**
114 * Removes settings for all submodules.
115 */
116 public function remove_settings() {
117 delete_site_option( 'wp_defender_hide_tutorials' );
118 }
119
120 /**
121 * Delete all the data & the cache.
122 */
123 public function remove_data() {
124 delete_site_option( 'wp_defender_hide_tutorials' );
125 }
126
127 /**
128 * Provides data for the frontend.
129 *
130 * @return array An array of data for the frontend.
131 */
132 public function data_frontend(): array {
133 return array_merge(
134 array( 'show' => $this->is_show() ),
135 $this->dump_routes_and_nonces()
136 );
137 }
138
139 /**
140 * Imports data into the model.
141 *
142 * @param array $data Data to be imported into the model.
143 */
144 public function import_data( array $data ) {
145 }
146
147 /**
148 * Exports strings.
149 *
150 * @return array An array of strings.
151 */
152 public function export_strings(): array {
153 return array();
154 }
155 }
156