PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 7.6.2
Jetpack – WP Security, Backup, Speed, & Growth v7.6.2
16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 All 504 releases
jetpack / modules / theme-tools / content-options / post-details.php

post-details.php in Jetpack – WP Security, Backup, Speed, & Growth 7.6.2, at modules/theme-tools/content-options/post-details.php

151 lines 5.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The function to include Post Details in a theme's stylesheet.
4 */
5 function jetpack_post_details_enqueue_scripts() {
6 // Make sure we can proceed.
7 list( $should_run, $options, $definied, $post_details ) = jetpack_post_details_should_run();
8
9 if ( ! $should_run ) {
10 return;
11 }
12
13 list( $date_option, $categories_option, $tags_option, $author_option, $comment_option ) = $options;
14 list( $date, $categories, $tags, $author, $comment ) = $definied;
15
16 $elements = array();
17
18 // If date option is unticked, add it to the list of classes.
19 if ( 1 != $date_option && ! empty( $date ) ) {
20 $elements[] = $date;
21 }
22
23 // If categories option is unticked, add it to the list of classes.
24 if ( 1 != $categories_option && ! empty( $categories ) ) {
25 $elements[] = $categories;
26 }
27
28 // If tags option is unticked, add it to the list of classes.
29 if ( 1 != $tags_option && ! empty( $tags ) ) {
30 $elements[] = $tags;
31 }
32
33 // If author option is unticked, add it to the list of classes.
34 if ( 1 != $author_option && ! empty( $author ) ) {
35 $elements[] = $author;
36 }
37
38 // If comment option is unticked, add it to the list of classes.
39 if ( 1 != $comment_option && ! empty( $comment ) ) {
40 $elements[] = $comment;
41 }
42
43 // Get the list of classes.
44 $elements = implode( ', ', $elements );
45
46 // Hide the classes with CSS.
47 $css = $elements . ' { clip: rect(1px, 1px, 1px, 1px); height: 1px; position: absolute; overflow: hidden; width: 1px; }';
48
49 // Add the CSS to the stylesheet.
50 wp_add_inline_style( $post_details['stylesheet'], $css );
51 }
52 add_action( 'wp_enqueue_scripts', 'jetpack_post_details_enqueue_scripts' );
53
54 /**
55 * Adds custom classes to the array of body classes.
56 */
57 function jetpack_post_details_body_classes( $classes ) {
58 // Make sure we can proceed.
59 list( $should_run, $options, $definied ) = jetpack_post_details_should_run();
60
61 if ( ! $should_run ) {
62 return $classes;
63 }
64
65 list( $date_option, $categories_option, $tags_option, $author_option, $comment_option ) = $options;
66 list( $date, $categories, $tags, $author, $comment ) = $definied;
67
68 // If date option is unticked, add a class of 'date-hidden' to the body.
69 if ( 1 != $date_option && ! empty( $date ) ) {
70 $classes[] = 'date-hidden';
71 }
72
73 // If categories option is unticked, add a class of 'categories-hidden' to the body.
74 if ( 1 != $categories_option && ! empty( $categories ) ) {
75 $classes[] = 'categories-hidden';
76 }
77
78 // If tags option is unticked, add a class of 'tags-hidden' to the body.
79 if ( 1 != $tags_option && ! empty( $tags ) ) {
80 $classes[] = 'tags-hidden';
81 }
82
83 // If author option is unticked, add a class of 'author-hidden' to the body.
84 if ( 1 != $author_option && ! empty( $author ) ) {
85 $classes[] = 'author-hidden';
86 }
87
88 // If comment option is unticked, add a class of 'comment-hidden' to the body.
89 if ( 1 != $comment_option && ! empty( $comment ) ) {
90 $classes[] = 'comment-hidden';
91 }
92
93 return $classes;
94 }
95 add_filter( 'body_class', 'jetpack_post_details_body_classes' );
96
97 /**
98 * Determines if Post Details should run.
99 */
100 function jetpack_post_details_should_run() {
101 // Empty value representing falsy return value.
102 $void = array( false, null, null, null );
103
104 // If the theme doesn't support 'jetpack-content-options', don't continue.
105 if ( ! current_theme_supports( 'jetpack-content-options' ) ) {
106 return $void;
107 }
108
109 $options = get_theme_support( 'jetpack-content-options' );
110 $post_details = ( ! empty( $options[0]['post-details'] ) ) ? $options[0]['post-details'] : null;
111
112 // If the theme doesn't support 'jetpack-content-options[ 'post-details' ]', don't continue.
113 if ( empty( $post_details ) ) {
114 return $void;
115 }
116
117 $date = ( ! empty( $post_details['date'] ) ) ? $post_details['date'] : null;
118 $categories = ( ! empty( $post_details['categories'] ) ) ? $post_details['categories'] : null;
119 $tags = ( ! empty( $post_details['tags'] ) ) ? $post_details['tags'] : null;
120 $author = ( ! empty( $post_details['author'] ) ) ? $post_details['author'] : null;
121 $comment = ( ! empty( $post_details['comment'] ) ) ? $post_details['comment'] : null;
122
123 // If there is no stylesheet and there are no date, categories, tags, author or comment declared, don't continue.
124 if (
125 empty( $post_details['stylesheet'] )
126 && ( empty( $date )
127 || empty( $categories )
128 || empty( $tags )
129 || empty( $author )
130 || empty( $comment ) )
131 ) {
132 return $void;
133 }
134
135 $date_option = get_option( 'jetpack_content_post_details_date', 1 );
136 $categories_option = get_option( 'jetpack_content_post_details_categories', 1 );
137 $tags_option = get_option( 'jetpack_content_post_details_tags', 1 );
138 $author_option = get_option( 'jetpack_content_post_details_author', 1 );
139 $comment_option = get_option( 'jetpack_content_post_details_comment', 1 );
140
141 $options = array( $date_option, $categories_option, $tags_option, $author_option, $comment_option );
142 $definied = array( $date, $categories, $tags, $author, $comment );
143
144 // If all the options are ticked, don't continue.
145 if ( array( 1, 1, 1, 1, 1 ) === $options ) {
146 return $void;
147 }
148
149 return array( true, $options, $definied, $post_details );
150 }
151