1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Content Options. |
4
|
|
|
* |
5
|
|
|
* This feature will only be activated for themes that declare their support. |
6
|
|
|
* This can be done by adding code similar to the following during the |
7
|
|
|
* 'after_setup_theme' action: |
8
|
|
|
* |
9
|
|
|
add_theme_support( 'jetpack-content-options', array( |
10
|
|
|
'blog-display' => 'content', // the default setting of the theme: 'content', 'excerpt' or array( 'content', 'excerpt' ) for themes mixing both display. |
11
|
|
|
'author-bio' => true, // display or not the author bio: true or false. |
12
|
|
|
'author-bio-default' => false, // the default setting of the author bio, if it's being displayed or not: true or false (only required if false). |
13
|
|
|
'masonry' => '.site-main', // a CSS selector matching the elements that triggers a masonry refresh if the theme is using a masonry layout. |
14
|
|
|
'post-details' => array( |
15
|
|
|
'stylesheet' => 'themeslug-style', // name of the theme's stylesheet. |
16
|
|
|
'date' => '.posted-on', // a CSS selector matching the elements that display the post date. |
17
|
|
|
'categories' => '.cat-links', // a CSS selector matching the elements that display the post categories. |
18
|
|
|
'tags' => '.tags-links', // a CSS selector matching the elements that display the post tags. |
19
|
|
|
'author' => '.byline', // a CSS selector matching the elements that display the post author. |
20
|
|
|
), |
21
|
|
|
'featured-images' => array( |
22
|
|
|
'archive' => true, // enable or not the featured image check for archive pages: true or false. |
23
|
|
|
'archive-default' => false, // the default setting of the featured image on archive pages, if it's being displayed or not: true or false (only required if false). |
24
|
|
|
'post' => true, // enable or not the featured image check for single posts: true or false. |
25
|
|
|
'post-default' => false, // the default setting of the featured image on single posts, if it's being displayed or not: true or false (only required if false). |
26
|
|
|
'page' => true, // enable or not the featured image check for single pages: true or false. |
27
|
|
|
'page-default' => false, // the default setting of the featured image on single pages, if it's being displayed or not: true or false (only required if false). |
28
|
|
|
), |
29
|
|
|
) ); |
30
|
|
|
* |
31
|
|
|
*/ |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Activate the Content Options plugin. |
35
|
|
|
* |
36
|
|
|
* @uses current_theme_supports() |
37
|
|
|
*/ |
38
|
|
|
function jetpack_content_options_init() { |
39
|
|
|
// If the theme doesn't support 'jetpack-content-options', don't continue. |
40
|
|
|
if ( ! current_theme_supports( 'jetpack-content-options' ) ) { |
41
|
|
|
return; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
// Load the Customizer options. |
45
|
|
|
require( dirname( __FILE__ ) . '/content-options/customizer.php' ); |
46
|
|
|
|
47
|
|
|
// Load Blog Display function. |
48
|
|
|
require( dirname( __FILE__ ) . '/content-options/blog-display.php' ); |
49
|
|
|
|
50
|
|
|
// Load Author Bio function. |
51
|
|
|
require( dirname( __FILE__ ) . '/content-options/author-bio.php' ); |
52
|
|
|
|
53
|
|
|
// Load Post Details function. |
54
|
|
|
require( dirname( __FILE__ ) . '/content-options/post-details.php' ); |
55
|
|
|
|
56
|
|
|
// Load Featured Images function. |
57
|
|
|
if ( jetpack_featured_images_should_load() ) { |
58
|
|
|
require( dirname( __FILE__ ) . '/content-options/featured-images.php' ); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
add_action( 'init', 'jetpack_content_options_init' ); |
62
|
|
|
|
63
|
|
|
function jetpack_featured_images_get_settings() { |
64
|
|
|
$options = get_theme_support( 'jetpack-content-options' ); |
65
|
|
|
$featured_images = ( ! empty( $options[0]['featured-images'] ) ) ? $options[0]['featured-images'] : null; |
66
|
|
|
|
67
|
|
|
$settings = array( |
|
|
|
|
68
|
|
|
'archive' => ( ! empty( $featured_images['archive'] ) ) ? $featured_images['archive'] : null, |
69
|
|
|
'post' => ( ! empty( $featured_images['post'] ) ) ? $featured_images['post'] : null, |
70
|
|
|
'page' => ( ! empty( $featured_images['page'] ) ) ? $featured_images['page'] : null, |
71
|
|
|
'archive-default' => ( isset( $featured_images['archive-default'] ) && false === $featured_images['archive-default'] ) ? '' : 1, |
72
|
|
|
'post-default' => ( isset( $featured_images['post-default'] ) && false === $featured_images['post-default'] ) ? '' : 1, |
73
|
|
|
'page-default' => ( isset( $featured_images['page-default'] ) && false === $featured_images['page-default'] ) ? '' : 1, |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
$settings = array_merge( $settings, array( |
|
|
|
|
77
|
|
|
'archive-option' => get_option( 'jetpack_content_featured_images_archive', $settings['archive-default'] ), |
78
|
|
|
'post-option' => get_option( 'jetpack_content_featured_images_post', $settings['post-default'] ), |
79
|
|
|
'page-option' => get_option( 'jetpack_content_featured_images_page', $settings['page-default'] ), |
80
|
|
|
) ); |
81
|
|
|
|
82
|
|
|
return $settings; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
function jetpack_featured_images_should_load() { |
86
|
|
|
$opts = jetpack_featured_images_get_settings(); |
87
|
|
|
|
88
|
|
|
// If the theme doesn't support archive, post and page or if all the options are ticked, don't continue. |
89
|
|
|
if ( ( true !== $opts['archive'] && true !== $opts['post'] && true !== $opts['page'] ) |
90
|
|
|
|| ( 1 === $opts['archive-option'] && 1 === $opts['post-option'] && 1 === $opts['page-option'] ) ) { |
91
|
|
|
return false; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return true; |
95
|
|
|
} |
96
|
|
|
|
This check looks for improperly formatted assignments.
Every assignment must have exactly one space before and one space after the equals operator.
To illustrate:
will have no issues, while
will report issues in lines 1 and 2.