Completed
Push — master ( 1614fa...13be2d )
by Armando
02:26 queued 42s
created

WP2D_Contextual_Help::__wakeup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 1
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Plugin Contextual Help.
4
 *
5
 * @package WP_To_Diaspora\Help
6
 * @since 1.4.0
7
 */
8
9
// Exit if accessed directly.
10
defined( 'ABSPATH' ) || exit;
11
12
/**
13
 * Class that handles the contextual help.
14
 */
15
class WP2D_Contextual_Help {
16
17
	/**
18
	 * Only instance of this class.
19
	 *
20
	 * @var WP2D_Contextual_Help
21
	 */
22
	private static $_instance;
23
24
	/**
25
	 * Create / Get the instance of this class.
26
	 *
27
	 * @return WP2D_Contextual_Help Instance of this class.
28
	 */
29 View Code Duplication
	public static function instance() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
		if ( ! isset( self::$_instance ) ) {
31
			self::$_instance = new self();
32
			self::$_instance->_constants();
33
			self::$_instance->_setup();
34
		}
35
		return self::$_instance;
36
	}
37
38
	/**
39
	 * Define all the required constants.
40
	 *
41
	 * @since 1.5.0
42
	 */
43
	private function _constants() {
44
		define( 'WP2D_EXT_WPORG',         esc_url( 'https://wordpress.org/plugins/wp-to-diaspora' ) );
45
		define( 'WP2D_EXT_I18N',          esc_url( 'https://poeditor.com/join/project?hash=c085b3654a5e04c69ec942e0f136716a' ) );
46
		define( 'WP2D_EXT_GH',            esc_url( 'https://github.com/DiasPHPora/wp-to-diaspora' ) );
47
		define( 'WP2D_EXT_DONATE',        esc_url( 'https://github.com/DiasPHPora/wp-to-diaspora#donate' ) );
48
		define( 'WP2D_EXT_GH_ISSUES',     esc_url( 'https://github.com/DiasPHPora/wp-to-diaspora/issues' ) );
49
		define( 'WP2D_EXT_GH_ISSUES_NEW', esc_url( 'https://github.com/DiasPHPora/wp-to-diaspora/issues/new' ) );
50
	}
51
52
	/**
53
	 * Set up the contextual help menu.
54
	 */
55
	private function _setup() {
56
		// Do we display the help tabs?
57
		$post_type = get_current_screen()->post_type;
58
		$enabled_post_types = WP2D_Options::instance()->get_option( 'enabled_post_types' );
59
		if ( '' !== $post_type && ! in_array( $post_type, $enabled_post_types ) ) {
60
			return;
61
		}
62
63
		// If we don't have a post type, we're on the main settings page.
64
		if ( '' === $post_type ) {
65
			// Set the sidebar in the contextual help.
66
			$this->_set_sidebar();
67
68
			// Add the main settings tabs and their content.
69
			$this->_add_settings_help_tabs();
70
		} else {
71
			// Add the post type specific tabs and their content.
72
			$this->_add_post_type_help_tabs();
73
		}
74
	}
75
76
	/** Singleton, keep private. */
77
	final private function __clone() { }
78
79
	/** Singleton, keep private. */
80
	final private function __construct() { }
81
82
	/**
83
	 * Set the sidebar in the contextual help.
84
	 */
85
	private function _set_sidebar() {
86
		get_current_screen()->set_help_sidebar(
87
			'<p><strong>' . esc_html__( 'WP to diaspora*', 'wp-to-diaspora' ) . '</strong></p>
88
			<ul>
89
				<li><a href="' . WP2D_EXT_GH     . '" target="_blank">GitHub</a>
90
				<li><a href="' . WP2D_EXT_WPORG  . '" target="_blank">WordPress.org</a>
91
				<li><a href="' . WP2D_EXT_I18N   . '" target="_blank">' . esc_html__( 'Help with translations', 'wp-to-diaspora' ) . '</a>
92
				<li><a href="' . WP2D_EXT_DONATE . '" target="_blank">' . esc_html__( 'Make a donation', 'wp-to-diaspora' )        . '</a>
93
			</ul>'
94
		);
95
	}
96
97
	/**
98
	 * Add help tabs to the contextual help on the settings page.
99
	 */
100
	private function _add_settings_help_tabs() {
101
		$screen = get_current_screen();
102
103
		// A short overview of the plugin.
104
		$screen->add_help_tab( array(
105
			'id'      => 'overview',
106
			'title'   => esc_html__( 'Overview', 'wp-to-diaspora' ),
107
			'content' => '<p><strong>' . esc_html__( 'With WP to diaspora*, sharing your WordPress posts to diaspora* is as easy as ever.', 'wp-to-diaspora' ) . '</strong></p>
108
				<ol>
109
					<li>' . esc_html__( 'Enter your diaspora* login details on the "Setup" tab.', 'wp-to-diaspora' ) . '
110
					<li>' . esc_html__( 'Define the default posting behaviour on the "Defaults" tab.', 'wp-to-diaspora' ) . '
111
					<li>' . esc_html__( 'Automatically share your WordPress post on diaspora* when publishing it on your website.', 'wp-to-diaspora' ) . '
112
					<li>' . esc_html__( 'Check out your new post on diaspora*.', 'wp-to-diaspora' ) . '
113
				</ol>'
114
		) );
115
116
		// How to set up the connection to diaspora*.
117
		$screen->add_help_tab( array(
118
			'id'      => 'setup',
119
			'title'   => esc_html__( 'Setup', 'wp-to-diaspora' ),
120
			'content' => '<p><strong>' . esc_html__( 'Enter your diaspora* login details to connect your account.', 'wp-to-diaspora' ) . '</strong></p>
121
				<ul>
122
					<li><strong>' . esc_html__( 'diaspora* Pod', 'wp-to-diaspora' ) . '</strong>: ' .
123
						esc_html__( 'This is the domain name of the pod you are on (e.g. joindiaspora.com)', 'wp-to-diaspora' ) . '
124
					<li><strong>' . esc_html__( 'Username', 'wp-to-diaspora' ) . '</strong>: ' .
125
						esc_html__( 'Your diaspora* username (without the pod domain).', 'wp-to-diaspora' ) . '
126
					<li><strong>' . esc_html__( 'Password', 'wp-to-diaspora' ) . '</strong>: ' .
127
						esc_html__( 'Your diaspora* password.', 'wp-to-diaspora' ) . '
128
				</ul>',
129
		) );
130
131
		// Explain the default options and what they do.
132
		$screen->add_help_tab( array(
133
			'id'      => 'defaults',
134
			'title'   => esc_html__( 'Defaults', 'wp-to-diaspora' ),
135
			'content' => '<p><strong>' . esc_html__( 'Define the default posting behaviour.', 'wp-to-diaspora' ) . '</strong></p>
136
				<ul>
137
					<li><strong>' . esc_html__( 'Post types', 'wp-to-diaspora' ) . '</strong>: ' .
138
						esc_html__( 'Choose the post types that are allowed to be shared to diaspora*.', 'wp-to-diaspora' ) . '
139
					<li><strong>' . esc_html__( 'Post to diaspora*', 'wp-to-diaspora' ) . '</strong>: ' .
140
						esc_html__( 'Automatically share new posts to diaspora* when publishing them.', 'wp-to-diaspora' ) . '
141
					<li><strong>' . esc_html__( 'Show "Posted at" link?', 'wp-to-diaspora' ) . '</strong>: ' .
142
						esc_html__( 'Add a link back to your original post, at the bottom of the diaspora* post.', 'wp-to-diaspora' ) . '
143
					<li><strong>' . esc_html__( 'Display', 'wp-to-diaspora' ) . '</strong>: ' .
144
						esc_html__( 'Choose whether you would like to post the whole post or just the excerpt.', 'wp-to-diaspora' ) . '
145
					<li><strong>' . esc_html__( 'Tags to post', 'wp-to-diaspora' ) . '</strong>: ' .
146
						esc_html__( 'You can add tags to your post to make it easier to find on diaspora*.' ) . '<br>
147
							<ul>
148
								<li><strong>' . esc_html__( 'Global tags', 'wp-to-diaspora' ) . '</strong>: ' . esc_html__( 'Tags that apply to all posts.', 'wp-to-diaspora' ) . '
149
								<li><strong>' . esc_html__( 'Custom tags', 'wp-to-diaspora' ) . '</strong>: ' . esc_html__( 'Tags that apply to individual posts (can be set on each post).', 'wp-to-diaspora' ) . '
150
								<li><strong>' . esc_html__( 'Post tags',   'wp-to-diaspora' ) . '</strong>: ' . esc_html__( 'Default WordPress Tags of individual posts.', 'wp-to-diaspora' ) . '
151
							</ul>
152
					<li><strong>' . esc_html__( 'Global tags', 'wp-to-diaspora' ) . '</strong>: ' .
153
						esc_html__( 'A list of tags that gets added to every post.', 'wp-to-diaspora' ) . '
154
					<li><strong>' . esc_html__( 'Aspects', 'wp-to-diaspora' ) . '</strong>: ' .
155
						esc_html__( 'Decide which of your diaspora* aspects can see your posts.', 'wp-to-diaspora' ) . '<br>
156
							<em>' . sprintf( esc_html__( 'Use the "%s" button to load your aspects from diaspora*.', 'wp-to-diaspora' ), esc_html__( 'Refresh Aspects', 'wp-to-diaspora' ) ) . '</em>
157
					<li><strong>' . esc_html__( 'Services', 'wp-to-diaspora' ) . '</strong>: ' .
158
						esc_html__( 'Choose the services your new diaspora* post gets shared to.', 'wp-to-diaspora' ) . '<br>
159
							<em>' . sprintf( esc_html__( 'Use the "%s" button to fetch the list of your connected services from diaspora*.', 'wp-to-diaspora' ), esc_html__( 'Refresh Services', 'wp-to-diaspora' ) ) . '</em>
160
				</ul>',
161
		) );
162
163
		$screen->add_help_tab( array(
164
			'id'      => 'ssl',
165
			'title'   => esc_html__( 'SSL', 'wp-to-diaspora' ),
166
			'content' => '<p><strong>' . esc_html__( 'WP to diaspora* makes sure the connection to your pod is secure!', 'wp-to-diaspora' ) . '</strong></p>
167
				<p>' . esc_html__( 'Most diaspora* pods are secured using SSL (Secure Sockets Layer), which makes your connection encrypted. For this connection to work, your server needs to know that those SSL certificates can be trusted.', 'wp-to-diaspora' ) . '</p>
168
				<p>' . esc_html__( 'Therefore, if your WordPress installation or server does not have an up to date CA certificate bundle, WP to diaspora* may not work for you.', 'wp-to-diaspora' ) . '</p>
169
				<p>' . esc_html__( 'Lucky for you though, we have you covered if this is the case for you!', 'wp-to-diaspora' ) . '</p>
170
				<p><a href="https://github.com/DiasPHPora/wp-to-diaspora/wiki/SSL-and-TLS-Issues">' . esc_html__( 'Learn more in the wiki', 'wp-to-diaspora' ) . '</a></p>'
171
		) );
172
173
		// Explain the meta box and the differences to the global defaults.
174
		$screen->add_help_tab( array(
175
			'id' => 'meta-box',
176
			'title'   => esc_html__( 'Meta Box', 'wp-to-diaspora' ),
177
			'content' => '<p><strong>' . esc_html__( 'The Meta Box is the new "WP to diaspora*" box you see when editing a post.', 'wp-to-diaspora' ) . '</strong></p>
178
				<p>' . esc_html__( 'When creating or editing a post, you will notice a new meta box called "WP to diaspora*" which has some options. These options are almost the same as the options you can find in the "Defaults" tab on the settings page. These options are post-specific though, meaning they override the global defaults for the post itself. You will see that the default values are filled in automatically, allowing you to change individual ones as you please.', 'wp-to-diaspora' ) . '</p>
179
				<p>' . esc_html__( 'There are a few important differences to the settings page:', 'wp-to-diaspora' ) . '</p>
180
				<ul>
181
					<li><strong>' . esc_html__( 'Already posted to diaspora*', 'wp-to-diaspora' ) . '</strong>: ' .
182
						esc_html__( 'If the post has already been posted to diaspora* a link to the diaspora* post will appear at the top.', 'wp-to-diaspora' ) . '
183
					<li><strong>' . esc_html__( 'Custom tags', 'wp-to-diaspora' ) . '</strong>: ' .
184
						esc_html__( 'A list of tags that gets added to this post. Note that they are seperate from the WordPress post tags!', 'wp-to-diaspora' ) . '
185
				</ul>
186
				<p class="dashicons-before dashicons-info">' . esc_html__( 'If you don\'t see the meta box, make sure the post type you\'re on has been added to the "Post types" list on the settings page. Also make sure it has been selected from the "Screen Options" at the top of the screen.', 'wp-to-diaspora' ) . '</p>',
187
		) );
188
189
		// Troubleshooting.
190
		$screen->add_help_tab( array(
191
			'id' => 'troubleshooting',
192
			'title'   => esc_html__( 'Troubleshooting', 'wp-to-diaspora' ),
193
			'content' => '<p><strong>' . esc_html__( 'Troubleshooting common errors.', 'wp-to-diaspora' ) . '</strong></p>
194
				<p>' . esc_html__( 'Here are a few common errors and their possible solutions:', 'wp-to-diaspora' ) . '</p>
195
				<ul>
196
					<li><strong>' . esc_html( sprintf( __( 'Failed to initialise connection to pod "%s"', 'wp-to-diaspora' ), 'xyz' ) ) . '</strong>: ' .
197
						esc_html__( 'This could have multiple reasons.' ) . '
198
						<ul>
199
							<li>' . esc_html__( 'Make sure that your pod domain is entered correctly.', 'wp-to-diaspora' ) . '
200
							<li>' .
201
								esc_html__( 'It might be an SSL problem.', 'wp-to-diaspora' ) .
202
								sprintf( ' <a href="https://github.com/DiasPHPora/wp-to-diaspora/wiki/SSL-and-TLS-Issues" class="open-help-tab" data-help-tab="ssl">%s</a>', esc_html__( 'Learn more', 'wp-to-diaspora' ) ) . '
203
							<li>' . esc_html__( 'The pod might be offline at the moment.', 'wp-to-diaspora' ) . '
204
						</ul>
205
					<li><strong>' . esc_html__( 'Login failed. Check your login details.', 'wp-to-diaspora' ) . '</strong>: ' .
206
						esc_html__( 'Make sure that your username and password are entered correctly.', 'wp-to-diaspora' ) . '
207
				</ul>',
208
		) );
209
210
		// Show different ways to contribute to the plugin.
211
		$screen->add_help_tab( array(
212
			'id' => 'contributing',
213
			'title'   => esc_html__( 'Contributing', 'wp-to-diaspora' ),
214
			'content' => '<p><strong>' . esc_html__( 'So you feel like contributing to the WP to diaspora* plugin? Great!', 'wp-to-diaspora' ) . '</strong></p>
215
				<p>' . esc_html__( 'There are many different ways that you can help out with this plugin:', 'wp-to-diaspora' ) . '</p>
216
				<ul>
217
					<li><a href="' . WP2D_EXT_GH_ISSUES_NEW . '" target="_blank">' . esc_html__( 'Report a bug', 'wp-to-diaspora' )           . '</a>
218
					<li><a href="' . WP2D_EXT_GH_ISSUES_NEW . '" target="_blank">' . esc_html__( 'Suggest a new feature', 'wp-to-diaspora' )  . '</a>
219
					<li><a href="' . WP2D_EXT_I18N          . '" target="_blank">' . esc_html__( 'Help with translations', 'wp-to-diaspora' ) . '</a>
220
					<li><a href="' . WP2D_EXT_DONATE        . '" target="_blank">' . esc_html__( 'Make a donation', 'wp-to-diaspora' )        . '</a>
221
				</ul>',
222
		) );
223
	}
224
225
	/**
226
	 * Add help tabs to the contextual help on the post pages.
227
	 */
228
	private function _add_post_type_help_tabs() {
229
		get_current_screen()->add_help_tab( array(
230
			'id'       => 'wp-to-diaspora',
231
			'title'    => esc_html__( 'WP to diaspora*', 'wp-to-diaspora' ),
232
			'content'  => '<p>' . sprintf(
233
				esc_html_x( 'For detailed information, refer to the contextual help on the %sWP to diaspora*%s settings page.', 'Placeholders represent the link.', 'wp-to-diaspora' ),
234
				'<a href="options-general.php?page=wp_to_diaspora" target="_blank">', '</a>'
235
			) . '</p>',
236
		) );
237
	}
238
239
	/**
240
	 * Get a link that directly opens a help tab via JS.
241
	 *
242
	 * @since 1.6.0
243
	 *
244
	 * @param WP_Error|string $error The WP_Error object with the tab id as data or the tab id itself.
245
	 * @return string HTML link.
246
	 */
247
	public static function get_help_tab_quick_link( $error ) {
248
		$help_tab = '';
249
		if ( is_wp_error( $error ) && ( $error_data = $error->get_error_data() ) && array_key_exists( 'help_tab', $error_data ) ) {
250
			$help_tab = $error_data['help_tab'];
251
		} elseif ( is_string( $error ) ) {
252
			$help_tab = $error;
253
		}
254
		if ( '' !== $help_tab ) {
255
			return sprintf( '<a href="#" class="open-help-tab" data-help-tab="%1$s">%2$s</a>', $help_tab, esc_html__( 'Help', 'wp-to-diaspora' ) );
256
		}
257
258
		return '';
259
	}
260
}
261