PluginProbe
Code Snippets / 2.14.0
Code Snippets v2.14.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 2.14.0, at php/class-contextual-help.php

154 lines 6.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * This file holds all of the content for the contextual help screens
5 * @package Code_Snippets
6 */
7 class Code_Snippets_Contextual_Help {
8
9 /**
10 * @var WP_Screen
11 */
12 public $screen;
13
14 /**
15 * @var string
16 */
17 public $screen_name;
18
19 /**
20 * @param string $screen_name
21 */
22 function __construct( $screen_name ) {
23 $this->screen_name = $screen_name;
24 }
25
26 /**
27 * Load the contextual help
28 */
29 public function load() {
30 $this->screen = get_current_screen();
31
32 if ( method_exists( $this, "load_{$this->screen_name}_help" ) ) {
33 call_user_func( array( $this, "load_{$this->screen_name}_help" ) );
34 }
35
36 $this->load_help_sidebar();
37 }
38
39 /**
40 * Load the help sidebar
41 */
42 private function load_help_sidebar() {
43
44 $this->screen->set_help_sidebar(
45 '<p><strong>' . __( 'For more information:', 'code-snippets' ) . '</strong></p>' .
46 '<p><a href="https://wordpress.org/plugins/code-snippets">' . __( 'About Plugin', 'code-snippets' ) . '</a></p>' .
47 '<p><a href="https://wordpress.org/plugins/code-snippets/faq">' . __( 'FAQ', 'code-snippets' ) . '</a></p>' .
48 '<p><a href="https://wordpress.org/support/plugin/code-snippets">' . __( 'Support Forum', 'code-snippets' ) . '</a></p>' .
49 '<p><a href="https://sheabunge.com/plugins/code-snippets">' . __( 'Plugin Website', 'code-snippets' ) . '</a></p>'
50 );
51 }
52
53 /**
54 * Reusable introduction text
55 * @return string
56 */
57 private function get_intro_text() {
58 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' );
59 }
60
61 /**
62 * Register and handle the help tabs for the manage snippets admin page
63 */
64 private function load_manage_help() {
65
66 $this->screen->add_help_tab( array(
67 'id' => 'overview',
68 'title' => __( 'Overview', 'code-snippets' ),
69 'content' => '<p>' . $this->get_intro_text() .
70 __( ' Here you can manage your existing snippets and perform tasks on them such as activating, deactivating, deleting and exporting.', 'code-snippets' ) . '</p>',
71 ) );
72
73 $this->screen->add_help_tab( array(
74 'id' => 'safe-mode',
75 'title' => __( 'Safe Mode', 'code-snippets' ),
76 'content' =>
77 '<p>' . __( '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' ) . '</p>' .
78 '<p>' . __( "If something goes wrong with a snippet and you can't use WordPress, you can cause all snippets to stop executing by adding <code>define('CODE_SNIPPETS_SAFE_MODE', true);</code> to your <code>wp-config.php</code> file. After you have deactivated the offending snippet, you can turn off safe mode by removing this line or replacing <strong>true</strong> with <strong>false</strong>.", 'code-snippets' ) . '</p>',
79 ) );
80 }
81
82 /**
83 * Register and handle the help tabs for the single snippet admin page
84 */
85 private function load_edit_help() {
86
87 $this->screen->add_help_tab( array(
88 'id' => 'overview',
89 'title' => __( 'Overview', 'code-snippets' ),
90 'content' => '<p>' . $this->get_intro_text() . __( ' Here you can add a new snippet, or edit an existing one.', 'code-snippets' ) . '</p>',
91 ) );
92
93 $snippet_host_links = array(
94 __( 'WP Function Me', 'code-snippets' ) => __( 'https://www.wpfunction.me', 'code-snippets' ),
95 __( 'CSS-Tricks', 'code-snippets' ) => __( 'https://css-tricks.com/snippets/wordpress/', 'code-snippets' ),
96 __( 'WordPress Stack Exchange', 'code-snippets' ) => __( 'https://wordpress.stackexchange.com/', 'code-snippets' ),
97 __( 'WP Beginner', 'code-snippets' ) => __( 'https://www.wpbeginner.com/category/wp-tutorials/', 'code-snippets' ),
98 __( 'GenerateWP', 'code-snippets' ) => __( 'https://generatewp.com', 'code-snippets' ),
99 );
100
101 $snippet_host_list = '';
102 foreach ( $snippet_host_links as $title => $link ) {
103 $snippet_host_list .= sprintf( '<li><a href="%s">%s</a></li>', esc_url( $link ), esc_html( $title ) );
104 }
105
106 $this->screen->add_help_tab( array(
107 'id' => 'finding',
108 'title' => __( 'Finding Snippets', 'code-snippets' ),
109 'content' =>
110 '<p>' . __( 'Here are some links to websites which host a large number of snippets that you can add to your site:', 'code-snippets' ) .
111 '<ul>' . $snippet_host_list . '</ul>' .
112 __( 'More places to find snippets, as well as a selection of example snippets, can be found in the <a href="https://github.com/sheabunge/code-snippets/wiki/Finding-snippets">plugin documentation</a>.', 'code-snippets' ) . '</p>',
113 ) );
114
115 $this->screen->add_help_tab( array(
116 'id' => 'adding',
117 'title' => __( 'Adding Snippets', 'code-snippets' ),
118 'content' =>
119 '<p>' . __( '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' ) . '</p>' .
120 '<p>' . __( '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' ) . '</p>',
121 ) );
122 }
123
124 /**
125 * Register and handle the help tabs for the import snippets admin page
126 */
127 private function load_import_help() {
128 $manage_url = code_snippets()->get_menu_url( 'manage' );
129
130 $this->screen->add_help_tab( array(
131 'id' => 'overview',
132 'title' => __( 'Overview', 'code-snippets' ),
133 'content' => '<p>' . $this->get_intro_text() .
134 __( ' Here you can load snippets from a code snippets export file into the database alongside existing snippets.', 'code-snippets' ) . '</p>',
135 ) );
136
137 $this->screen->add_help_tab( array(
138 'id' => 'import',
139 'title' => __( 'Importing', 'code-snippets' ),
140 'content' =>
141 '<p>' . __( 'You can load your snippets from a code snippets export file using this page.', 'code-snippets' ) .
142 /* translators: %s: URL to Snippets admin menu */
143 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 ) . '</p>',
144 ) );
145
146 $this->screen->add_help_tab( array(
147 'id' => 'export',
148 'title' => __( 'Exporting', 'code-snippets' ),
149 /* translators: %s: URL to Manage Snippets admin menu */
150 'content' => '<p>' . 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 ) . '</p>',
151 ) );
152 }
153 }
154