Completed
Push — fix/markdown-auto-enable ( d52805 )
by Jeremy
09:50
created

markdown.php ➔ jetpack_markdown_posting_always_on()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Module Name: Markdown
5
 * Module Description: Write posts or pages in plain-text Markdown syntax.
6
 * Sort Order: 31
7
 * First Introduced: 2.8
8
 * Requires Connection: No
9
 * Auto Activate: No
10
 * Module Tags: Writing
11
 * Feature: Writing
12
 * Additional Search Queries: md, markdown
13
 */
14
15
include dirname( __FILE__ ) . '/markdown/easy-markdown.php';
16
17
/**
18
 * Markdown should be enabled for posts whenever the module is active.
19
 * We don't need any additional checkbox in Settings > Writing for that option.
20
 *
21
 * In addition to the filter above, the option is also automatically set when
22
 * the Markdown module is activated, thanks to the jetpack_activate_module_markdown filter.
23
 *
24
 * @see https://github.com/Automattic/jetpack/pull/6548
25
 */
26
27
// Step 1. Force the option on whenever this file is loaded (i.e. when the module is acive).
28
add_filter( 'pre_option_' . WPCom_Markdown::POST_OPTION, '__return_true' );
29
30
/**
31
 * Step 2: remove checkbox set in modules/markdown/easy-markdown.php.
32
 * We don't just remove the register_setting call there because the checkbox is
33
 * needed on WordPress.com, where the file is sync'ed verbatim.
34
 */
35
function jetpack_markdown_posting_always_on() {
36
	// why oh why isn't there a remove_settings_field?
37
	global $wp_settings_fields;
38
	if ( isset( $wp_settings_fields['writing']['default'][ WPCom_Markdown::POST_OPTION ] ) ) {
39
		unset( $wp_settings_fields['writing']['default'][ WPCom_Markdown::POST_OPTION ] );
40
	}
41
}
42
add_action( 'admin_init', 'jetpack_markdown_posting_always_on', 11 );
43