PluginProbe
Code Snippets / 3.1.0
Code Snippets v3.1.0
3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 3.0.1 All 64 releases
code-snippets / php / class-contextual-help.php

class-contextual-help.php in Code Snippets 3.1.0, at php/class-contextual-help.php

189 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Code_Snippets;
4
5 use WP_Screen;
6
7 /**
8 * This file holds all the content for the contextual help screens.
9 *
10 * @package Code_Snippets
11 */
12 class Contextual_Help {
13
14 /**
15 * Current screen object
16 *
17 * @see get_current_screen()
18 *
19 * @var WP_Screen
20 */
21 public $screen;
22
23 /**
24 * Name of current screen
25 *
26 * @see get_current_screen()
27 *
28 * @var string
29 */
30 public $screen_name;
31
32 /**
33 * Class constructor
34 *
35 * @param string $screen_name Name of current screen.
36 */
37 public function __construct( $screen_name ) {
38 $this->screen_name = $screen_name;
39 }
40
41 /**
42 * Load the contextual help
43 */
44 public function load() {
45 $this->screen = get_current_screen();
46
47 if ( method_exists( $this, "load_{$this->screen_name}_help" ) ) {
48 call_user_func( array( $this, "load_{$this->screen_name}_help" ) );
49 }
50
51 $this->load_help_sidebar();
52 }
53
54 /**
55 * Load the help sidebar
56 */
57 private function load_help_sidebar() {
58 $sidebar_links = [
59 'https://wordpress.org/plugins/code-snippets' => __( 'About Plugin', 'code-snippets' ),
60 'https://help.codesnippets.pro/collection/3-faq' => __( 'FAQ', 'code-snippets' ),
61 'https://wordpress.org/support/plugin/code-snippets' => __( 'Support Forum', 'code-snippets' ),
62 'https://codesnippets.pro' => __( 'Plugin Website', 'code-snippets' ),
63 ];
64
65 $contents = '<p><strong>' . __( 'For more information:', 'code-snippets' ) . "</strong></p>\n";
66
67 foreach ( $sidebar_links as $url => $label ) {
68 $contents .= "\n" . sprintf( '<p><a href="%s">%s</a></p>', esc_url( $url ), esc_html( $label ) );
69 }
70
71 $this->screen->set_help_sidebar( wp_kses_post( $contents ) );
72 }
73
74 /**
75 * Add a help tab to the current screen.
76 *
77 * @param string $id Screen ID.
78 * @param string $title Screen title.
79 * @param string|array $paragraphs List of paragraphs to display as content.
80 *
81 * @return void
82 */
83 private function add_help_tab( $id, $title, $paragraphs ) {
84 $this->screen->add_help_tab(
85 array(
86 'title' => $title,
87 'id' => $id,
88 'content' => wp_kses_post(
89 implode(
90 "\n",
91 array_map(
92 function ( $content ) {
93 return '<p>' . $content . '</p>';
94 },
95 is_array( $paragraphs ) ? $paragraphs : [ $paragraphs ]
96 )
97 )
98 ),
99 )
100 );
101 }
102
103 /**
104 * Reusable introduction text
105 *
106 * @return string
107 */
108 private function get_intro_text() {
109 return __( 'Snippets are similar to plugins - they both extend and expand the functionality of WordPress. Snippets are more light-weight, just a few lines of code, and do not put as much load on your server. ', 'code-snippets' );
110 }
111
112 /**
113 * Register and handle the help tabs for the manage snippets admin page
114 */
115 private function load_manage_help() {
116
117 $this->add_help_tab(
118 'overview',
119 __( 'Overview', 'code-snippets' ),
120 $this->get_intro_text() .
121 __( 'Here you can manage your existing snippets and perform tasks on them such as activating, deactivating, deleting and exporting.', 'code-snippets' )
122 );
123
124 $this->add_help_tab(
125 'safe-mode',
126 __( 'Safe Mode', 'code-snippets' ),
127 [
128 __( 'Be sure to check your snippets for errors before you activate them, as a faulty snippet could bring your whole blog down. If your site starts doing strange things, deactivate all your snippets and activate them one at a time.', 'code-snippets' ),
129 __( "If something goes wrong with a snippet, and you can't use WordPress, you can cause all snippets to stop executing by turning on <strong>safe mode</strong>.", 'code-snippets' ),
130 __( 'You can find out how to enable safe mode in the <a href="https://help.codesnippets.pro/article/12-safe-mode">Code Snippets Pro Docs</a>.', 'code-snippets' ),
131 ]
132 );
133 }
134
135 /**
136 * Register and handle the help tabs for the single snippet admin page
137 */
138 private function load_edit_help() {
139
140 $this->add_help_tab(
141 'overview',
142 __( 'Overview', 'code-snippets' ),
143 [
144 $this->get_intro_text() .
145 __( 'Here you can add a new snippet, or edit an existing one.', 'code-snippets' ),
146 __( "If you're not sure about the types of snippets you can add, take a look at the <a href=\"https://help.codesnippets.pro/collection/2-adding-snippets\">Code Snippets Pro Docs</a> for inspiration.", 'code-snippets' ),
147 ]
148 );
149
150 $this->add_help_tab(
151 'adding',
152 __( 'Adding Snippets', 'code-snippets' ),
153 [
154 __( 'You need to fill out the name and code fields for your snippet to be added. While the description field will add more information about how your snippet works, what is does and where you found it, it is completely optional.', 'code-snippets' ),
155 __( 'Please be sure to check that your snippet is valid PHP code and will not produce errors before adding it through this page. While doing so will not become active straight away, it will help to minimise the chance of a faulty snippet becoming active on your site.', 'code-snippets' ),
156 ]
157 );
158 }
159
160 /**
161 * Register and handle the help tabs for the import snippets admin page
162 */
163 private function load_import_help() {
164 $manage_url = code_snippets()->get_menu_url( 'manage' );
165
166 $this->add_help_tab(
167 'overview',
168 __( 'Overview', 'code-snippets' ),
169 $this->get_intro_text() .
170 __( 'Here you can load snippets from a code snippets export file into the database alongside existing snippets.', 'code-snippets' )
171 );
172
173 $this->add_help_tab(
174 'import',
175 __( 'Importing', 'code-snippets' ),
176 __( 'You can load your snippets from a code snippets export file using this page.', 'code-snippets' ) .
177 /* translators: %s: URL to Snippets admin menu */
178 sprintf( __( 'Imported snippets will be added to the database along with your existing snippets. Regardless of whether the snippets were active on the previous site, imported snippets are always inactive until activated using the <a href="%s">Manage Snippets</a> page.', 'code-snippets' ), $manage_url )
179 );
180
181 $this->add_help_tab(
182 'export',
183 __( 'Exporting', 'code-snippets' ),
184 /* translators: %s: URL to Manage Snippets admin menu */
185 sprintf( __( 'You can save your snippets to a code snippets export file using the <a href="%s">Manage Snippets</a> page.', 'code-snippets' ), $manage_url )
186 );
187 }
188 }
189