← All changes
|
modules/theme-tools/content-options/post-details.php
+144
-120
13.7.2
→
16.3-a.1
View file →
| @@ -4,160 +4,184 @@ | ||
| 4 | 4 | * |
| 5 | 5 | * @package automattic/jetpack |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -/** | |
| 9 | - * The function to include Post Details in a theme's stylesheet. | |
| 10 | - */ | |
| 11 | -function jetpack_post_details_enqueue_scripts() { | |
| 12 | - // Make sure we can proceed. | |
| 13 | - list( $should_run, $options, $definied, $post_details ) = jetpack_post_details_should_run(); | |
| 8 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 9 | + exit( 0 ); | |
| 10 | +} | |
| 14 | 11 | |
| 15 | - if ( ! $should_run ) { | |
| 16 | - return; | |
| 17 | - } | |
| 12 | +if ( ! function_exists( 'jetpack_post_details_enqueue_scripts' ) ) { | |
| 18 | 13 | |
| 19 | - list( $date_option, $categories_option, $tags_option, $author_option, $comment_option ) = $options; | |
| 20 | - list( $date, $categories, $tags, $author, $comment ) = $definied; | |
| 14 | + /** | |
| 15 | + * The function to include Post Details in a theme's stylesheet. | |
| 16 | + * | |
| 17 | + * @deprecated 13.9 Moved to Classic Theme Helper package. | |
| 18 | + */ | |
| 19 | + function jetpack_post_details_enqueue_scripts() { | |
| 20 | + _deprecated_function( __FUNCTION__, 'jetpack-13.9' ); | |
| 21 | + // Make sure we can proceed. | |
| 22 | + list( $should_run, $options, $definied, $post_details ) = jetpack_post_details_should_run(); | |
| 21 | 23 | |
| 22 | - $elements = array(); | |
| 24 | + if ( ! $should_run ) { | |
| 25 | + return; | |
| 26 | + } | |
| 23 | 27 | |
| 24 | - // If date option is unticked, add it to the list of classes. | |
| 25 | - if ( 1 !== (int) $date_option && ! empty( $date ) ) { | |
| 26 | - $elements[] = $date; | |
| 27 | - } | |
| 28 | + list( $date_option, $categories_option, $tags_option, $author_option, $comment_option ) = $options; | |
| 29 | + list( $date, $categories, $tags, $author, $comment ) = $definied; | |
| 28 | 30 | |
| 29 | - // If categories option is unticked, add it to the list of classes. | |
| 30 | - if ( 1 !== (int) $categories_option && ! empty( $categories ) ) { | |
| 31 | - $elements[] = $categories; | |
| 32 | - } | |
| 31 | + $elements = array(); | |
| 33 | 32 | |
| 34 | - // If tags option is unticked, add it to the list of classes. | |
| 35 | - if ( 1 !== (int) $tags_option && ! empty( $tags ) ) { | |
| 36 | - $elements[] = $tags; | |
| 37 | - } | |
| 33 | + // If date option is unticked, add it to the list of classes. | |
| 34 | + if ( 1 !== (int) $date_option && ! empty( $date ) ) { | |
| 35 | + $elements[] = $date; | |
| 36 | + } | |
| 38 | 37 | |
| 39 | - // If author option is unticked, add it to the list of classes. | |
| 40 | - if ( 1 !== (int) $author_option && ! empty( $author ) ) { | |
| 41 | - $elements[] = $author; | |
| 42 | - } | |
| 38 | + // If categories option is unticked, add it to the list of classes. | |
| 39 | + if ( 1 !== (int) $categories_option && ! empty( $categories ) ) { | |
| 40 | + $elements[] = $categories; | |
| 41 | + } | |
| 43 | 42 | |
| 44 | - // If comment option is unticked, add it to the list of classes. | |
| 45 | - if ( 1 !== (int) $comment_option && ! empty( $comment ) ) { | |
| 46 | - $elements[] = $comment; | |
| 47 | - } | |
| 43 | + // If tags option is unticked, add it to the list of classes. | |
| 44 | + if ( 1 !== (int) $tags_option && ! empty( $tags ) ) { | |
| 45 | + $elements[] = $tags; | |
| 46 | + } | |
| 48 | 47 | |
| 49 | - // If the Elements array is empty, return without setting custom CSS. | |
| 50 | - if ( empty( $elements ) ) { | |
| 51 | - return; | |
| 48 | + // If author option is unticked, add it to the list of classes. | |
| 49 | + if ( 1 !== (int) $author_option && ! empty( $author ) ) { | |
| 50 | + $elements[] = $author; | |
| 51 | + } | |
| 52 | + | |
| 53 | + // If comment option is unticked, add it to the list of classes. | |
| 54 | + if ( 1 !== (int) $comment_option && ! empty( $comment ) ) { | |
| 55 | + $elements[] = $comment; | |
| 56 | + } | |
| 57 | + | |
| 58 | + // If the Elements array is empty, return without setting custom CSS. | |
| 59 | + if ( empty( $elements ) ) { | |
| 60 | + return; | |
| 61 | + } | |
| 62 | + | |
| 63 | + // Get the list of classes. | |
| 64 | + $elements = implode( ', ', $elements ); | |
| 65 | + | |
| 66 | + // Hide the classes with CSS. | |
| 67 | + $css = $elements . ' { clip: rect(1px, 1px, 1px, 1px); height: 1px; position: absolute; overflow: hidden; width: 1px; }'; | |
| 68 | + | |
| 69 | + // Add the CSS to the stylesheet. | |
| 70 | + wp_add_inline_style( $post_details['stylesheet'], $css ); | |
| 52 | 71 | } |
| 72 | + add_action( 'wp_enqueue_scripts', 'jetpack_post_details_enqueue_scripts' ); | |
| 53 | 73 | |
| 54 | - // Get the list of classes. | |
| 55 | - $elements = implode( ', ', $elements ); | |
| 74 | +} | |
| 56 | 75 | |
| 57 | - // Hide the classes with CSS. | |
| 58 | - $css = $elements . ' { clip: rect(1px, 1px, 1px, 1px); height: 1px; position: absolute; overflow: hidden; width: 1px; }'; | |
| 76 | +if ( ! function_exists( 'jetpack_post_details_body_classes' ) ) { | |
| 59 | 77 | |
| 60 | - // Add the CSS to the stylesheet. | |
| 61 | - wp_add_inline_style( $post_details['stylesheet'], $css ); | |
| 62 | -} | |
| 63 | -add_action( 'wp_enqueue_scripts', 'jetpack_post_details_enqueue_scripts' ); | |
| 78 | + /** | |
| 79 | + * Adds custom classes to the array of body classes. | |
| 80 | + * | |
| 81 | + * @deprecated 13.9 Moved to Classic Theme Helper package. | |
| 82 | + * @param array $classes Classes for the body element. | |
| 83 | + */ | |
| 84 | + function jetpack_post_details_body_classes( $classes ) { | |
| 85 | + _deprecated_function( __FUNCTION__, 'jetpack-13.9' ); | |
| 86 | + // Make sure we can proceed. | |
| 87 | + list( $should_run, $options, $definied ) = jetpack_post_details_should_run(); | |
| 64 | 88 | |
| 65 | -/** | |
| 66 | - * Adds custom classes to the array of body classes. | |
| 67 | - * | |
| 68 | - * @param array $classes Classes for the body element. | |
| 69 | - */ | |
| 70 | -function jetpack_post_details_body_classes( $classes ) { | |
| 71 | - // Make sure we can proceed. | |
| 72 | - list( $should_run, $options, $definied ) = jetpack_post_details_should_run(); | |
| 89 | + if ( ! $should_run ) { | |
| 90 | + return $classes; | |
| 91 | + } | |
| 73 | 92 | |
| 74 | - if ( ! $should_run ) { | |
| 75 | - return $classes; | |
| 76 | - } | |
| 93 | + list( $date_option, $categories_option, $tags_option, $author_option, $comment_option ) = $options; | |
| 94 | + list( $date, $categories, $tags, $author, $comment ) = $definied; | |
| 77 | 95 | |
| 78 | - list( $date_option, $categories_option, $tags_option, $author_option, $comment_option ) = $options; | |
| 79 | - list( $date, $categories, $tags, $author, $comment ) = $definied; | |
| 96 | + // If date option is unticked, add a class of 'date-hidden' to the body. | |
| 97 | + if ( 1 !== (int) $date_option && ! empty( $date ) ) { | |
| 98 | + $classes[] = 'date-hidden'; | |
| 99 | + } | |
| 80 | 100 | |
| 81 | - // If date option is unticked, add a class of 'date-hidden' to the body. | |
| 82 | - if ( 1 !== (int) $date_option && ! empty( $date ) ) { | |
| 83 | - $classes[] = 'date-hidden'; | |
| 84 | - } | |
| 101 | + // If categories option is unticked, add a class of 'categories-hidden' to the body. | |
| 102 | + if ( 1 !== (int) $categories_option && ! empty( $categories ) ) { | |
| 103 | + $classes[] = 'categories-hidden'; | |
| 104 | + } | |
| 85 | 105 | |
| 86 | - // If categories option is unticked, add a class of 'categories-hidden' to the body. | |
| 87 | - if ( 1 !== (int) $categories_option && ! empty( $categories ) ) { | |
| 88 | - $classes[] = 'categories-hidden'; | |
| 89 | - } | |
| 106 | + // If tags option is unticked, add a class of 'tags-hidden' to the body. | |
| 107 | + if ( 1 !== (int) $tags_option && ! empty( $tags ) ) { | |
| 108 | + $classes[] = 'tags-hidden'; | |
| 109 | + } | |
| 90 | 110 | |
| 91 | - // If tags option is unticked, add a class of 'tags-hidden' to the body. | |
| 92 | - if ( 1 !== (int) $tags_option && ! empty( $tags ) ) { | |
| 93 | - $classes[] = 'tags-hidden'; | |
| 94 | - } | |
| 111 | + // If author option is unticked, add a class of 'author-hidden' to the body. | |
| 112 | + if ( 1 !== (int) $author_option && ! empty( $author ) ) { | |
| 113 | + $classes[] = 'author-hidden'; | |
| 114 | + } | |
| 95 | 115 | |
| 96 | - // If author option is unticked, add a class of 'author-hidden' to the body. | |
| 97 | - if ( 1 !== (int) $author_option && ! empty( $author ) ) { | |
| 98 | - $classes[] = 'author-hidden'; | |
| 99 | - } | |
| 116 | + // If comment option is unticked, add a class of 'comment-hidden' to the body. | |
| 117 | + if ( 1 !== (int) $comment_option && ! empty( $comment ) ) { | |
| 118 | + $classes[] = 'comment-hidden'; | |
| 119 | + } | |
| 100 | 120 | |
| 101 | - // If comment option is unticked, add a class of 'comment-hidden' to the body. | |
| 102 | - if ( 1 !== (int) $comment_option && ! empty( $comment ) ) { | |
| 103 | - $classes[] = 'comment-hidden'; | |
| 121 | + return $classes; | |
| 104 | 122 | } |
| 123 | + add_filter( 'body_class', 'jetpack_post_details_body_classes' ); | |
| 105 | 124 | |
| 106 | - return $classes; | |
| 107 | 125 | } |
| 108 | -add_filter( 'body_class', 'jetpack_post_details_body_classes' ); | |
| 109 | 126 | |
| 110 | -/** | |
| 111 | - * Determines if Post Details should run. | |
| 112 | - */ | |
| 113 | -function jetpack_post_details_should_run() { | |
| 114 | - // Empty value representing falsy return value. | |
| 115 | - $void = array( false, null, null, null ); | |
| 127 | +if ( ! function_exists( 'jetpack_post_details_should_run' ) ) { | |
| 116 | 128 | |
| 117 | - // If the theme doesn't support 'jetpack-content-options', don't continue. | |
| 118 | - if ( ! current_theme_supports( 'jetpack-content-options' ) ) { | |
| 119 | - return $void; | |
| 120 | - } | |
| 129 | + /** | |
| 130 | + * Determines if Post Details should run. | |
| 131 | + * | |
| 132 | + * @deprecated 13.9 Moved to Classic Theme Helper package. | |
| 133 | + */ | |
| 134 | + function jetpack_post_details_should_run() { | |
| 135 | + _deprecated_function( __FUNCTION__, 'jetpack-13.9' ); | |
| 136 | + // Empty value representing falsy return value. | |
| 137 | + $void = array( false, null, null, null ); | |
| 121 | 138 | |
| 122 | - $options = get_theme_support( 'jetpack-content-options' ); | |
| 123 | - $post_details = ( ! empty( $options[0]['post-details'] ) ) ? $options[0]['post-details'] : null; | |
| 139 | + // If the theme doesn't support 'jetpack-content-options', don't continue. | |
| 140 | + if ( ! current_theme_supports( 'jetpack-content-options' ) ) { | |
| 141 | + return $void; | |
| 142 | + } | |
| 124 | 143 | |
| 125 | - // If the theme doesn't support 'jetpack-content-options[ 'post-details' ]', don't continue. | |
| 126 | - if ( empty( $post_details ) ) { | |
| 127 | - return $void; | |
| 128 | - } | |
| 144 | + $options = get_theme_support( 'jetpack-content-options' ); | |
| 145 | + $post_details = ( ! empty( $options[0]['post-details'] ) ) ? $options[0]['post-details'] : null; | |
| 129 | 146 | |
| 130 | - $date = ( ! empty( $post_details['date'] ) ) ? $post_details['date'] : null; | |
| 131 | - $categories = ( ! empty( $post_details['categories'] ) ) ? $post_details['categories'] : null; | |
| 132 | - $tags = ( ! empty( $post_details['tags'] ) ) ? $post_details['tags'] : null; | |
| 133 | - $author = ( ! empty( $post_details['author'] ) ) ? $post_details['author'] : null; | |
| 134 | - $comment = ( ! empty( $post_details['comment'] ) ) ? $post_details['comment'] : null; | |
| 147 | + // If the theme doesn't support 'jetpack-content-options[ 'post-details' ]', don't continue. | |
| 148 | + if ( empty( $post_details ) ) { | |
| 149 | + return $void; | |
| 150 | + } | |
| 135 | 151 | |
| 136 | - // If there is no stylesheet and there are no date, categories, tags, author or comment declared, don't continue. | |
| 137 | - if ( | |
| 138 | - empty( $post_details['stylesheet'] ) | |
| 139 | - && ( empty( $date ) | |
| 140 | - || empty( $categories ) | |
| 141 | - || empty( $tags ) | |
| 142 | - || empty( $author ) | |
| 143 | - || empty( $comment ) ) | |
| 144 | - ) { | |
| 145 | - return $void; | |
| 146 | - } | |
| 152 | + $date = ( ! empty( $post_details['date'] ) ) ? $post_details['date'] : null; | |
| 153 | + $categories = ( ! empty( $post_details['categories'] ) ) ? $post_details['categories'] : null; | |
| 154 | + $tags = ( ! empty( $post_details['tags'] ) ) ? $post_details['tags'] : null; | |
| 155 | + $author = ( ! empty( $post_details['author'] ) ) ? $post_details['author'] : null; | |
| 156 | + $comment = ( ! empty( $post_details['comment'] ) ) ? $post_details['comment'] : null; | |
| 147 | 157 | |
| 148 | - $date_option = Jetpack_Options::get_option_and_ensure_autoload( 'jetpack_content_post_details_date', 1 ); | |
| 149 | - $categories_option = Jetpack_Options::get_option_and_ensure_autoload( 'jetpack_content_post_details_categories', 1 ); | |
| 150 | - $tags_option = Jetpack_Options::get_option_and_ensure_autoload( 'jetpack_content_post_details_tags', 1 ); | |
| 151 | - $author_option = Jetpack_Options::get_option_and_ensure_autoload( 'jetpack_content_post_details_author', 1 ); | |
| 152 | - $comment_option = Jetpack_Options::get_option_and_ensure_autoload( 'jetpack_content_post_details_comment', 1 ); | |
| 158 | + // If there is no stylesheet and there are no date, categories, tags, author or comment declared, don't continue. | |
| 159 | + if ( | |
| 160 | + empty( $post_details['stylesheet'] ) | |
| 161 | + && ( empty( $date ) | |
| 162 | + || empty( $categories ) | |
| 163 | + || empty( $tags ) | |
| 164 | + || empty( $author ) | |
| 165 | + || empty( $comment ) ) | |
| 166 | + ) { | |
| 167 | + return $void; | |
| 168 | + } | |
| 153 | 169 | |
| 154 | - $options = array( $date_option, $categories_option, $tags_option, $author_option, $comment_option ); | |
| 155 | - $definied = array( $date, $categories, $tags, $author, $comment ); | |
| 170 | + $date_option = Jetpack_Options::get_option_and_ensure_autoload( 'jetpack_content_post_details_date', 1 ); | |
| 171 | + $categories_option = Jetpack_Options::get_option_and_ensure_autoload( 'jetpack_content_post_details_categories', 1 ); | |
| 172 | + $tags_option = Jetpack_Options::get_option_and_ensure_autoload( 'jetpack_content_post_details_tags', 1 ); | |
| 173 | + $author_option = Jetpack_Options::get_option_and_ensure_autoload( 'jetpack_content_post_details_author', 1 ); | |
| 174 | + $comment_option = Jetpack_Options::get_option_and_ensure_autoload( 'jetpack_content_post_details_comment', 1 ); | |
| 156 | 175 | |
| 157 | - // If all the options are ticked, don't continue. | |
| 158 | - if ( array( 1, 1, 1, 1, 1 ) === $options ) { | |
| 159 | - return $void; | |
| 176 | + $options = array( $date_option, $categories_option, $tags_option, $author_option, $comment_option ); | |
| 177 | + $definied = array( $date, $categories, $tags, $author, $comment ); | |
| 178 | + | |
| 179 | + // If all the options are ticked, don't continue. | |
| 180 | + if ( array( 1, 1, 1, 1, 1 ) === $options ) { | |
| 181 | + return $void; | |
| 182 | + } | |
| 183 | + | |
| 184 | + return array( true, $options, $definied, $post_details ); | |
| 160 | 185 | } |
| 161 | 186 | |
| 162 | - return array( true, $options, $definied, $post_details ); | |
| 163 | 187 | } |