diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2019-01-01 22:18:11 -0500 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2019-01-01 22:18:11 -0500 |
commit | 018bd442ec1e04ba78a6628763414eb60b359398 (patch) | |
tree | 448cde462397af33e5a964ba5d0803b73c65040e /plugins/jetpack/modules/theme-tools | |
parent | Update easy-table 1.8 (diff) | |
download | blogs-gentoo-018bd442ec1e04ba78a6628763414eb60b359398.tar.gz blogs-gentoo-018bd442ec1e04ba78a6628763414eb60b359398.tar.bz2 blogs-gentoo-018bd442ec1e04ba78a6628763414eb60b359398.zip |
Update jetpack 6.8.1
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'plugins/jetpack/modules/theme-tools')
30 files changed, 1963 insertions, 1299 deletions
diff --git a/plugins/jetpack/modules/theme-tools/compat/twentyfifteen-rtl.css b/plugins/jetpack/modules/theme-tools/compat/twentyfifteen-rtl.css index cd2a372c..7557cfd5 100644 --- a/plugins/jetpack/modules/theme-tools/compat/twentyfifteen-rtl.css +++ b/plugins/jetpack/modules/theme-tools/compat/twentyfifteen-rtl.css @@ -163,13 +163,15 @@ margin-bottom: 0; } -/* Polldaddy */ -.PDS_Poll { +/* Crowdsignal */ +.PDS_Poll, +.CSS_Poll { display: block !important; margin-bottom: 1.6em; } -.PDS_Poll .pds-box { +.PDS_Poll .pds-box, +.CSS_Poll .css-box { max-width: 100%; width: auto; } @@ -378,6 +380,7 @@ iframe[id*="twitter-widget-"] { .hentry .fb_iframe_widget, .hentry .googlemaps, .hentry .PDS_Poll, + .hentry .CSS_Poll, .site .hentry .presentation-wrapper, .site .hentry .jetpack-recipe, .site .hentry .slideshow-window, @@ -388,6 +391,7 @@ iframe[id*="twitter-widget-"] { .widget .fb_iframe_widget, .widget .googlemaps, .widget .PDS_Poll, + .widget .CSS_Poll, .site .widget .presentation-wrapper, .site .widget .jetpack-recipe, .site .widget .slideshow-window, @@ -479,6 +483,7 @@ iframe[id*="twitter-widget-"] { .hentry .fb_iframe_widget, .hentry .googlemaps, .hentry .PDS_Poll, + .hentry .CSS_Poll, .site .hentry .presentation-wrapper, .site .hentry .jetpack-recipe, .site .hentry .slideshow-window, @@ -549,6 +554,7 @@ iframe[id*="twitter-widget-"] { .hentry .fb_iframe_widget, .hentry .googlemaps, .hentry .PDS_Poll, + .hentry .CSS_Poll, .site .hentry .presentation-wrapper, .site .hentry .jetpack-recipe, .site .hentry .slideshow-window, @@ -622,6 +628,7 @@ iframe[id*="twitter-widget-"] { .hentry .fb_iframe_widget, .hentry .googlemaps, .hentry .PDS_Poll, + .hentry .CSS_Poll, .site .hentry .presentation-wrapper, .site .hentry .jetpack-recipe, .site .hentry .slideshow-window, @@ -691,6 +698,7 @@ iframe[id*="twitter-widget-"] { .hentry .fb_iframe_widget, .hentry .googlemaps, .hentry .PDS_Poll, + .hentry .CSS_Poll, .site .hentry .presentation-wrapper, .site .hentry .jetpack-recipe, .site .hentry .slideshow-window, diff --git a/plugins/jetpack/modules/theme-tools/compat/twentyfifteen.css b/plugins/jetpack/modules/theme-tools/compat/twentyfifteen.css index f436f635..cd343681 100644 --- a/plugins/jetpack/modules/theme-tools/compat/twentyfifteen.css +++ b/plugins/jetpack/modules/theme-tools/compat/twentyfifteen.css @@ -188,13 +188,15 @@ margin-bottom: 0; } -/* Polldaddy */ -.PDS_Poll { +/* Crowdsignal */ +.PDS_Poll, +.CSS_Poll { display: block !important; margin-bottom: 1.6em; } -.PDS_Poll .pds-box { +.PDS_Poll .pds-box, +.CSS_Poll .css-box { max-width: 100%; width: auto; } @@ -403,6 +405,7 @@ iframe[id*="twitter-widget-"] { .hentry .fb_iframe_widget, .hentry .googlemaps, .hentry .PDS_Poll, + .hentry .CSS_Poll, .site .hentry .presentation-wrapper, .site .hentry .jetpack-recipe, .site .hentry .slideshow-window, @@ -413,6 +416,7 @@ iframe[id*="twitter-widget-"] { .widget .fb_iframe_widget, .widget .googlemaps, .widget .PDS_Poll, + .widget .CSS_Poll, .site .widget .presentation-wrapper, .site .widget .jetpack-recipe, .site .widget .slideshow-window, @@ -504,6 +508,7 @@ iframe[id*="twitter-widget-"] { .hentry .fb_iframe_widget, .hentry .googlemaps, .hentry .PDS_Poll, + .hentry .CSS_Poll, .site .hentry .presentation-wrapper, .site .hentry .jetpack-recipe, .site .hentry .slideshow-window, @@ -574,6 +579,7 @@ iframe[id*="twitter-widget-"] { .hentry .fb_iframe_widget, .hentry .googlemaps, .hentry .PDS_Poll, + .hentry .CSS_Poll, .site .hentry .presentation-wrapper, .site .hentry .jetpack-recipe, .site .hentry .slideshow-window, @@ -647,6 +653,7 @@ iframe[id*="twitter-widget-"] { .hentry .fb_iframe_widget, .hentry .googlemaps, .hentry .PDS_Poll, + .hentry .CSS_Poll, .site .hentry .presentation-wrapper, .site .hentry .jetpack-recipe, .site .hentry .slideshow-window, @@ -716,6 +723,7 @@ iframe[id*="twitter-widget-"] { .hentry .fb_iframe_widget, .hentry .googlemaps, .hentry .PDS_Poll, + .hentry .CSS_Poll, .site .hentry .presentation-wrapper, .site .hentry .jetpack-recipe, .site .hentry .slideshow-window, diff --git a/plugins/jetpack/modules/theme-tools/compat/twentyfourteen-rtl.css b/plugins/jetpack/modules/theme-tools/compat/twentyfourteen-rtl.css index e69fb00f..66e74dbd 100644 --- a/plugins/jetpack/modules/theme-tools/compat/twentyfourteen-rtl.css +++ b/plugins/jetpack/modules/theme-tools/compat/twentyfourteen-rtl.css @@ -27,19 +27,22 @@ div.jp-relatedposts .jp-relatedposts-headline em:after { #page .entry-content h3.sd-title, #page .entry-summary h3.sd-title, #primary div.sharedaddy .jp-relatedposts-headline em, -.pd-rating { +.pd-rating, +.cs-rating { color: #767676; font-size: 11px; text-transform: uppercase; } -.pd-rating { +.pd-rating, +.cs-rating { min-height: 23px; margin-bottom: 5px; } .wp-multiplayer, .PDS_Poll, +.CSS_Poll, .entry-content .slideshow-window { margin-bottom: 24px; } diff --git a/plugins/jetpack/modules/theme-tools/compat/twentyfourteen.css b/plugins/jetpack/modules/theme-tools/compat/twentyfourteen.css index 1de2b931..903bc3de 100644 --- a/plugins/jetpack/modules/theme-tools/compat/twentyfourteen.css +++ b/plugins/jetpack/modules/theme-tools/compat/twentyfourteen.css @@ -23,19 +23,22 @@ #page .entry-content h3.sd-title, #page .entry-summary h3.sd-title, #primary div.sharedaddy .jp-relatedposts-headline em, -.pd-rating { +.pd-rating, +.cs-rating { color: #767676; font-size: 11px; text-transform: uppercase; } -.pd-rating { +.pd-rating, +.cs-rating { min-height: 23px; margin-bottom: 5px; } .wp-multiplayer, .PDS_Poll, +.CSS_Poll, .entry-content .slideshow-window { margin-bottom: 24px; } diff --git a/plugins/jetpack/modules/theme-tools/compat/twentyfourteen.php b/plugins/jetpack/modules/theme-tools/compat/twentyfourteen.php index 7c3859a1..202dfbf3 100644 --- a/plugins/jetpack/modules/theme-tools/compat/twentyfourteen.php +++ b/plugins/jetpack/modules/theme-tools/compat/twentyfourteen.php @@ -43,7 +43,7 @@ add_action( 'featured_content_default_settings', 'twentyfourteen_featured_conten * Removes sharing markup from post content if we're not in the loop and it's a * formatted post. * - * @param bool $show Whether to show sharing options. + * @param bool $show Whether to show sharing options. * @param WP_Post $post The post to share. * @return bool */ diff --git a/plugins/jetpack/modules/theme-tools/compat/twentynineteen.css b/plugins/jetpack/modules/theme-tools/compat/twentynineteen.css new file mode 100644 index 00000000..2bd0512c --- /dev/null +++ b/plugins/jetpack/modules/theme-tools/compat/twentynineteen.css @@ -0,0 +1,321 @@ +/* Infinite scroll */ + +/* Globally hidden elements when Infinite Scroll is supported and in use. */ +.infinite-scroll .pagination, +.infinite-scroll .posts-navigation, +.infinite-scroll.neverending .site-footer { + /* Theme Footer (when set to scrolling) */ + display: none; +} + + /* When Infinite Scroll has reached its end we need to re-display elements that were hidden (via .neverending) before. */ +.infinity-end.neverending .site-footer { + display: block; +} + +.infinite-loader { + margin: calc(3 * 1rem) auto; +} + +.infinite-loader .spinner { + margin: 0 auto; + left: inherit !important; +} + +.site-main #infinite-handle { + margin: calc(2 * 1rem) auto; +} + +.site-main #infinite-handle span { + background: transparent; + display: block; + font-size: 0.8888888889em; + text-align: center; +} + +.site-main #infinite-handle span button, +.site-main #infinite-handle span button:hover, +.site-main #infinite-handle span button:focus { + transition: background 150ms ease-in-out; + background: #0073aa; + border: none; + border-radius: 5px; + box-sizing: border-box; + color: white; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; + font-size: 0.8888888889em; + font-weight: 600; + line-height: 1.2; + outline: none; + padding: 0.66rem 1rem; +} + +.site-main #infinite-handle span button:hover { + cursor: pointer; +} + +.site-main #infinite-handle span button:hover, +.site-main #infinite-handle span button:focus { + background: #111; +} + +.site-main #infinite-handle span button:focus { + outline: thin dotted; + outline-offset: -4px; +} + +/** + * Responsive Videos + */ +.entry .jetpack-video-wrapper { + margin-bottom: 1.75em; +} + +/** + * Sharing + */ + +.sd-block { + line-height: 1; +} + +.entry div.sharedaddy h3.sd-title, +.entry h3.sd-title { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; + font-size: 1.125em; + font-weight: 700; + letter-spacing: -0.02em; + line-height: 1.2; + margin-bottom: 0.5em; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +.entry div.sharedaddy h3.sd-title:before, +.entry h3.sd-title:before { + background: #767676; + border-top: none; + content: "\020"; + display: block; + height: 2px; + margin: 1rem 0; + width: 1em; + min-width: inherit; +} + +.sd-social-icon-text .sd-content ul, +.sd-social-text .sd-content ul { + margin-bottom: -0.3125em !important; +} + +.sd-social-icon .sd-content ul { + margin-bottom: 0 !important; +} + +.sd-social-official .sd-content ul { + margin-bottom: -0.625em !important; +} + +.entry #sharing_email .sharing_send, +.entry .sd-content ul li .option a.share-ustom, +.entry .sd-content ul li a.sd-button, +.entry .sd-content ul li.advanced a.share-more, +.entry .sd-content ul li.preview-item div.option.option-smart-off a, +.entry .sd-social-icon .sd-content ul li a.sd-button, +.entry .sd-social-icon-text .sd-content ul li a.sd-button, +.entry .sd-social-official .sd-content > ul > li .digg_button > a, +.entry .sd-social-official .sd-content > ul > li > a.sd-button, +.entry .sd-social-text .sd-content ul li a.sd-button { + box-shadow: none; +} + + +/** + * Related Posts + */ + +.entry #jp-relatedposts { + padding-top: 0; + margin-top: 32px; + margin-bottom: 32px; +} + +.entry #jp-relatedposts h3.jp-relatedposts-headline { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; + font-size: 1.125em; + font-weight: 700; + letter-spacing: -0.02em; + line-height: 1.2; + margin-bottom: 0.5em; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +.entry #jp-relatedposts h3.jp-relatedposts-headline:before { + background: #767676; + border-top: none; + content: "\020"; + display: block; + height: 2px; + margin: 1rem 0; + width: 1em; + min-width: inherit; +} + +.entry #jp-relatedposts h3.jp-relatedposts-headline em:before { + display: none; +} + +.entry #jp-relatedposts .jp-relatedposts-items-visual .jp-relatedposts-post { + opacity: 1; +} + +.entry #jp-relatedposts .jp-relatedposts-items-visual h4.jp-relatedposts-post-title, +.entry #jp-relatedposts .jp-relatedposts-items .jp-relatedposts-post { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; + font-size: 1em; + letter-spacing: -0.02em; + line-height: 1.2; + margin-bottom: 0.5em; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +.entry #jp-relatedposts .jp-relatedposts-items-visual h4.jp-relatedposts-post-title a, +.entry #jp-relatedposts .jp-relatedposts-items .jp-relatedposts-post span a { + font-weight: 700; +} + +.entry #jp-relatedposts .jp-relatedposts-items .jp-relatedposts-post .jp-relatedposts-post-title, +.entry #jp-relatedposts .jp-relatedposts-items .jp-relatedposts-post .jp-relatedposts-post-excerpt { + margin-top: 0.5em; + margin-bottom: 0.5em; +} + +.entry #jp-relatedposts .jp-relatedposts-items .jp-relatedposts-post .jp-relatedposts-post-context, +.entry #jp-relatedposts .jp-relatedposts-items .jp-relatedposts-post .jp-relatedposts-post-date { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; + font-size: 13px; + font-weight: 500; +} + +.entry #jp-relatedposts .jp-relatedposts-items p, +.entry #jp-relatedposts .jp-relatedposts-items-visual +.entry h4.jp-relatedposts-post-title { + letter-spacing: normal; +} + + +/** + * Stats + */ + +#wpstats { + display: none; +} + + +/** + * Comments + */ + +.comments-area .comments-title-wrap + .comment-respond .comment-reply-title { + display: none; +} + + +/** + * Widgets + */ + +/* Authors Widget */ +.widget.widget_authors ul li > ul { + list-style-type: disc; + padding-left: 4.25rem; +} + +.rtl .widget.widget_authors ul li > ul { + padding-left: 0; + padding-right: 1rem; +} + +.widget_authors > ul > li > a { + display: block; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; + position: relative; +} + +.widget.widget_authors li a strong { + line-height: 1.2; + position: absolute; + top: 0; +} + +.widget.widget_authors .avatar { + float: left; + margin-right: 1em; +} + +.widget_authors li > ul { + clear: both; +} + +/* Display WordPress Posts */ +.widget_jetpack_display_posts_widget .jetpack-display-remote-posts h4 { + font-size: 100%; + margin: 1rem 0; +} + +/* GoodReads */ +.widget_goodreads div[class^="gr_custom_container"] { + border: none; +} + +.widget_goodreads div[class^="gr_custom_each_container"] { + border-bottom: none; + margin-bottom: 1rem; + padding-bottom: 0; +} + +.widget_goodreads h2[class^="gr_custom_header"], +.widget_goodreads div[class^="gr_custom_author"] { + font-size: inherit; + line-height: 1.15; +} + +/* EU cookie law */ +.widget_eu_cookie_law_widget #eu-cookie-law { + border-color: #ccc; + color: #767676; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; + font-size: 0.68182em; + padding: 0.5rem 1rem; +} + +.widget_eu_cookie_law_widget #eu-cookie-law .accept { + font-size: 1em; + padding: 10px 12px; +} + +/* RSS Links */ +.widget_rss_links ul { + list-style: none; + padding-left: 0; + padding-right: 0; +} + +.widget_rss_links li { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; + font-size: calc(22px * 1.125); + font-weight: bold; + line-height: 1.2; + padding-bottom: 0.75rem; +} + +/** + * Content Options + */ +.twentynineteen-customizer .entry .entry-meta > span, +.twentynineteen-customizer .entry .entry-footer > span { + display: inline; +} diff --git a/plugins/jetpack/modules/theme-tools/compat/twentynineteen.php b/plugins/jetpack/modules/theme-tools/compat/twentynineteen.php new file mode 100644 index 00000000..b9c50e7b --- /dev/null +++ b/plugins/jetpack/modules/theme-tools/compat/twentynineteen.php @@ -0,0 +1,126 @@ +<?php +/** + * Jetpack Compatibility File + * See: http://jetpack.com/ + */ + +function twentynineteen_jetpack_setup() { + + /** + * Add theme support for Infinite Scroll. + */ + add_theme_support( 'infinite-scroll', array( + 'type' => 'click', + 'container' => 'main', + 'render' => 'twentynineteen_infinite_scroll_render', + 'footer' => 'page', + ) ); + + /** + * Add theme support for Responsive Videos. + */ + add_theme_support( 'jetpack-responsive-videos' ); + + /** + * Add theme support for geo-location. + */ + add_theme_support( 'jetpack-geo-location' ); + + /** + * Add theme support for Content Options. + */ + add_theme_support( 'jetpack-content-options', array( + 'blog-display' => 'content', // the default setting of the theme: 'content', 'excerpt' or array( 'content', 'excerpt' ) for themes mixing both display. + 'post-details' => array( + 'stylesheet' => 'twentynineteen-style', + 'date' => '.posted-on', + 'categories' => '.cat-links', + 'tags' => '.tags-links', + 'author' => '.byline', + 'comment' => '.comments-link', + ), + 'featured-images' => array( + 'archive' => true, + 'post' => true, + 'page' => true, + ), + ) ); +} +add_action( 'after_setup_theme', 'twentynineteen_jetpack_setup' ); + +/** + * Custom render function for Infinite Scroll. + */ +function twentynineteen_infinite_scroll_render() { + while ( have_posts() ) { + the_post(); + get_template_part( 'template-parts/content/content' ); + } +} + +function twentynineteen_init_jetpack() { + /** + * Add our compat CSS file for Infinite Scroll and custom widget stylings and such. + * Set the version equal to filemtime for development builds, and the JETPACK__VERSION for production + * or skip it entirely for wpcom. + */ + if ( ! is_admin() ) { + $version = false; + if ( method_exists( 'Jetpack', 'is_development_version' ) ) { + $version = Jetpack::is_development_version() ? filemtime( plugin_dir_path( __FILE__ ) . 'twentynineteen.css' ) : JETPACK__VERSION; + } + wp_enqueue_style( 'twentynineteen-jetpack', plugins_url( 'twentynineteen.css', __FILE__ ), array(), $version ); + wp_style_add_data( 'twentynineteen-jetpack', 'rtl', 'replace' ); + } +} +add_action( 'init', 'twentynineteen_init_jetpack' ); + +/** + * Alter gallery widget default width. + */ +function twentynineteen_gallery_widget_content_width( $width ) { + return 390; +} +add_filter( 'gallery_widget_content_width', 'twentynineteen_gallery_widget_content_width' ); + +/** + * Alter featured-image default visibility for content-options. + */ +function twentynineteen_override_post_thumbnail( $width ) { + $options = get_theme_support( 'jetpack-content-options' ); + $featured_images = ( ! empty( $options[0]['featured-images'] ) ) ? $options[0]['featured-images'] : null; + + $settings = array( + 'post-default' => ( isset( $featured_images['post-default'] ) && false === $featured_images['post-default'] ) ? '' : 1, + 'page-default' => ( isset( $featured_images['page-default'] ) && false === $featured_images['page-default'] ) ? '' : 1, + ); + + $settings = array_merge( $settings, array( + 'post-option' => get_option( 'jetpack_content_featured_images_post', $settings['post-default'] ), + 'page-option' => get_option( 'jetpack_content_featured_images_page', $settings['page-default'] ), + ) ); + + if ( ( ! $settings['post-option'] && is_single() ) + || ( ! $settings['page-option'] && is_singular() && is_page() ) ) { + return false; + } else { + return ! post_password_required() && ! is_attachment() && has_post_thumbnail(); + } +} +add_filter( 'twentynineteen_can_show_post_thumbnail', 'twentynineteen_override_post_thumbnail', 10, 2 ); + +/** + * Adds custom classes to the array of body classes. + * + * @param array $classes Classes for the body element. + * @return array + */ +function twentynineteen_jetpack_body_classes( $classes ) { + // Adds a class if we're in the Customizer + if ( is_customize_preview() ) : + $classes[] = 'twentynineteen-customizer'; + endif; + + return $classes; +} +add_filter( 'body_class', 'twentynineteen_jetpack_body_classes' ); diff --git a/plugins/jetpack/modules/theme-tools/compat/twentysixteen-rtl.css b/plugins/jetpack/modules/theme-tools/compat/twentysixteen-rtl.css index a616269d..d60c31a4 100644 --- a/plugins/jetpack/modules/theme-tools/compat/twentysixteen-rtl.css +++ b/plugins/jetpack/modules/theme-tools/compat/twentysixteen-rtl.css @@ -342,13 +342,15 @@ iframe[src^="http://api.mixcloud.com/"] { max-width: calc(100% + 8px); } -/* Polldaddy */ -.PDS_Poll { +/* Crowdsignal */ +.PDS_Poll, +.CSS_Poll { display: block !important; margin-bottom: 1.75em; } -.PDS_Poll .pds-box { +.PDS_Poll .pds-box, +.CSS_Poll .css-box { max-width: 100%; width: auto; } diff --git a/plugins/jetpack/modules/theme-tools/compat/twentysixteen.css b/plugins/jetpack/modules/theme-tools/compat/twentysixteen.css index 672b264e..acc056cf 100644 --- a/plugins/jetpack/modules/theme-tools/compat/twentysixteen.css +++ b/plugins/jetpack/modules/theme-tools/compat/twentysixteen.css @@ -341,13 +341,15 @@ iframe[src^="http://api.mixcloud.com/"] { max-width: calc(100% + 8px); } -/* Polldaddy */ -.PDS_Poll { +/* Crowdsignal */ +.PDS_Poll, +.CSS_Poll { display: block !important; margin-bottom: 1.75em; } -.PDS_Poll .pds-box { +.PDS_Poll .pds-box, +.CSS_Poll .css-box { max-width: 100%; width: auto; } diff --git a/plugins/jetpack/modules/theme-tools/compat/twentysixteen.php b/plugins/jetpack/modules/theme-tools/compat/twentysixteen.php index 20fd7f5d..e13df99d 100644 --- a/plugins/jetpack/modules/theme-tools/compat/twentysixteen.php +++ b/plugins/jetpack/modules/theme-tools/compat/twentysixteen.php @@ -47,10 +47,10 @@ add_filter( 'gallery_widget_content_width', 'twentysixteen_gallery_widget_conten */ function twentysixteen_remove_share() { if ( is_single() || is_archive() || is_home() ) { - remove_filter( 'the_excerpt', 'sharing_display', 19 ); - if ( class_exists( 'Jetpack_Likes' ) ) { - remove_filter( 'the_excerpt', array( Jetpack_Likes::init(), 'post_likes' ), 30, 1 ); - } + remove_filter( 'the_excerpt', 'sharing_display', 19 ); + if ( class_exists( 'Jetpack_Likes' ) ) { + remove_filter( 'the_excerpt', array( Jetpack_Likes::init(), 'post_likes' ), 30, 1 ); + } } } add_action( 'loop_start', 'twentysixteen_remove_share' ); diff --git a/plugins/jetpack/modules/theme-tools/content-options.php b/plugins/jetpack/modules/theme-tools/content-options.php index fb858718..118e31db 100644 --- a/plugins/jetpack/modules/theme-tools/content-options.php +++ b/plugins/jetpack/modules/theme-tools/content-options.php @@ -32,7 +32,6 @@ 'fallback-default' => true, // the default setting for featured image fallbacks: true or false (only required if false) ), ) ); - * */ /** @@ -47,35 +46,35 @@ function jetpack_content_options_init() { } // Load the Customizer options. - require( dirname( __FILE__ ) . '/content-options/customizer.php' ); + require dirname( __FILE__ ) . '/content-options/customizer.php'; // Load Blog Display function. - require( dirname( __FILE__ ) . '/content-options/blog-display.php' ); + require dirname( __FILE__ ) . '/content-options/blog-display.php'; // Load Author Bio function. - require( dirname( __FILE__ ) . '/content-options/author-bio.php' ); + require dirname( __FILE__ ) . '/content-options/author-bio.php'; // Load Post Details function. - require( dirname( __FILE__ ) . '/content-options/post-details.php' ); + require dirname( __FILE__ ) . '/content-options/post-details.php'; // Load Featured Images function. if ( jetpack_featured_images_should_load() ) { - require( dirname( __FILE__ ) . '/content-options/featured-images.php' ); + require dirname( __FILE__ ) . '/content-options/featured-images.php'; } // Load Featured Images Fallback function. if ( jetpack_featured_images_fallback_should_load() ) { - require( dirname( __FILE__ ) . '/content-options/featured-images-fallback.php' ); + require dirname( __FILE__ ) . '/content-options/featured-images-fallback.php'; } } add_action( 'init', 'jetpack_content_options_init' ); function jetpack_featured_images_get_settings() { - $options = get_theme_support( 'jetpack-content-options' ); + $options = get_theme_support( 'jetpack-content-options' ); $featured_images = ( ! empty( $options[0]['featured-images'] ) ) ? $options[0]['featured-images'] : null; - $settings = array( + $settings = array( 'archive' => ( ! empty( $featured_images['archive'] ) ) ? $featured_images['archive'] : null, 'post' => ( ! empty( $featured_images['post'] ) ) ? $featured_images['post'] : null, 'page' => ( ! empty( $featured_images['page'] ) ) ? $featured_images['page'] : null, @@ -88,13 +87,16 @@ function jetpack_featured_images_get_settings() { 'fallback-default' => ( isset( $featured_images['fallback-default'] ) && false === $featured_images['fallback-default'] ) ? '' : 1, ); - $settings = array_merge( $settings, array( - 'archive-option' => get_option( 'jetpack_content_featured_images_archive', $settings['archive-default'] ), - 'post-option' => get_option( 'jetpack_content_featured_images_post', $settings['post-default'] ), - 'page-option' => get_option( 'jetpack_content_featured_images_page', $settings['page-default'] ), - 'portfolio-option' => get_option( 'jetpack_content_featured_images_portfolio', $settings['portfolio-default'] ), - 'fallback-option' => get_option( 'jetpack_content_featured_images_fallback', $settings['fallback-default'] ), - ) ); + $settings = array_merge( + $settings, + array( + 'archive-option' => get_option( 'jetpack_content_featured_images_archive', $settings['archive-default'] ), + 'post-option' => get_option( 'jetpack_content_featured_images_post', $settings['post-default'] ), + 'page-option' => get_option( 'jetpack_content_featured_images_page', $settings['page-default'] ), + 'portfolio-option' => get_option( 'jetpack_content_featured_images_portfolio', $settings['portfolio-default'] ), + 'fallback-option' => get_option( 'jetpack_content_featured_images_fallback', $settings['fallback-default'] ), + ) + ); return $settings; } diff --git a/plugins/jetpack/modules/theme-tools/content-options/author-bio.php b/plugins/jetpack/modules/theme-tools/content-options/author-bio.php index 3e2c1c8e..89d4603c 100644 --- a/plugins/jetpack/modules/theme-tools/content-options/author-bio.php +++ b/plugins/jetpack/modules/theme-tools/content-options/author-bio.php @@ -26,7 +26,7 @@ function jetpack_author_bio() { if ( ! is_single() ) { return; } -?> + ?> <div class="entry-author"> <div class="author-avatar"> <?php @@ -56,5 +56,5 @@ function jetpack_author_bio() { </a> </p><!-- .author-bio --> </div><!-- .entry-auhtor --> -<?php + <?php } diff --git a/plugins/jetpack/modules/theme-tools/content-options/blog-display.php b/plugins/jetpack/modules/theme-tools/content-options/blog-display.php index 89665396..a3f74d0b 100644 --- a/plugins/jetpack/modules/theme-tools/content-options/blog-display.php +++ b/plugins/jetpack/modules/theme-tools/content-options/blog-display.php @@ -51,10 +51,10 @@ function jetpack_blog_display_custom_excerpt( $content ) { $text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' ); preg_match_all( '/./u', $text, $words ); $words = array_slice( $words[0], 0, $excerpt_length + 1 ); - $sep = ''; + $sep = ''; } else { $words = preg_split( "/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY ); - $sep = ' '; + $sep = ' '; } if ( count( $words ) > $excerpt_length ) { @@ -90,18 +90,20 @@ function jetpack_the_content_to_the_excerpt( $content ) { function jetpack_the_excerpt_to_the_content( $content ) { if ( ( is_home() || is_archive() ) && ! is_post_type_archive( array( 'jetpack-testimonial', 'jetpack-portfolio', 'product' ) ) ) { ob_start(); - the_content( sprintf( - wp_kses( - /* translators: %s: Name of current post. Only visible to screen readers */ - __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'jetpack' ), - array( - 'span' => array( - 'class' => array(), - ), - ) - ), - get_the_title() - ) ); + the_content( + sprintf( + wp_kses( + /* translators: %s: Name of current post. Only visible to screen readers */ + __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'jetpack' ), + array( + 'span' => array( + 'class' => array(), + ), + ) + ), + get_the_title() + ) + ); $content = ob_get_clean(); } return $content; @@ -132,18 +134,20 @@ function jetpack_the_content_customizer( $content ) { function jetpack_the_excerpt_customizer( $excerpt ) { if ( ( is_home() || is_archive() ) && ! is_post_type_archive( array( 'jetpack-testimonial', 'jetpack-portfolio', 'product' ) ) ) { ob_start(); - the_content( sprintf( - wp_kses( - /* translators: %s: Name of current post. Only visible to screen readers */ - __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'jetpack' ), - array( - 'span' => array( - 'class' => array(), - ), - ) - ), - get_the_title() - ) ); + the_content( + sprintf( + wp_kses( + /* translators: %s: Name of current post. Only visible to screen readers */ + __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'jetpack' ), + array( + 'span' => array( + 'class' => array(), + ), + ) + ), + get_the_title() + ) + ); $content = ob_get_clean(); } if ( empty( $content ) ) { @@ -175,10 +179,10 @@ function jetpack_the_content_customizer_class( $new_class = null ) { if ( isset( $new_class ) ) { // Assign a new class and return. $class = $new_class; - } else if ( isset( $class ) ) { + } elseif ( isset( $class ) ) { // Reset the class after getting value. $prev_class = $class; - $class = null; + $class = null; return $prev_class; } else { // Return default class value. diff --git a/plugins/jetpack/modules/theme-tools/content-options/customizer.php b/plugins/jetpack/modules/theme-tools/content-options/customizer.php index 0fea7ae7..844e5074 100644 --- a/plugins/jetpack/modules/theme-tools/content-options/customizer.php +++ b/plugins/jetpack/modules/theme-tools/content-options/customizer.php @@ -5,9 +5,9 @@ * @param WP_Customize_Manager $wp_customize Theme Customizer object. */ function jetpack_content_options_customize_register( $wp_customize ) { - $options = get_theme_support( 'jetpack-content-options' ); - $blog_display = ( ! empty( $options[0]['blog-display'] ) ) ? $options[0]['blog-display'] : null; - $blog_display = preg_grep( '/^(content|excerpt)$/', (array) $blog_display ); + $options = get_theme_support( 'jetpack-content-options' ); + $blog_display = ( ! empty( $options[0]['blog-display'] ) ) ? $options[0]['blog-display'] : null; + $blog_display = preg_grep( '/^(content|excerpt)$/', (array) $blog_display ); sort( $blog_display ); $blog_display = implode( ', ', $blog_display ); $blog_display = ( 'content, excerpt' === $blog_display ) ? 'mixed' : $blog_display; @@ -33,15 +33,15 @@ function jetpack_content_options_customize_register( $wp_customize ) { // If the theme doesn't support 'jetpack-content-options[ 'blog-display' ]', 'jetpack-content-options[ 'author-bio' ]', 'jetpack-content-options[ 'post-details' ]' and 'jetpack-content-options[ 'featured-images' ]', don't continue. if ( ( ! in_array( $blog_display, array( 'content', 'excerpt', 'mixed' ) ) ) - && ( true !== $author_bio ) - && ( ( empty( $post_details['stylesheet'] ) ) + && ( true !== $author_bio ) + && ( ( empty( $post_details['stylesheet'] ) ) && ( empty( $date ) || empty( $categories ) || empty( $tags ) || empty( $author ) || empty( $comment ) ) ) && ( true !== $fi_archive && true !== $fi_post && true !== $fi_page && true !== $fi_portfolio && true !== $fi_fallback ) ) { - return; + return; } // New control type: Title. @@ -49,18 +49,21 @@ function jetpack_content_options_customize_register( $wp_customize ) { public $type = 'title'; public function render_content() { - ?> + ?> <span class="customize-control-title"><?php echo wp_kses_post( $this->label ); ?></span> - <?php + <?php } } // Add Content section. - $wp_customize->add_section( 'jetpack_content_options', array( - 'title' => esc_html__( 'Content Options', 'jetpack' ), - 'theme_supports' => 'jetpack-content-options', - 'priority' => 100, - ) ); + $wp_customize->add_section( + 'jetpack_content_options', + array( + 'title' => esc_html__( 'Content Options', 'jetpack' ), + 'theme_supports' => 'jetpack-content-options', + 'priority' => 100, + ) + ); // Add Blog Display option. if ( in_array( $blog_display, array( 'content', 'excerpt', 'mixed' ) ) ) { @@ -85,43 +88,61 @@ function jetpack_content_options_customize_register( $wp_customize ) { } } - $wp_customize->add_setting( 'jetpack_content_blog_display', array( - 'default' => $blog_display, - 'type' => 'option', - 'transport' => 'postMessage', - 'sanitize_callback' => 'jetpack_content_options_sanitize_blog_display', - ) ); - - $wp_customize->add_control( 'jetpack_content_blog_display', array( - 'section' => 'jetpack_content_options', - 'label' => esc_html__( 'Blog Display', 'jetpack' ), - 'description' => $blog_display_description, - 'type' => 'radio', - 'choices' => $blog_display_choices, - ) ); + $wp_customize->add_setting( + 'jetpack_content_blog_display', + array( + 'default' => $blog_display, + 'type' => 'option', + 'transport' => 'postMessage', + 'sanitize_callback' => 'jetpack_content_options_sanitize_blog_display', + ) + ); + + $wp_customize->add_control( + 'jetpack_content_blog_display', + array( + 'section' => 'jetpack_content_options', + 'label' => esc_html__( 'Blog Display', 'jetpack' ), + 'description' => $blog_display_description, + 'type' => 'radio', + 'choices' => $blog_display_choices, + ) + ); } // Add Author Bio option. if ( true === $author_bio ) { $wp_customize->add_setting( 'jetpack_content_author_bio_title' ); - $wp_customize->add_control( new Jetpack_Customize_Control_Title( $wp_customize, 'jetpack_content_author_bio_title', array( - 'section' => 'jetpack_content_options', - 'label' => esc_html__( 'Author Bio', 'jetpack' ), - 'type' => 'title', - ) ) ); - - $wp_customize->add_setting( 'jetpack_content_author_bio', array( - 'default' => $author_bio_default, - 'type' => 'option', - 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', - ) ); - - $wp_customize->add_control( 'jetpack_content_author_bio', array( - 'section' => 'jetpack_content_options', - 'label' => esc_html__( 'Display on single posts', 'jetpack' ), - 'type' => 'checkbox', - ) ); + $wp_customize->add_control( + new Jetpack_Customize_Control_Title( + $wp_customize, + 'jetpack_content_author_bio_title', + array( + 'section' => 'jetpack_content_options', + 'label' => esc_html__( 'Author Bio', 'jetpack' ), + 'type' => 'title', + ) + ) + ); + + $wp_customize->add_setting( + 'jetpack_content_author_bio', + array( + 'default' => $author_bio_default, + 'type' => 'option', + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', + ) + ); + + $wp_customize->add_control( + 'jetpack_content_author_bio', + array( + 'section' => 'jetpack_content_options', + 'label' => esc_html__( 'Display on single posts', 'jetpack' ), + 'type' => 'checkbox', + ) + ); } // Add Post Details options. @@ -134,90 +155,126 @@ function jetpack_content_options_customize_register( $wp_customize ) { || ! empty( $comment ) ) ) { $wp_customize->add_setting( 'jetpack_content_post_details_title' ); - $wp_customize->add_control( new Jetpack_Customize_Control_Title( $wp_customize, 'jetpack_content_post_details_title', array( - 'section' => 'jetpack_content_options', - 'label' => esc_html__( 'Post Details', 'jetpack' ), - 'type' => 'title', - ) ) ); + $wp_customize->add_control( + new Jetpack_Customize_Control_Title( + $wp_customize, + 'jetpack_content_post_details_title', + array( + 'section' => 'jetpack_content_options', + 'label' => esc_html__( 'Post Details', 'jetpack' ), + 'type' => 'title', + ) + ) + ); // Post Details: Date if ( ! empty( $date ) ) { - $wp_customize->add_setting( 'jetpack_content_post_details_date', array( - 'default' => 1, - 'type' => 'option', - 'transport' => 'postMessage', - 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', - ) ); - - $wp_customize->add_control( 'jetpack_content_post_details_date', array( - 'section' => 'jetpack_content_options', - 'label' => esc_html__( 'Display date', 'jetpack' ), - 'type' => 'checkbox', - ) ); + $wp_customize->add_setting( + 'jetpack_content_post_details_date', + array( + 'default' => 1, + 'type' => 'option', + 'transport' => 'postMessage', + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', + ) + ); + + $wp_customize->add_control( + 'jetpack_content_post_details_date', + array( + 'section' => 'jetpack_content_options', + 'label' => esc_html__( 'Display date', 'jetpack' ), + 'type' => 'checkbox', + ) + ); } // Post Details: Categories if ( ! empty( $categories ) ) { - $wp_customize->add_setting( 'jetpack_content_post_details_categories', array( - 'default' => 1, - 'type' => 'option', - 'transport' => 'postMessage', - 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', - ) ); - - $wp_customize->add_control( 'jetpack_content_post_details_categories', array( - 'section' => 'jetpack_content_options', - 'label' => esc_html__( 'Display categories', 'jetpack' ), - 'type' => 'checkbox', - ) ); + $wp_customize->add_setting( + 'jetpack_content_post_details_categories', + array( + 'default' => 1, + 'type' => 'option', + 'transport' => 'postMessage', + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', + ) + ); + + $wp_customize->add_control( + 'jetpack_content_post_details_categories', + array( + 'section' => 'jetpack_content_options', + 'label' => esc_html__( 'Display categories', 'jetpack' ), + 'type' => 'checkbox', + ) + ); } // Post Details: Tags if ( ! empty( $tags ) ) { - $wp_customize->add_setting( 'jetpack_content_post_details_tags', array( - 'default' => 1, - 'type' => 'option', - 'transport' => 'postMessage', - 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', - ) ); - - $wp_customize->add_control( 'jetpack_content_post_details_tags', array( - 'section' => 'jetpack_content_options', - 'label' => esc_html__( 'Display tags', 'jetpack' ), - 'type' => 'checkbox', - ) ); + $wp_customize->add_setting( + 'jetpack_content_post_details_tags', + array( + 'default' => 1, + 'type' => 'option', + 'transport' => 'postMessage', + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', + ) + ); + + $wp_customize->add_control( + 'jetpack_content_post_details_tags', + array( + 'section' => 'jetpack_content_options', + 'label' => esc_html__( 'Display tags', 'jetpack' ), + 'type' => 'checkbox', + ) + ); } // Post Details: Author if ( ! empty( $author ) ) { - $wp_customize->add_setting( 'jetpack_content_post_details_author', array( - 'default' => 1, - 'type' => 'option', - 'transport' => 'postMessage', - 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', - ) ); - - $wp_customize->add_control( 'jetpack_content_post_details_author', array( - 'section' => 'jetpack_content_options', - 'label' => esc_html__( 'Display author', 'jetpack' ), - 'type' => 'checkbox', - ) ); + $wp_customize->add_setting( + 'jetpack_content_post_details_author', + array( + 'default' => 1, + 'type' => 'option', + 'transport' => 'postMessage', + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', + ) + ); + + $wp_customize->add_control( + 'jetpack_content_post_details_author', + array( + 'section' => 'jetpack_content_options', + 'label' => esc_html__( 'Display author', 'jetpack' ), + 'type' => 'checkbox', + ) + ); } // Post Details: Comment link if ( ! empty( $comment ) ) { - $wp_customize->add_setting( 'jetpack_content_post_details_comment', array( - 'default' => 1, - 'type' => 'option', - 'transport' => 'postMessage', - 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', - ) ); - - $wp_customize->add_control( 'jetpack_content_post_details_comment', array( - 'section' => 'jetpack_content_options', - 'label' => esc_html__( 'Display comment link', 'jetpack' ), - 'type' => 'checkbox', - ) ); + $wp_customize->add_setting( + 'jetpack_content_post_details_comment', + array( + 'default' => 1, + 'type' => 'option', + 'transport' => 'postMessage', + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', + ) + ); + + $wp_customize->add_control( + 'jetpack_content_post_details_comment', + array( + 'section' => 'jetpack_content_options', + 'label' => esc_html__( 'Display comment link', 'jetpack' ), + 'type' => 'checkbox', + ) + ); } } @@ -225,91 +282,127 @@ function jetpack_content_options_customize_register( $wp_customize ) { if ( true === $fi_archive || true === $fi_post || true === $fi_page || true === $fi_portfolio || true === $fi_fallback ) { $wp_customize->add_setting( 'jetpack_content_featured_images_title' ); - $wp_customize->add_control( new Jetpack_Customize_Control_Title( $wp_customize, 'jetpack_content_featured_images_title', array( - 'section' => 'jetpack_content_options', - 'label' => esc_html__( 'Featured Images', 'jetpack' ) . sprintf( '<a href="https://en.support.wordpress.com/featured-images/" class="customize-help-toggle dashicons dashicons-editor-help" title="%1$s" rel="noopener noreferrer" target="_blank"><span class="screen-reader-text">%1$s</span></a>', esc_html__( 'Learn more about Featured Images', 'jetpack' ) ), - 'type' => 'title', - 'active_callback' => 'jetpack_post_thumbnail_supports', - ) ) ); + $wp_customize->add_control( + new Jetpack_Customize_Control_Title( + $wp_customize, + 'jetpack_content_featured_images_title', + array( + 'section' => 'jetpack_content_options', + 'label' => esc_html__( 'Featured Images', 'jetpack' ) . sprintf( '<a href="https://en.support.wordpress.com/featured-images/" class="customize-help-toggle dashicons dashicons-editor-help" title="%1$s" rel="noopener noreferrer" target="_blank"><span class="screen-reader-text">%1$s</span></a>', esc_html__( 'Learn more about Featured Images', 'jetpack' ) ), + 'type' => 'title', + 'active_callback' => 'jetpack_post_thumbnail_supports', + ) + ) + ); // Featured Images: Archive if ( true === $fi_archive ) { - $wp_customize->add_setting( 'jetpack_content_featured_images_archive', array( - 'default' => $fi_archive_default, - 'type' => 'option', - 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', - ) ); - - $wp_customize->add_control( 'jetpack_content_featured_images_archive', array( - 'section' => 'jetpack_content_options', - 'label' => esc_html__( 'Display on blog and archives', 'jetpack' ), - 'type' => 'checkbox', - 'active_callback' => 'jetpack_post_thumbnail_supports', - ) ); + $wp_customize->add_setting( + 'jetpack_content_featured_images_archive', + array( + 'default' => $fi_archive_default, + 'type' => 'option', + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', + ) + ); + + $wp_customize->add_control( + 'jetpack_content_featured_images_archive', + array( + 'section' => 'jetpack_content_options', + 'label' => esc_html__( 'Display on blog and archives', 'jetpack' ), + 'type' => 'checkbox', + 'active_callback' => 'jetpack_post_thumbnail_supports', + ) + ); } // Featured Images: Post if ( true === $fi_post ) { - $wp_customize->add_setting( 'jetpack_content_featured_images_post', array( - 'default' => $fi_post_default, - 'type' => 'option', - 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', - ) ); - - $wp_customize->add_control( 'jetpack_content_featured_images_post', array( - 'section' => 'jetpack_content_options', - 'label' => esc_html__( 'Display on single posts', 'jetpack' ), - 'type' => 'checkbox', - 'active_callback' => 'jetpack_post_thumbnail_supports', - ) ); + $wp_customize->add_setting( + 'jetpack_content_featured_images_post', + array( + 'default' => $fi_post_default, + 'type' => 'option', + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', + ) + ); + + $wp_customize->add_control( + 'jetpack_content_featured_images_post', + array( + 'section' => 'jetpack_content_options', + 'label' => esc_html__( 'Display on single posts', 'jetpack' ), + 'type' => 'checkbox', + 'active_callback' => 'jetpack_post_thumbnail_supports', + ) + ); } // Featured Images: Page if ( true === $fi_page ) { - $wp_customize->add_setting( 'jetpack_content_featured_images_page', array( - 'default' => $fi_page_default, - 'type' => 'option', - 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', - ) ); - - $wp_customize->add_control( 'jetpack_content_featured_images_page', array( - 'section' => 'jetpack_content_options', - 'label' => esc_html__( 'Display on pages', 'jetpack' ), - 'type' => 'checkbox', - 'active_callback' => 'jetpack_post_thumbnail_supports', - ) ); + $wp_customize->add_setting( + 'jetpack_content_featured_images_page', + array( + 'default' => $fi_page_default, + 'type' => 'option', + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', + ) + ); + + $wp_customize->add_control( + 'jetpack_content_featured_images_page', + array( + 'section' => 'jetpack_content_options', + 'label' => esc_html__( 'Display on pages', 'jetpack' ), + 'type' => 'checkbox', + 'active_callback' => 'jetpack_post_thumbnail_supports', + ) + ); } - + // Featured Images: Portfolio if ( true === $fi_portfolio && post_type_exists( 'jetpack-portfolio' ) ) { - $wp_customize->add_setting( 'jetpack_content_featured_images_portfolio', array( - 'default' => $fi_portfolio_default, - 'type' => 'option', - 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', - ) ); - - $wp_customize->add_control( 'jetpack_content_featured_images_portfolio', array( - 'section' => 'jetpack_content_options', - 'label' => esc_html__( 'Display on single projects', 'jetpack' ), - 'type' => 'checkbox', - 'active_callback' => 'jetpack_post_thumbnail_supports', - ) ); + $wp_customize->add_setting( + 'jetpack_content_featured_images_portfolio', + array( + 'default' => $fi_portfolio_default, + 'type' => 'option', + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', + ) + ); + + $wp_customize->add_control( + 'jetpack_content_featured_images_portfolio', + array( + 'section' => 'jetpack_content_options', + 'label' => esc_html__( 'Display on single projects', 'jetpack' ), + 'type' => 'checkbox', + 'active_callback' => 'jetpack_post_thumbnail_supports', + ) + ); } // Featured Images: Fallback if ( true === $fi_fallback ) { - $wp_customize->add_setting( 'jetpack_content_featured_images_fallback', array( - 'default' => $fi_fallback_default, - 'type' => 'option', - 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', - ) ); - - $wp_customize->add_control( 'jetpack_content_featured_images_fallback', array( - 'section' => 'jetpack_content_options', - 'label' => esc_html__( 'Automatically use first image in post', 'jetpack' ), - 'type' => 'checkbox', - 'active_callback' => 'jetpack_post_thumbnail_supports', - ) ); + $wp_customize->add_setting( + 'jetpack_content_featured_images_fallback', + array( + 'default' => $fi_fallback_default, + 'type' => 'option', + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', + ) + ); + + $wp_customize->add_control( + 'jetpack_content_featured_images_fallback', + array( + 'section' => 'jetpack_content_options', + 'label' => esc_html__( 'Automatically use first image in post', 'jetpack' ), + 'type' => 'checkbox', + 'active_callback' => 'jetpack_post_thumbnail_supports', + ) + ); } } } @@ -365,17 +458,25 @@ function jetpack_content_options_customize_preview_js() { wp_enqueue_script( 'jetpack-content-options-customizer', plugins_url( 'customizer.js', __FILE__ ), array( 'customize-preview' ), '1.0', true ); - wp_localize_script( 'jetpack-content-options-customizer', 'blogDisplay', array( - 'display' => get_option( 'jetpack_content_blog_display', $blog_display ), - 'masonry' => $masonry, - ) ); - - wp_localize_script( 'jetpack-content-options-customizer', 'postDetails', array( - 'date' => $date, - 'categories' => $categories, - 'tags' => $tags, - 'author' => $author, - 'comment' => $comment, - ) ); + wp_localize_script( + 'jetpack-content-options-customizer', + 'blogDisplay', + array( + 'display' => get_option( 'jetpack_content_blog_display', $blog_display ), + 'masonry' => $masonry, + ) + ); + + wp_localize_script( + 'jetpack-content-options-customizer', + 'postDetails', + array( + 'date' => $date, + 'categories' => $categories, + 'tags' => $tags, + 'author' => $author, + 'comment' => $comment, + ) + ); } add_action( 'customize_preview_init', 'jetpack_content_options_customize_preview_js' ); diff --git a/plugins/jetpack/modules/theme-tools/content-options/featured-images-fallback.php b/plugins/jetpack/modules/theme-tools/content-options/featured-images-fallback.php index e0547467..dc8d92d6 100644 --- a/plugins/jetpack/modules/theme-tools/content-options/featured-images-fallback.php +++ b/plugins/jetpack/modules/theme-tools/content-options/featured-images-fallback.php @@ -57,7 +57,7 @@ function jetpack_featured_images_fallback_get_image( $html, $post_id, $post_thum // Use the theme's crop setting rather than forcing to true $image_src = add_query_arg( 'crop', $image['crop'], $image_src ); - $html = '<img src="' . esc_url( $image_src ) . '" title="' . esc_attr( strip_tags( get_the_title() ) ) . '" class="attachment-' . esc_attr( $size ) . ' wp-post-image" />'; + $html = '<img src="' . esc_url( $image_src ) . '" title="' . esc_attr( strip_tags( get_the_title() ) ) . '" class="attachment-' . esc_attr( $size ) . ' wp-post-image" />'; return trim( $html ); } @@ -71,9 +71,9 @@ add_filter( 'post_thumbnail_html', 'jetpack_featured_images_fallback_get_image', * Get URL of one image from a specified post in the following order: * Featured Image then first image from the_content HTML * - * @param int $post_id The post ID to check. - * @param int $post_thumbnail_id The ID of the featured image. - * @param string $size The image size to return, defaults to 'post-thumbnail'. + * @param int $post_id The post ID to check. + * @param int $post_thumbnail_id The ID of the featured image. + * @param string $size The image size to return, defaults to 'post-thumbnail'. * * @return string|null $image_src The URL of the thumbnail image. */ @@ -142,9 +142,9 @@ function jetpack_has_featured_image( $post = null ) { /** * Adds custom class to the array of post classes. * - * @param array $classes Classes for the post element. - * @param array $class Optional. Comma separated list of additional classes. - * @param array $post_id Unique The post ID to check + * @param array $classes Classes for the post element. + * @param array $class Optional. Comma separated list of additional classes. + * @param array $post_id Unique The post ID to check * * @return array $classes */ diff --git a/plugins/jetpack/modules/theme-tools/content-options/featured-images.php b/plugins/jetpack/modules/theme-tools/content-options/featured-images.php index 52ebe7fb..d6855f6c 100644 --- a/plugins/jetpack/modules/theme-tools/content-options/featured-images.php +++ b/plugins/jetpack/modules/theme-tools/content-options/featured-images.php @@ -74,7 +74,7 @@ function jetpack_is_shop_page() { $current_page_id = $wp_query->get( 'page_id' ); $is_static_front_page = 'page' === get_option( 'show_on_front' ); - if ( $is_static_front_page && $front_page_id === $current_page_id ) { + if ( $is_static_front_page && $front_page_id === $current_page_id ) { $is_shop_page = ( $current_page_id === wc_get_page_id( 'shop' ) ) ? true : false; } else { $is_shop_page = is_shop(); diff --git a/plugins/jetpack/modules/theme-tools/content-options/post-details.php b/plugins/jetpack/modules/theme-tools/content-options/post-details.php index a448381d..7851a5be 100644 --- a/plugins/jetpack/modules/theme-tools/content-options/post-details.php +++ b/plugins/jetpack/modules/theme-tools/content-options/post-details.php @@ -11,7 +11,7 @@ function jetpack_post_details_enqueue_scripts() { } list( $date_option, $categories_option, $tags_option, $author_option, $comment_option ) = $options; - list( $date, $categories, $tags, $author, $comment ) = $definied; + list( $date, $categories, $tags, $author, $comment ) = $definied; $elements = array(); @@ -63,7 +63,7 @@ function jetpack_post_details_body_classes( $classes ) { } list( $date_option, $categories_option, $tags_option, $author_option, $comment_option ) = $options; - list( $date, $categories, $tags, $author, $comment ) = $definied; + list( $date, $categories, $tags, $author, $comment ) = $definied; // If date option is unticked, add a class of 'date-hidden' to the body. if ( 1 != $date_option && ! empty( $date ) ) { diff --git a/plugins/jetpack/modules/theme-tools/featured-content.php b/plugins/jetpack/modules/theme-tools/featured-content.php index d63f3fd5..1090982c 100644 --- a/plugins/jetpack/modules/theme-tools/featured-content.php +++ b/plugins/jetpack/modules/theme-tools/featured-content.php @@ -2,677 +2,710 @@ if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'plugins.php' !== $GLOBALS['pagenow'] ) { -/** - * Featured Content. - * - * This module will allow users to define a subset of posts to be displayed in a - * theme-designated featured content area. - * - * This feature will only be activated for themes that declare that they support - * it. This can be done by adding code similar to the following during the - * "after_setup_theme" action: - * - * add_theme_support( 'featured-content', array( - * 'filter' => 'mytheme_get_featured_content', - * 'max_posts' => 20, - * 'post_types' => array( 'post', 'page' ), - * ) ); - * - * For maximum compatibility with different methods of posting users will - * designate a featured post tag to associate posts with. Since this tag now has - * special meaning beyond that of a normal tags, users will have the ability to - * hide it from the front-end of their site. - */ -class Featured_Content { - /** - * The maximum number of posts that a Featured Content area can contain. We - * define a default value here but themes can override this by defining a - * "max_posts" entry in the second parameter passed in the call to - * add_theme_support( 'featured-content' ). + * Featured Content. * - * @see Featured_Content::init() - */ - public static $max_posts = 15; - - /** - * The registered post types supported by Featured Content. Themes can add - * Featured Content support for registered post types by defining a - * 'post_types' argument (string|array) in the call to - * add_theme_support( 'featured-content' ). + * This module will allow users to define a subset of posts to be displayed in a + * theme-designated featured content area. * - * @see Featured_Content::init() - */ - public static $post_types = array( 'post' ); - - /** - * The tag that is used to mark featured content. Users can define - * a custom tag name that will be stored in this variable. + * This feature will only be activated for themes that declare that they support + * it. This can be done by adding code similar to the following during the + * "after_setup_theme" action: * - * @see Featured_Content::hide_featured_term - */ - public static $tag; - - /** - * Instantiate. + * add_theme_support( 'featured-content', array( + * 'filter' => 'mytheme_get_featured_content', + * 'max_posts' => 20, + * 'post_types' => array( 'post', 'page' ), + * ) ); * - * All custom functionality will be hooked into the "init" action. + * For maximum compatibility with different methods of posting users will + * designate a featured post tag to associate posts with. Since this tag now has + * special meaning beyond that of a normal tags, users will have the ability to + * hide it from the front-end of their site. */ - public static function setup() { - add_action( 'init', array( __CLASS__, 'init' ), 30 ); - } + class Featured_Content { - /** - * Conditionally hook into WordPress. - * - * Themes must declare that they support this module by adding - * add_theme_support( 'featured-content' ); during after_setup_theme. - * - * If no theme support is found there is no need to hook into WordPress. We'll - * just return early instead. - * - * @uses Featured_Content::$max_posts - */ - public static function init() { - $theme_support = get_theme_support( 'featured-content' ); + /** + * The maximum number of posts that a Featured Content area can contain. We + * define a default value here but themes can override this by defining a + * "max_posts" entry in the second parameter passed in the call to + * add_theme_support( 'featured-content' ). + * + * @see Featured_Content::init() + */ + public static $max_posts = 15; - // Return early if theme does not support featured content. - if ( ! $theme_support ) { - return; - } + /** + * The registered post types supported by Featured Content. Themes can add + * Featured Content support for registered post types by defining a + * 'post_types' argument (string|array) in the call to + * add_theme_support( 'featured-content' ). + * + * @see Featured_Content::init() + */ + public static $post_types = array( 'post' ); - /* - * An array of named arguments must be passed as the second parameter - * of add_theme_support(). + /** + * The tag that is used to mark featured content. Users can define + * a custom tag name that will be stored in this variable. + * + * @see Featured_Content::hide_featured_term */ - if ( ! isset( $theme_support[0] ) ) { - return; - } + public static $tag; - if ( isset( $theme_support[0]['featured_content_filter'] ) ) { - $theme_support[0]['filter'] = $theme_support[0]['featured_content_filter']; - unset( $theme_support[0]['featured_content_filter'] ); + /** + * Instantiate. + * + * All custom functionality will be hooked into the "init" action. + */ + public static function setup() { + add_action( 'init', array( __CLASS__, 'init' ), 30 ); } - // Return early if "filter" has not been defined. - if ( ! isset( $theme_support[0]['filter'] ) ) { - return; - } + /** + * Conditionally hook into WordPress. + * + * Themes must declare that they support this module by adding + * add_theme_support( 'featured-content' ); during after_setup_theme. + * + * If no theme support is found there is no need to hook into WordPress. We'll + * just return early instead. + * + * @uses Featured_Content::$max_posts + */ + public static function init() { + $theme_support = get_theme_support( 'featured-content' ); - // Theme can override the number of max posts. - if ( isset( $theme_support[0]['max_posts'] ) ) { - self::$max_posts = absint( $theme_support[0]['max_posts'] ); - } + // Return early if theme does not support featured content. + if ( ! $theme_support ) { + return; + } - add_filter( $theme_support[0]['filter'], array( __CLASS__, 'get_featured_posts' ) ); - add_action( 'customize_register', array( __CLASS__, 'customize_register' ), 9 ); - add_action( 'admin_init', array( __CLASS__, 'register_setting' ) ); - add_action( 'save_post', array( __CLASS__, 'delete_transient' ) ); - add_action( 'delete_post_tag', array( __CLASS__, 'delete_post_tag' ) ); - add_action( 'customize_controls_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) ); - add_action( 'pre_get_posts', array( __CLASS__, 'pre_get_posts' ) ); - add_action( 'switch_theme', array( __CLASS__, 'switch_theme' ) ); - add_action( 'switch_theme', array( __CLASS__, 'delete_transient' ) ); - add_action( 'wp_loaded', array( __CLASS__, 'wp_loaded' ) ); - add_action( 'update_option_featured-content', array( __CLASS__, 'flush_post_tag_cache' ), 10, 2 ); - add_action( 'delete_option_featured-content', array( __CLASS__, 'flush_post_tag_cache' ), 10, 2 ); - add_action( 'split_shared_term', array( __CLASS__, 'jetpack_update_featured_content_for_split_terms', 10, 4 ) ); - - - if ( isset( $theme_support[0]['additional_post_types'] ) ) { - $theme_support[0]['post_types'] = array_merge( array( 'post' ), (array) $theme_support[0]['additional_post_types'] ); - unset( $theme_support[0]['additional_post_types'] ); - } + /* + * An array of named arguments must be passed as the second parameter + * of add_theme_support(). + */ + if ( ! isset( $theme_support[0] ) ) { + return; + } - // Themes can allow Featured Content pages - if ( isset( $theme_support[0]['post_types'] ) ) { - self::$post_types = array_merge( self::$post_types, (array) $theme_support[0]['post_types'] ); + if ( isset( $theme_support[0]['featured_content_filter'] ) ) { + $theme_support[0]['filter'] = $theme_support[0]['featured_content_filter']; + unset( $theme_support[0]['featured_content_filter'] ); + } - // register post_tag support for each post type - foreach ( self::$post_types as $post_type ) { - register_taxonomy_for_object_type( 'post_tag', $post_type ); + // Return early if "filter" has not been defined. + if ( ! isset( $theme_support[0]['filter'] ) ) { + return; } - } - } - /** - * Hide "featured" tag from the front-end. - * - * Has to run on wp_loaded so that the preview filters of the customizer - * have a chance to alter the value. - */ - public static function wp_loaded() { - if ( self::get_setting( 'hide-tag' ) ) { - $settings = self::get_setting(); + // Theme can override the number of max posts. + if ( isset( $theme_support[0]['max_posts'] ) ) { + self::$max_posts = absint( $theme_support[0]['max_posts'] ); + } + + add_filter( $theme_support[0]['filter'], array( __CLASS__, 'get_featured_posts' ) ); + add_action( 'customize_register', array( __CLASS__, 'customize_register' ), 9 ); + add_action( 'admin_init', array( __CLASS__, 'register_setting' ) ); + add_action( 'save_post', array( __CLASS__, 'delete_transient' ) ); + add_action( 'delete_post_tag', array( __CLASS__, 'delete_post_tag' ) ); + add_action( 'customize_controls_enqueue_scripts', array( __CLASS__, 'enqueue_scripts' ) ); + add_action( 'pre_get_posts', array( __CLASS__, 'pre_get_posts' ) ); + add_action( 'switch_theme', array( __CLASS__, 'switch_theme' ) ); + add_action( 'switch_theme', array( __CLASS__, 'delete_transient' ) ); + add_action( 'wp_loaded', array( __CLASS__, 'wp_loaded' ) ); + add_action( 'update_option_featured-content', array( __CLASS__, 'flush_post_tag_cache' ), 10, 2 ); + add_action( 'delete_option_featured-content', array( __CLASS__, 'flush_post_tag_cache' ), 10, 2 ); + add_action( 'split_shared_term', array( __CLASS__, 'jetpack_update_featured_content_for_split_terms', 10, 4 ) ); + + if ( isset( $theme_support[0]['additional_post_types'] ) ) { + $theme_support[0]['post_types'] = array_merge( array( 'post' ), (array) $theme_support[0]['additional_post_types'] ); + unset( $theme_support[0]['additional_post_types'] ); + } - // This is done before setting filters for get_terms in order to avoid an infinite filter loop - self::$tag = get_term_by( 'name', $settings['tag-name'], 'post_tag' ); + // Themes can allow Featured Content pages + if ( isset( $theme_support[0]['post_types'] ) ) { + self::$post_types = array_merge( self::$post_types, (array) $theme_support[0]['post_types'] ); + self::$post_types = array_unique( self::$post_types ); - add_filter( 'get_terms', array( __CLASS__, 'hide_featured_term' ), 10, 3 ); - add_filter( 'get_the_terms', array( __CLASS__, 'hide_the_featured_term' ), 10, 3 ); + // register post_tag support for each post type + foreach ( self::$post_types as $post_type ) { + register_taxonomy_for_object_type( 'post_tag', $post_type ); + } + } } - } - /** - * Get featured posts - * - * This method is not intended to be called directly. Theme developers should - * place a filter directly in their theme and then pass its name as a value of - * the "filter" key in the array passed as the $args parameter during the call - * to: add_theme_support( 'featured-content', $args ). - * - * @uses Featured_Content::get_featured_post_ids() - * - * @return array - */ - public static function get_featured_posts() { - $post_ids = self::get_featured_post_ids(); + /** + * Hide "featured" tag from the front-end. + * + * Has to run on wp_loaded so that the preview filters of the customizer + * have a chance to alter the value. + */ + public static function wp_loaded() { + if ( self::get_setting( 'hide-tag' ) ) { + $settings = self::get_setting(); - // No need to query if there is are no featured posts. - if ( empty( $post_ids ) ) { - return array(); + // This is done before setting filters for get_terms in order to avoid an infinite filter loop + self::$tag = get_term_by( 'name', $settings['tag-name'], 'post_tag' ); + + add_filter( 'get_terms', array( __CLASS__, 'hide_featured_term' ), 10, 3 ); + add_filter( 'get_the_terms', array( __CLASS__, 'hide_the_featured_term' ), 10, 3 ); + } } - $featured_posts = get_posts( array( - 'include' => $post_ids, - 'posts_per_page' => count( $post_ids ), - 'post_type' => self::$post_types, - 'suppress_filters' => false, - ) ); + /** + * Get featured posts + * + * This method is not intended to be called directly. Theme developers should + * place a filter directly in their theme and then pass its name as a value of + * the "filter" key in the array passed as the $args parameter during the call + * to: add_theme_support( 'featured-content', $args ). + * + * @uses Featured_Content::get_featured_post_ids() + * + * @return array + */ + public static function get_featured_posts() { + $post_ids = self::get_featured_post_ids(); - return $featured_posts; - } + // No need to query if there is are no featured posts. + if ( empty( $post_ids ) ) { + return array(); + } - /** - * Get featured post IDs - * - * This function will return the an array containing the post IDs of all - * featured posts. - * - * Sets the "featured_content_ids" transient. - * - * @return array Array of post IDs. - */ - public static function get_featured_post_ids() { - // Return array of cached results if they exist. - $featured_ids = get_transient( 'featured_content_ids' ); - if ( ! empty( $featured_ids ) ) { - return array_map( - 'absint', - /** - * Filter the list of Featured Posts IDs. - * - * @module theme-tools - * - * @since 2.7.0 - * - * @param array $featured_ids Array of post IDs. - */ - apply_filters( 'featured_content_post_ids', (array) $featured_ids ) + $featured_posts = get_posts( + array( + 'include' => $post_ids, + 'posts_per_page' => count( $post_ids ), + 'post_type' => self::$post_types, + 'suppress_filters' => false, + ) ); + + return $featured_posts; } - $settings = self::get_setting(); + /** + * Get featured post IDs + * + * This function will return the an array containing the post IDs of all + * featured posts. + * + * Sets the "featured_content_ids" transient. + * + * @return array Array of post IDs. + */ + public static function get_featured_post_ids() { + // Return array of cached results if they exist. + $featured_ids = get_transient( 'featured_content_ids' ); + if ( ! empty( $featured_ids ) ) { + return array_map( + 'absint', + /** + * Filter the list of Featured Posts IDs. + * + * @module theme-tools + * + * @since 2.7.0 + * + * @param array $featured_ids Array of post IDs. + */ + apply_filters( 'featured_content_post_ids', (array) $featured_ids ) + ); + } - // Return empty array if no tag name is set. - $term = get_term_by( 'name', $settings['tag-name'], 'post_tag' ); - if ( ! $term ) { - $term = get_term_by( 'id', $settings['tag-id'], 'post_tag' ); - } - if ( $term ) { - $tag = $term->term_id; - } else { - /** This action is documented in modules/theme-tools/featured-content.php */ - return apply_filters( 'featured_content_post_ids', array() ); - } + $settings = self::get_setting(); - // Back compat for installs that have the quantity option still set. - $quantity = isset( $settings['quantity'] ) ? $settings['quantity'] : self::$max_posts; + // Return empty array if no tag name is set. + $term = get_term_by( 'name', $settings['tag-name'], 'post_tag' ); + if ( ! $term ) { + $term = get_term_by( 'id', $settings['tag-id'], 'post_tag' ); + } + if ( $term ) { + $tag = $term->term_id; + } else { + /** This action is documented in modules/theme-tools/featured-content.php */ + return apply_filters( 'featured_content_post_ids', array() ); + } - // Query for featured posts. - $featured = get_posts( array( - 'numberposts' => $quantity, - 'post_type' => self::$post_types, - 'suppress_filters' => false, - 'tax_query' => array( - array( - 'field' => 'term_id', - 'taxonomy' => 'post_tag', - 'terms' => $tag, - ), - ), - ) ); - - // Return empty array if no featured content exists. - if ( ! $featured ) { - /** This action is documented in modules/theme-tools/featured-content.php */ - return apply_filters( 'featured_content_post_ids', array() ); - } + // Back compat for installs that have the quantity option still set. + $quantity = isset( $settings['quantity'] ) ? $settings['quantity'] : self::$max_posts; - // Ensure correct format before save/return. - $featured_ids = wp_list_pluck( (array) $featured, 'ID' ); - $featured_ids = array_map( 'absint', $featured_ids ); + // Query for featured posts. + $featured = get_posts( + array( + 'numberposts' => $quantity, + 'post_type' => self::$post_types, + 'suppress_filters' => false, + 'tax_query' => array( + array( + 'field' => 'term_id', + 'taxonomy' => 'post_tag', + 'terms' => $tag, + ), + ), + ) + ); - set_transient( 'featured_content_ids', $featured_ids ); + // Return empty array if no featured content exists. + if ( ! $featured ) { + /** This action is documented in modules/theme-tools/featured-content.php */ + return apply_filters( 'featured_content_post_ids', array() ); + } - /** This action is documented in modules/theme-tools/featured-content.php */ - return apply_filters( 'featured_content_post_ids', $featured_ids ); - } + // Ensure correct format before save/return. + $featured_ids = wp_list_pluck( (array) $featured, 'ID' ); + $featured_ids = array_map( 'absint', $featured_ids ); - /** - * Delete Transient. - * - * Hooks in the "save_post" action. - * @see Featured_Content::validate_settings(). - */ - public static function delete_transient() { - delete_transient( 'featured_content_ids' ); - } + set_transient( 'featured_content_ids', $featured_ids ); - /** - * Flush the Post Tag relationships cache. - * - * Hooks in the "update_option_featured-content" action. - */ - public static function flush_post_tag_cache( $prev, $opts ) { - if ( ! empty( $opts ) && ! empty( $opts['tag-id'] ) ) { - $query = new WP_Query( array( - 'tag_id' => (int) $opts['tag-id'], - 'posts_per_page' => -1, - ) ); - foreach ( $query->posts as $post ) { - wp_cache_delete( $post->ID, 'post_tag_relationships' ); - } + /** This action is documented in modules/theme-tools/featured-content.php */ + return apply_filters( 'featured_content_post_ids', $featured_ids ); } - } - - /** - * Exclude featured posts from the blog query when the blog is the front-page, - * and user has not checked the "Also display tagged posts outside the Featured Content area" checkbox. - * - * Filter the home page posts, and remove any featured post ID's from it. - * Hooked onto the 'pre_get_posts' action, this changes the parameters of the - * query before it gets any posts. - * - * @uses Featured_Content::get_featured_post_ids(); - * @uses Featured_Content::get_setting(); - * @param WP_Query $query - * @return WP_Query Possibly modified WP_Query - */ - public static function pre_get_posts( $query ) { - // Bail if not home or not main query. - if ( ! $query->is_home() || ! $query->is_main_query() ) { - return; + /** + * Delete Transient. + * + * Hooks in the "save_post" action. + * + * @see Featured_Content::validate_settings(). + */ + public static function delete_transient() { + delete_transient( 'featured_content_ids' ); } - // Bail if the blog page is not the front page. - if ( 'posts' !== get_option( 'show_on_front' ) ) { - return; + /** + * Flush the Post Tag relationships cache. + * + * Hooks in the "update_option_featured-content" action. + */ + public static function flush_post_tag_cache( $prev, $opts ) { + if ( ! empty( $opts ) && ! empty( $opts['tag-id'] ) ) { + $query = new WP_Query( + array( + 'tag_id' => (int) $opts['tag-id'], + 'posts_per_page' => -1, + ) + ); + foreach ( $query->posts as $post ) { + wp_cache_delete( $post->ID, 'post_tag_relationships' ); + } + } } - $featured = self::get_featured_post_ids(); + /** + * Exclude featured posts from the blog query when the blog is the front-page, + * and user has not checked the "Also display tagged posts outside the Featured Content area" checkbox. + * + * Filter the home page posts, and remove any featured post ID's from it. + * Hooked onto the 'pre_get_posts' action, this changes the parameters of the + * query before it gets any posts. + * + * @uses Featured_Content::get_featured_post_ids(); + * @uses Featured_Content::get_setting(); + * @param WP_Query $query + * @return WP_Query Possibly modified WP_Query + */ + public static function pre_get_posts( $query ) { - // Bail if no featured posts. - if ( ! $featured ) { - return; - } + // Bail if not home or not main query. + if ( ! $query->is_home() || ! $query->is_main_query() ) { + return; + } - $settings = self::get_setting(); + // Bail if the blog page is not the front page. + if ( 'posts' !== get_option( 'show_on_front' ) ) { + return; + } - // Bail if the user wants featured posts always displayed. - if ( true == $settings['show-all'] ) { - return; - } + $featured = self::get_featured_post_ids(); - // We need to respect post ids already in the blacklist. - $post__not_in = $query->get( 'post__not_in' ); + // Bail if no featured posts. + if ( ! $featured ) { + return; + } - if ( ! empty( $post__not_in ) ) { - $featured = array_merge( (array) $post__not_in, $featured ); - $featured = array_unique( $featured ); - } + $settings = self::get_setting(); - $query->set( 'post__not_in', $featured ); - } + // Bail if the user wants featured posts always displayed. + if ( true == $settings['show-all'] ) { + return; + } - /** - * Reset tag option when the saved tag is deleted. - * - * It's important to mention that the transient needs to be deleted, too. - * While it may not be obvious by looking at the function alone, the transient - * is deleted by Featured_Content::validate_settings(). - * - * Hooks in the "delete_post_tag" action. - * @see Featured_Content::validate_settings(). - * - * @param int $tag_id The term_id of the tag that has been deleted. - * @return void - */ - public static function delete_post_tag( $tag_id ) { - $settings = self::get_setting(); + // We need to respect post ids already in the blacklist. + $post__not_in = $query->get( 'post__not_in' ); - if ( empty( $settings['tag-id'] ) || $tag_id != $settings['tag-id'] ) { - return; + if ( ! empty( $post__not_in ) ) { + $featured = array_merge( (array) $post__not_in, $featured ); + $featured = array_unique( $featured ); + } + + $query->set( 'post__not_in', $featured ); } - $settings['tag-id'] = 0; - $settings = self::validate_settings( $settings ); - update_option( 'featured-content', $settings ); - } + /** + * Reset tag option when the saved tag is deleted. + * + * It's important to mention that the transient needs to be deleted, too. + * While it may not be obvious by looking at the function alone, the transient + * is deleted by Featured_Content::validate_settings(). + * + * Hooks in the "delete_post_tag" action. + * + * @see Featured_Content::validate_settings(). + * + * @param int $tag_id The term_id of the tag that has been deleted. + * @return void + */ + public static function delete_post_tag( $tag_id ) { + $settings = self::get_setting(); - /** - * Hide featured tag from displaying when global terms are queried from - * the front-end. - * - * Hooks into the "get_terms" filter. - * - * @uses Featured_Content::get_setting() - * - * @param array $terms A list of term objects. This is the return value of get_terms(). - * @param array $taxonomies An array of taxonomy slugs. - * @return array $terms - */ - public static function hide_featured_term( $terms, $taxonomies, $args ) { + if ( empty( $settings['tag-id'] ) || $tag_id != $settings['tag-id'] ) { + return; + } - // This filter is only appropriate on the front-end. - if ( is_admin() ) { - return $terms; + $settings['tag-id'] = 0; + $settings = self::validate_settings( $settings ); + update_option( 'featured-content', $settings ); } - // We only want to hide the featured tag. - if ( ! in_array( 'post_tag', $taxonomies ) ) { - return $terms; - } + /** + * Hide featured tag from displaying when global terms are queried from + * the front-end. + * + * Hooks into the "get_terms" filter. + * + * @uses Featured_Content::get_setting() + * + * @param array $terms A list of term objects. This is the return value of get_terms(). + * @param array $taxonomies An array of taxonomy slugs. + * @return array $terms + */ + public static function hide_featured_term( $terms, $taxonomies, $args ) { - // Bail if no terms were returned. - if ( empty( $terms ) ) { - return $terms; - } + // This filter is only appropriate on the front-end. + if ( is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) ) { + return $terms; + } - // Bail if term objects are unavailable. - if ( 'all' != $args['fields'] ) { - return $terms; - } + // We only want to hide the featured tag. + if ( ! in_array( 'post_tag', $taxonomies ) ) { + return $terms; + } + + // Bail if no terms were returned. + if ( empty( $terms ) ) { + return $terms; + } + + // Bail if term objects are unavailable. + if ( 'all' != $args['fields'] ) { + return $terms; + } - $settings = self::get_setting(); + $settings = self::get_setting(); - if ( false !== self::$tag ) { - foreach ( $terms as $order => $term ) { - if ( + if ( false !== self::$tag ) { + foreach ( $terms as $order => $term ) { + if ( is_object( $term ) && ( $settings['tag-id'] === $term->term_id || $settings['tag-name'] === $term->name ) - ) { - unset( $terms[ $order ] ); + ) { + unset( $terms[ $order ] ); + } } } - } - - return $terms; - } - /** - * Hide featured tag from displaying when terms associated with a post object - * are queried from the front-end. - * - * Hooks into the "get_the_terms" filter. - * - * @uses Featured_Content::get_setting() - * - * @param array $terms A list of term objects. This is the return value of get_the_terms(). - * @param int $id The ID field for the post object that terms are associated with. - * @param array $taxonomy An array of taxonomy slugs. - * @return array $terms - */ - public static function hide_the_featured_term( $terms, $id, $taxonomy ) { - - // This filter is only appropriate on the front-end. - if ( is_admin() ) { return $terms; } - // Make sure we are in the correct taxonomy. - if ( 'post_tag' != $taxonomy ) { - return $terms; - } + /** + * Hide featured tag from displaying when terms associated with a post object + * are queried from the front-end. + * + * Hooks into the "get_the_terms" filter. + * + * @uses Featured_Content::get_setting() + * + * @param array $terms A list of term objects. This is the return value of get_the_terms(). + * @param int $id The ID field for the post object that terms are associated with. + * @param array $taxonomy An array of taxonomy slugs. + * @return array $terms + */ + public static function hide_the_featured_term( $terms, $id, $taxonomy ) { - // No terms? Return early! - if ( empty( $terms ) ) { - return $terms; - } + // This filter is only appropriate on the front-end. + if ( is_admin() ) { + return $terms; + } - $settings = self::get_setting(); - $tag = get_term_by( 'name', $settings['tag-name'], 'post_tag' ); + // Make sure we are in the correct taxonomy. + if ( 'post_tag' != $taxonomy ) { + return $terms; + } - if ( false !== $tag ) { - foreach ( $terms as $order => $term ) { - if ( $settings['tag-id'] === $term->term_id || $settings['tag-name'] === $term->name ) { - unset( $terms[ $order ] ); + // No terms? Return early! + if ( empty( $terms ) ) { + return $terms; + } + + $settings = self::get_setting(); + $tag = get_term_by( 'name', $settings['tag-name'], 'post_tag' ); + + if ( false !== $tag ) { + foreach ( $terms as $order => $term ) { + if ( $settings['tag-id'] === $term->term_id || $settings['tag-name'] === $term->name ) { + unset( $terms[ $order ] ); + } } } - } - return $terms; - } + return $terms; + } - /** - * Register custom setting on the Settings -> Reading screen. - * - * @uses Featured_Content::render_form() - * @uses Featured_Content::validate_settings() - * - * @return void - */ - public static function register_setting() { - add_settings_field( 'featured-content', __( 'Featured Content', 'jetpack' ), array( __class__, 'render_form' ), 'reading' ); + /** + * Register custom setting on the Settings -> Reading screen. + * + * @uses Featured_Content::render_form() + * @uses Featured_Content::validate_settings() + * + * @return void + */ + public static function register_setting() { + add_settings_field( 'featured-content', __( 'Featured Content', 'jetpack' ), array( __class__, 'render_form' ), 'reading' ); - // Register sanitization callback for the Customizer. - register_setting( 'featured-content', 'featured-content', array( __class__, 'validate_settings' ) ); - } + // Register sanitization callback for the Customizer. + register_setting( 'featured-content', 'featured-content', array( __class__, 'validate_settings' ) ); + } - /** - * Add settings to the Customizer. - * - * @param WP_Customize_Manager $wp_customize Theme Customizer object. - */ - public static function customize_register( $wp_customize ) { - $wp_customize->add_section( 'featured_content', array( - 'title' => esc_html__( 'Featured Content', 'jetpack' ), - 'description' => sprintf( __( 'Easily feature all posts with the <a href="%1$s">"featured" tag</a> or a tag of your choice. Your theme supports up to %2$s posts in its featured content area.', 'jetpack' ), admin_url( '/edit.php?tag=featured' ), absint( self::$max_posts ) ), - 'priority' => 130, - 'theme_supports' => 'featured-content', - ) ); - - /* Add Featured Content settings. - * - * Sanitization callback registered in Featured_Content::validate_settings(). - * See http://themeshaper.com/2013/04/29/validation-sanitization-in-customizer/comment-page-1/#comment-12374 + /** + * Add settings to the Customizer. + * + * @param WP_Customize_Manager $wp_customize Theme Customizer object. */ - $wp_customize->add_setting( 'featured-content[tag-name]', array( - 'type' => 'option', - 'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ), - ) ); - $wp_customize->add_setting( 'featured-content[hide-tag]', array( - 'default' => true, - 'type' => 'option', - 'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ), - ) ); - $wp_customize->add_setting( 'featured-content[show-all]', array( - 'default' => false, - 'type' => 'option', - 'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ), - ) ); - - // Add Featured Content controls. - $wp_customize->add_control( 'featured-content[tag-name]', array( - 'label' => esc_html__( 'Tag name', 'jetpack' ), - 'section' => 'featured_content', - 'theme_supports' => 'featured-content', - 'priority' => 20, - ) ); - $wp_customize->add_control( 'featured-content[hide-tag]', array( - 'label' => esc_html__( 'Do not display tag in post details and tag clouds.', 'jetpack' ), - 'section' => 'featured_content', - 'theme_supports' => 'featured-content', - 'type' => 'checkbox', - 'priority' => 30, - ) ); - $wp_customize->add_control( 'featured-content[show-all]', array( - 'label' => esc_html__( 'Also display tagged posts outside the Featured Content area.', 'jetpack' ), - 'section' => 'featured_content', - 'theme_supports' => 'featured-content', - 'type' => 'checkbox', - 'priority' => 40, - ) ); - } + public static function customize_register( $wp_customize ) { + $wp_customize->add_section( + 'featured_content', + array( + 'title' => esc_html__( 'Featured Content', 'jetpack' ), + 'description' => sprintf( __( 'Easily feature all posts with the <a href="%1$s">"featured" tag</a> or a tag of your choice. Your theme supports up to %2$s posts in its featured content area.', 'jetpack' ), admin_url( '/edit.php?tag=featured' ), absint( self::$max_posts ) ), + 'priority' => 130, + 'theme_supports' => 'featured-content', + ) + ); - /** - * Enqueue the tag suggestion script. - */ - public static function enqueue_scripts() { - wp_enqueue_script( 'featured-content-suggest', plugins_url( 'js/suggest.js', __FILE__ ), array( 'suggest' ), '20131022', true ); - } + /* + Add Featured Content settings. + * + * Sanitization callback registered in Featured_Content::validate_settings(). + * See http://themeshaper.com/2013/04/29/validation-sanitization-in-customizer/comment-page-1/#comment-12374 + */ + $wp_customize->add_setting( + 'featured-content[tag-name]', + array( + 'type' => 'option', + 'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ), + ) + ); + $wp_customize->add_setting( + 'featured-content[hide-tag]', + array( + 'default' => true, + 'type' => 'option', + 'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ), + ) + ); + $wp_customize->add_setting( + 'featured-content[show-all]', + array( + 'default' => false, + 'type' => 'option', + 'sanitize_js_callback' => array( __CLASS__, 'delete_transient' ), + ) + ); - /** - * Renders all form fields on the Settings -> Reading screen. - */ - public static function render_form() { - printf( __( 'The settings for Featured Content have <a href="%s">moved to Appearance → Customize</a>.', 'jetpack' ), admin_url( 'customize.php?#accordion-section-featured_content' ) ); - } + // Add Featured Content controls. + $wp_customize->add_control( + 'featured-content[tag-name]', + array( + 'label' => esc_html__( 'Tag name', 'jetpack' ), + 'section' => 'featured_content', + 'theme_supports' => 'featured-content', + 'priority' => 20, + ) + ); + $wp_customize->add_control( + 'featured-content[hide-tag]', + array( + 'label' => esc_html__( 'Do not display tag in post details and tag clouds.', 'jetpack' ), + 'section' => 'featured_content', + 'theme_supports' => 'featured-content', + 'type' => 'checkbox', + 'priority' => 30, + ) + ); + $wp_customize->add_control( + 'featured-content[show-all]', + array( + 'label' => esc_html__( 'Also display tagged posts outside the Featured Content area.', 'jetpack' ), + 'section' => 'featured_content', + 'theme_supports' => 'featured-content', + 'type' => 'checkbox', + 'priority' => 40, + ) + ); + } - /** - * Get settings - * - * Get all settings recognized by this module. This function will return all - * settings whether or not they have been stored in the database yet. This - * ensures that all keys are available at all times. - * - * In the event that you only require one setting, you may pass its name as the - * first parameter to the function and only that value will be returned. - * - * @param string $key The key of a recognized setting. - * @return mixed Array of all settings by default. A single value if passed as first parameter. - */ - public static function get_setting( $key = 'all' ) { - $saved = (array) get_option( 'featured-content' ); + /** + * Enqueue the tag suggestion script. + */ + public static function enqueue_scripts() { + wp_enqueue_script( 'featured-content-suggest', plugins_url( 'js/suggest.js', __FILE__ ), array( 'suggest' ), '20131022', true ); + } /** - * Filter Featured Content's default settings. - * - * @module theme-tools + * Renders all form fields on the Settings -> Reading screen. + */ + public static function render_form() { + printf( __( 'The settings for Featured Content have <a href="%s">moved to Appearance → Customize</a>.', 'jetpack' ), admin_url( 'customize.php?#accordion-section-featured_content' ) ); + } + + /** + * Get settings * - * @since 2.7.0 + * Get all settings recognized by this module. This function will return all + * settings whether or not they have been stored in the database yet. This + * ensures that all keys are available at all times. * - * @param array $args { - * Array of Featured Content Settings + * In the event that you only require one setting, you may pass its name as the + * first parameter to the function and only that value will be returned. * - * @type int hide-tag Default is 1. - * @type int tag-id Default is 0. - * @type string tag-name Default is empty. - * @type int show-all Default is 0. - * } + * @param string $key The key of a recognized setting. + * @return mixed Array of all settings by default. A single value if passed as first parameter. */ - $defaults = apply_filters( 'featured_content_default_settings', array( - 'hide-tag' => 1, - 'tag-id' => 0, - 'tag-name' => '', - 'show-all' => 0, - ) ); - - $options = wp_parse_args( $saved, $defaults ); - $options = array_intersect_key( $options, $defaults ); - - if ( 'all' != $key ) { - return isset( $options[ $key ] ) ? $options[ $key ] : false; - } + public static function get_setting( $key = 'all' ) { + $saved = (array) get_option( 'featured-content' ); + + /** + * Filter Featured Content's default settings. + * + * @module theme-tools + * + * @since 2.7.0 + * + * @param array $args { + * Array of Featured Content Settings + * + * @type int hide-tag Default is 1. + * @type int tag-id Default is 0. + * @type string tag-name Default is empty. + * @type int show-all Default is 0. + * } + */ + $defaults = apply_filters( + 'featured_content_default_settings', + array( + 'hide-tag' => 1, + 'tag-id' => 0, + 'tag-name' => '', + 'show-all' => 0, + ) + ); - return $options; - } + $options = wp_parse_args( $saved, $defaults ); + $options = array_intersect_key( $options, $defaults ); - /** - * Validate settings - * - * Make sure that all user supplied content is in an expected format before - * saving to the database. This function will also delete the transient set in - * Featured_Content::get_featured_content(). - * - * @uses Featured_Content::delete_transient() - * - * @param array $input - * @return array $output - */ - public static function validate_settings( $input ) { - $output = array(); + if ( 'all' != $key ) { + return isset( $options[ $key ] ) ? $options[ $key ] : false; + } - if ( empty( $input['tag-name'] ) ) { - $output['tag-id'] = 0; - } else { - $term = get_term_by( 'name', $input['tag-name'], 'post_tag' ); + return $options; + } - if ( $term ) { - $output['tag-id'] = $term->term_id; + /** + * Validate settings + * + * Make sure that all user supplied content is in an expected format before + * saving to the database. This function will also delete the transient set in + * Featured_Content::get_featured_content(). + * + * @uses Featured_Content::delete_transient() + * + * @param array $input + * @return array $output + */ + public static function validate_settings( $input ) { + $output = array(); + + if ( empty( $input['tag-name'] ) ) { + $output['tag-id'] = 0; } else { - $new_tag = wp_create_tag( $input['tag-name'] ); + $term = get_term_by( 'name', $input['tag-name'], 'post_tag' ); + + if ( $term ) { + $output['tag-id'] = $term->term_id; + } else { + $new_tag = wp_create_tag( $input['tag-name'] ); - if ( ! is_wp_error( $new_tag ) && isset( $new_tag['term_id'] ) ) { - $output['tag-id'] = $new_tag['term_id']; + if ( ! is_wp_error( $new_tag ) && isset( $new_tag['term_id'] ) ) { + $output['tag-id'] = $new_tag['term_id']; + } } + + $output['tag-name'] = $input['tag-name']; } - $output['tag-name'] = $input['tag-name']; - } + $output['hide-tag'] = isset( $input['hide-tag'] ) && $input['hide-tag'] ? 1 : 0; - $output['hide-tag'] = isset( $input['hide-tag'] ) && $input['hide-tag'] ? 1 : 0; + $output['show-all'] = isset( $input['show-all'] ) && $input['show-all'] ? 1 : 0; - $output['show-all'] = isset( $input['show-all'] ) && $input['show-all'] ? 1 : 0; + self::delete_transient(); - self::delete_transient(); + return $output; + } - return $output; - } + /** + * Removes the quantity setting from the options array. + * + * @return void + */ + public static function switch_theme() { + $option = (array) get_option( 'featured-content' ); - /** - * Removes the quantity setting from the options array. - * - * @return void - */ - public static function switch_theme() { - $option = (array) get_option( 'featured-content' ); + if ( isset( $option['quantity'] ) ) { + unset( $option['quantity'] ); + update_option( 'featured-content', $option ); + } + } - if ( isset( $option['quantity'] ) ) { - unset( $option['quantity'] ); - update_option( 'featured-content', $option ); + public static function jetpack_update_featured_content_for_split_terms( $old_term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) { + $featured_content_settings = get_option( 'featured-content', array() ); + + // Check to see whether the stored tag ID is the one that's just been split. + if ( isset( $featured_content_settings['tag-id'] ) && $old_term_id == $featured_content_settings['tag-id'] && 'post_tag' == $taxonomy ) { + // We have a match, so we swap out the old tag ID for the new one and resave the option. + $featured_content_settings['tag-id'] = $new_term_id; + update_option( 'featured-content', $featured_content_settings ); + } } } - public static function jetpack_update_featured_content_for_split_terms( $old_term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) { - $featured_content_settings = get_option( 'featured-content', array() ); + Featured_Content::setup(); - // Check to see whether the stored tag ID is the one that's just been split. - if ( isset( $featured_content_settings['tag-id'] ) && $old_term_id == $featured_content_settings['tag-id'] && 'post_tag' == $taxonomy ) { - // We have a match, so we swap out the old tag ID for the new one and resave the option. - $featured_content_settings['tag-id'] = $new_term_id; - update_option( 'featured-content', $featured_content_settings ); - } + /** + * Adds the featured content plugin to the set of files for which action + * handlers should be copied when the theme context is loaded by the REST API. + * + * @param array $copy_dirs Copy paths with actions to be copied + * @return array Copy paths with featured content plugin + */ + function wpcom_rest_api_featured_content_copy_plugin_actions( $copy_dirs ) { + $copy_dirs[] = __FILE__; + return $copy_dirs; } -} - -Featured_Content::setup(); - -/** - * Adds the featured content plugin to the set of files for which action - * handlers should be copied when the theme context is loaded by the REST API. - * - * @param array $copy_dirs Copy paths with actions to be copied - * @return array Copy paths with featured content plugin - */ -function wpcom_rest_api_featured_content_copy_plugin_actions( $copy_dirs ) { - $copy_dirs[] = __FILE__; - return $copy_dirs; -} -add_action( 'restapi_theme_action_copy_dirs', 'wpcom_rest_api_featured_content_copy_plugin_actions' ); + add_action( 'restapi_theme_action_copy_dirs', 'wpcom_rest_api_featured_content_copy_plugin_actions' ); } // end if ( ! class_exists( 'Featured_Content' ) && isset( $GLOBALS['pagenow'] ) && 'plugins.php' !== $GLOBALS['pagenow'] ) { diff --git a/plugins/jetpack/modules/theme-tools/infinite-scroll.php b/plugins/jetpack/modules/theme-tools/infinite-scroll.php index 4b036fff..ac5a0aa8 100644 --- a/plugins/jetpack/modules/theme-tools/infinite-scroll.php +++ b/plugins/jetpack/modules/theme-tools/infinite-scroll.php @@ -1,7 +1,7 @@ <?php /** -* INFINITE SCROLL -*/ + * INFINITE SCROLL + */ /** * Load theme's infinite scroll annotation file, if present in the IS plugin. @@ -17,31 +17,33 @@ function jetpack_load_infinite_scroll_annotation() { if ( is_admin() && isset( $_GET['page'] ) && 'jetpack' == $_GET['page'] ) { $theme = wp_get_theme(); - if ( ! is_a( $theme, 'WP_Theme' ) && ! is_array( $theme ) ) + if ( ! is_a( $theme, 'WP_Theme' ) && ! is_array( $theme ) ) { return; + } /** This filter is already documented in modules/infinite-scroll/infinity.php */ $customization_file = apply_filters( 'infinite_scroll_customization_file', dirname( __FILE__ ) . "/infinite-scroll/themes/{$theme['Stylesheet']}.php", $theme['Stylesheet'] ); if ( is_readable( $customization_file ) ) { - require_once( $customization_file ); + require_once $customization_file; } elseif ( ! empty( $theme['Template'] ) ) { $customization_file = dirname( __FILE__ ) . "/infinite-scroll/themes/{$theme['Template']}.php"; - if ( is_readable( $customization_file ) ) - require_once( $customization_file ); + if ( is_readable( $customization_file ) ) { + require_once $customization_file; + } } } } add_action( 'setup_theme', 'jetpack_load_infinite_scroll_annotation' ); /** -* Prevent IS from being activated if theme doesn't support it -* -* @param bool $can_activate -* @filter jetpack_can_activate_infinite-scroll -* @return bool -*/ + * Prevent IS from being activated if theme doesn't support it + * + * @param bool $can_activate + * @filter jetpack_can_activate_infinite-scroll + * @return bool + */ function jetpack_can_activate_infinite_scroll() { return (bool) current_theme_supports( 'infinite-scroll' ); } diff --git a/plugins/jetpack/modules/theme-tools/random-redirect.php b/plugins/jetpack/modules/theme-tools/random-redirect.php index 78c8f349..d866d336 100644 --- a/plugins/jetpack/modules/theme-tools/random-redirect.php +++ b/plugins/jetpack/modules/theme-tools/random-redirect.php @@ -12,8 +12,10 @@ function jetpack_matt_random_redirect() { // Verify that the Random Redirect plugin this code is from is not active // See http://plugins.trac.wordpress.org/ticket/1898 if ( ! ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ) { - require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); - if ( is_plugin_active( 'random-redirect/random-redirect.php' ) ) return; + require_once ABSPATH . 'wp-admin/includes/plugin.php'; + if ( is_plugin_active( 'random-redirect/random-redirect.php' ) ) { + return; + } } // Set default post type. @@ -29,31 +31,36 @@ function jetpack_matt_random_redirect() { // Set author name if we're on an author archive. if ( is_author() ) { - $random_author_name = get_the_author_meta( 'user_login' ); + $random_author_name = get_the_author_meta( 'user_login' ); $random_author_query = 'AND user_login = "' . $random_author_name . '"'; } else { $random_author_query = ''; } // Acceptable URL formats: /[...]/?random=[post type], /?random, /&random, /&random=1 - if ( ! isset( $_GET['random'] ) && ! in_array( strtolower( $_SERVER['REQUEST_URI'] ), array( '/&random', '/&random=1' ) ) ) + if ( ! isset( $_GET['random'] ) && ! in_array( strtolower( $_SERVER['REQUEST_URI'] ), array( '/&random', '/&random=1' ) ) ) { return; + } // Ignore POST requests. - if ( ! empty( $_POST ) ) + if ( ! empty( $_POST ) ) { return; + } // Persistent AppEngine abuse. ORDER BY RAND is expensive. - if ( strstr( $_SERVER['HTTP_USER_AGENT'], 'AppEngine-Google' ) ) + if ( strstr( $_SERVER['HTTP_USER_AGENT'], 'AppEngine-Google' ) ) { wp_die( 'Please <a href="http://en.support.wordpress.com/contact/" rel="noopener noreferrer" target="_blank">contact support</a>' ); + } // Set the category ID if the parameter is set. - if ( isset( $_GET['random_cat_id'] ) ) + if ( isset( $_GET['random_cat_id'] ) ) { $random_cat_id = (int) $_GET['random_cat_id']; + } // Change the post type if the parameter is set. - if ( isset( $_GET['random_post_type'] ) && post_type_exists( $_GET['random_post_type'] ) ) + if ( isset( $_GET['random_post_type'] ) && post_type_exists( $_GET['random_post_type'] ) ) { $post_type = $_GET['random_post_type']; + } // Don't show a random page if 'page' isn't specified as the post type specifically. if ( 'page' === $post_type && is_front_page() && ! isset( $_GET['random_post_type'] ) ) { diff --git a/plugins/jetpack/modules/theme-tools/responsive-videos.php b/plugins/jetpack/modules/theme-tools/responsive-videos.php index eb97130e..c4eacf46 100644 --- a/plugins/jetpack/modules/theme-tools/responsive-videos.php +++ b/plugins/jetpack/modules/theme-tools/responsive-videos.php @@ -12,10 +12,10 @@ function jetpack_responsive_videos_init() { /* If the theme does support 'jetpack-responsive-videos', wrap the videos */ add_filter( 'wp_video_shortcode', 'jetpack_responsive_videos_embed_html' ); - add_filter( 'video_embed_html', 'jetpack_responsive_videos_embed_html' ); + add_filter( 'video_embed_html', 'jetpack_responsive_videos_embed_html' ); /* Only wrap oEmbeds if video */ - add_filter( 'embed_oembed_html', 'jetpack_responsive_videos_maybe_wrap_oembed', 10, 2 ); + add_filter( 'embed_oembed_html', 'jetpack_responsive_videos_maybe_wrap_oembed', 10, 2 ); add_filter( 'embed_handler_html', 'jetpack_responsive_videos_maybe_wrap_oembed', 10, 2 ); /* Wrap videos in Buddypress */ @@ -61,11 +61,11 @@ function jetpack_responsive_videos_embed_html( $html ) { } /** - * Check if oEmbed is YouTube or Vimeo before wrapping. + * Check if oEmbed is a `$video_patterns` provider video before wrapping. * * @return string */ -function jetpack_responsive_videos_maybe_wrap_oembed( $html, $url ) { +function jetpack_responsive_videos_maybe_wrap_oembed( $html, $url = null ) { if ( empty( $html ) || ! is_string( $html ) || ! $url ) { return $html; } @@ -90,20 +90,23 @@ function jetpack_responsive_videos_maybe_wrap_oembed( $html, $url ) { * * @param array $video_patterns oEmbed video provider Regex patterns. */ - $video_patterns = apply_filters( 'jetpack_responsive_videos_oembed_videos', array( - 'https?://((m|www)\.)?youtube\.com/watch', - 'https?://((m|www)\.)?youtube\.com/playlist', - 'https?://youtu\.be/', - 'https?://(.+\.)?vimeo\.com/', - 'https?://(www\.)?dailymotion\.com/', - 'https?://dai.ly/', - 'https?://(www\.)?hulu\.com/watch/', - 'https?://wordpress.tv/', - 'https?://(www\.)?funnyordie\.com/videos/', - 'https?://vine.co/v/', - 'https?://(www\.)?collegehumor\.com/video/', - 'https?://(www\.|embed\.)?ted\.com/talks/' - ) ); + $video_patterns = apply_filters( + 'jetpack_responsive_videos_oembed_videos', + array( + 'https?://((m|www)\.)?youtube\.com/watch', + 'https?://((m|www)\.)?youtube\.com/playlist', + 'https?://youtu\.be/', + 'https?://(.+\.)?vimeo\.com/', + 'https?://(www\.)?dailymotion\.com/', + 'https?://dai.ly/', + 'https?://(www\.)?hulu\.com/watch/', + 'https?://wordpress.tv/', + 'https?://(www\.)?funnyordie\.com/videos/', + 'https?://vine.co/v/', + 'https?://(www\.)?collegehumor\.com/video/', + 'https?://(www\.|embed\.)?ted\.com/talks/', + ) + ); // Merge patterns to run in a single preg_match call. $video_patterns = '(' . implode( '|', $video_patterns ) . ')'; diff --git a/plugins/jetpack/modules/theme-tools/site-breadcrumbs.php b/plugins/jetpack/modules/theme-tools/site-breadcrumbs.php index 47088ff0..2f266738 100644 --- a/plugins/jetpack/modules/theme-tools/site-breadcrumbs.php +++ b/plugins/jetpack/modules/theme-tools/site-breadcrumbs.php @@ -10,10 +10,10 @@ */ function jetpack_breadcrumbs() { - $taxonomy = is_category() ? 'category' : get_query_var( 'taxonomy' ); + $taxonomy = is_category() ? 'category' : get_query_var( 'taxonomy' ); $is_taxonomy_hierarchical = is_taxonomy_hierarchical( $taxonomy ); - $post_type = is_page() ? 'page' : get_query_var( 'post_type' ); + $post_type = is_page() ? 'page' : get_query_var( 'post_type' ); $is_post_type_hierarchical = is_post_type_hierarchical( $post_type ); if ( ! ( $is_post_type_hierarchical || $is_taxonomy_hierarchical ) || is_front_page() ) { @@ -23,7 +23,7 @@ function jetpack_breadcrumbs() { $breadcrumb = ''; if ( $is_post_type_hierarchical ) { - $post_id = get_queried_object_id(); + $post_id = get_queried_object_id(); $ancestors = array_reverse( get_post_ancestors( $post_id ) ); if ( $ancestors ) { foreach ( $ancestors as $ancestor ) { @@ -53,9 +53,9 @@ function jetpack_breadcrumbs() { /** * Return the parents for a given taxonomy term ID. * - * @param int $term Taxonomy term whose parents will be returned. + * @param int $term Taxonomy term whose parents will be returned. * @param string $taxonomy Taxonomy name that the term belongs to. - * @param array $visited Terms already added to prevent duplicates. + * @param array $visited Terms already added to prevent duplicates. * * @return string A list of links to the term parents. */ @@ -70,7 +70,7 @@ function jetpack_get_term_parents( $term, $taxonomy, $visited = array() ) { if ( $parent->parent && ( $parent->parent != $parent->term_id ) && ! in_array( $parent->parent, $visited ) ) { $visited[] = $parent->parent; - $chain .= jetpack_get_term_parents( $parent->parent, $taxonomy, $visited ); + $chain .= jetpack_get_term_parents( $parent->parent, $taxonomy, $visited ); } $chain .= '<a href="' . esc_url( get_category_link( $parent->term_id ) ) . '">' . $parent->name . '</a>'; diff --git a/plugins/jetpack/modules/theme-tools/site-logo.php b/plugins/jetpack/modules/theme-tools/site-logo.php index d6510c2b..04f16b71 100644 --- a/plugins/jetpack/modules/theme-tools/site-logo.php +++ b/plugins/jetpack/modules/theme-tools/site-logo.php @@ -34,13 +34,13 @@ function site_logo_init() { // Only load our code if our theme declares support, and the standalone plugin is not activated. if ( current_theme_supports( 'site-logo' ) && ! class_exists( 'Site_Logo', false ) ) { // Load our class for namespacing. - require( dirname( __FILE__ ) . '/site-logo/inc/class-site-logo.php' ); + require dirname( __FILE__ ) . '/site-logo/inc/class-site-logo.php'; // Load template tags. - require( dirname( __FILE__ ) . '/site-logo/inc/functions.php' ); + require dirname( __FILE__ ) . '/site-logo/inc/functions.php'; // Load backwards-compatible template tags. - require( dirname( __FILE__ ) . '/site-logo/inc/compat.php' ); + require dirname( __FILE__ ) . '/site-logo/inc/compat.php'; } } add_action( 'init', 'site_logo_init' ); diff --git a/plugins/jetpack/modules/theme-tools/site-logo/inc/class-site-logo-control.php b/plugins/jetpack/modules/theme-tools/site-logo/inc/class-site-logo-control.php index c43c0211..5e23507d 100644 --- a/plugins/jetpack/modules/theme-tools/site-logo/inc/class-site-logo-control.php +++ b/plugins/jetpack/modules/theme-tools/site-logo/inc/class-site-logo-control.php @@ -10,17 +10,17 @@ class Site_Logo_Image_Control extends WP_Customize_Control { * * @param object $wp_customize * @param string $control_id - * @param array $args + * @param array $args * @uses Site_Logo_Image_Control::l10n() */ public function __construct( $wp_customize, $control_id, $args = array() ) { // declare these first so they can be overridden $this->l10n = array( - 'upload' => __( 'Add logo', 'jetpack' ), - 'set' => __( 'Set as logo', 'jetpack' ), - 'choose' => __( 'Choose logo', 'jetpack' ), - 'change' => __( 'Change logo', 'jetpack' ), - 'remove' => __( 'Remove logo', 'jetpack' ), + 'upload' => __( 'Add logo', 'jetpack' ), + 'set' => __( 'Set as logo', 'jetpack' ), + 'choose' => __( 'Choose logo', 'jetpack' ), + 'change' => __( 'Change logo', 'jetpack' ), + 'remove' => __( 'Remove logo', 'jetpack' ), 'placeholder' => __( 'No logo set', 'jetpack' ), ); @@ -104,5 +104,6 @@ class Site_Logo_Image_Control extends WP_Customize_Control { <div class="current"></div> <div class="actions"></div> - <?php } + <?php + } } diff --git a/plugins/jetpack/modules/theme-tools/site-logo/inc/class-site-logo.php b/plugins/jetpack/modules/theme-tools/site-logo/inc/class-site-logo.php index 728a1548..75fe80b1 100644 --- a/plugins/jetpack/modules/theme-tools/site-logo/inc/class-site-logo.php +++ b/plugins/jetpack/modules/theme-tools/site-logo/inc/class-site-logo.php @@ -23,7 +23,7 @@ class Site_Logo { */ public static function instance() { if ( ! isset( self::$instance ) ) { - self::$instance = new Site_Logo; + self::$instance = new Site_Logo(); self::$instance->register_hooks(); } @@ -77,46 +77,61 @@ class Site_Logo { */ public function customize_register( $wp_customize ) { // Include our custom control. - require( dirname( __FILE__ ) . '/class-site-logo-control.php' ); - - //Update the Customizer section title for discoverability. - $wp_customize->get_section('title_tagline')->title = __( 'Site Title, Tagline, and Logo', 'jetpack' ); + require dirname( __FILE__ ) . '/class-site-logo-control.php'; // Add a setting to hide header text if the theme isn't supporting the feature itself if ( ! current_theme_supports( 'custom-header' ) ) { - $wp_customize->add_setting( 'site_logo_header_text', array( - 'default' => 1, - 'sanitize_callback' => array( $this, 'sanitize_checkbox' ), - 'transport' => 'postMessage', - ) ); - - $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'site_logo_header_text', array( - 'label' => __( 'Display Header Text', 'jetpack' ), - 'section' => 'title_tagline', - 'settings' => 'site_logo_header_text', - 'type' => 'checkbox', - ) ) ); + $wp_customize->add_setting( + 'site_logo_header_text', + array( + 'default' => 1, + 'sanitize_callback' => array( $this, 'sanitize_checkbox' ), + 'transport' => 'postMessage', + ) + ); + + $wp_customize->add_control( + new WP_Customize_Control( + $wp_customize, + 'site_logo_header_text', + array( + 'label' => __( 'Display Header Text', 'jetpack' ), + 'section' => 'title_tagline', + 'settings' => 'site_logo_header_text', + 'type' => 'checkbox', + ) + ) + ); } // Add the setting for our logo value. - $wp_customize->add_setting( 'site_logo', array( - 'capability' => 'manage_options', - 'default' => array( - 'id' => 0, - 'sizes' => array(), - 'url' => false, - ), - 'sanitize_callback' => array( $this, 'sanitize_logo_setting' ), - 'transport' => 'postMessage', - 'type' => 'option', - ) ); + $wp_customize->add_setting( + 'site_logo', + array( + 'capability' => 'manage_options', + 'default' => array( + 'id' => 0, + 'sizes' => array(), + 'url' => false, + ), + 'sanitize_callback' => array( $this, 'sanitize_logo_setting' ), + 'transport' => 'postMessage', + 'type' => 'option', + ) + ); // Add our image uploader. - $wp_customize->add_control( new Site_Logo_Image_Control( $wp_customize, 'site_logo', array( - 'label' => __( 'Logo', 'jetpack' ), - 'section' => 'title_tagline', - 'settings' => 'site_logo', - ) ) ); + $wp_customize->add_control( + new Site_Logo_Image_Control( + $wp_customize, + 'site_logo', + array( + 'label' => __( 'Logo', 'jetpack' ), + 'section' => 'title_tagline', + 'settings' => 'site_logo', + ) + ) + ); } /** @@ -148,9 +163,9 @@ class Site_Logo { public function header_text_classes() { $args = get_theme_support( 'site-logo' ); - if ( isset( $args[0][ 'header-text' ] ) ) { + if ( isset( $args[0]['header-text'] ) ) { // Use any classes defined in add_theme_support(). - $classes = $args[0][ 'header-text' ]; + $classes = $args[0]['header-text']; } else { // Otherwise, use these defaults, which will work with any Underscores-based theme. $classes = array( @@ -205,7 +220,7 @@ class Site_Logo { * @return string Size specified in add_theme_support declaration, or 'thumbnail' default */ public function theme_size() { - $args = get_theme_support( 'site-logo' ); + $args = get_theme_support( 'site-logo' ); $valid_sizes = get_intermediate_image_sizes(); // Add 'full' to the list of accepted values. @@ -288,11 +303,14 @@ class Site_Logo { * @uses update_option() */ public function remove_site_logo() { - update_option( 'site_logo', array( - 'id' => (int) 0, - 'sizes' => array(), - 'url' => '', - ) ); + update_option( + 'site_logo', + array( + 'id' => (int) 0, + 'sizes' => array(), + 'url' => '', + ) + ); } /** diff --git a/plugins/jetpack/modules/theme-tools/site-logo/inc/compat.php b/plugins/jetpack/modules/theme-tools/site-logo/inc/compat.php index c51ac3aa..d1098536 100644 --- a/plugins/jetpack/modules/theme-tools/site-logo/inc/compat.php +++ b/plugins/jetpack/modules/theme-tools/site-logo/inc/compat.php @@ -8,37 +8,37 @@ */ if ( ! function_exists( 'the_site_logo' ) ) : -/** - * Unprefixed, backwards-compatible function for outputting the site logo. - * - * @uses jetpack_the_site_logo() - */ -function the_site_logo() { - jetpack_the_site_logo(); -} + /** + * Unprefixed, backwards-compatible function for outputting the site logo. + * + * @uses jetpack_the_site_logo() + */ + function the_site_logo() { + jetpack_the_site_logo(); + } endif; if ( ! function_exists( 'has_site_logo' ) ) : -/** - * Unprefixed, backwards-compatible function for determining if a site logo has been set. - * - * @uses jetpack_has_site_logo() - * @return bool True if a site logo is set, false otherwise. - */ -function has_site_logo() { - return jetpack_has_site_logo(); -} + /** + * Unprefixed, backwards-compatible function for determining if a site logo has been set. + * + * @uses jetpack_has_site_logo() + * @return bool True if a site logo is set, false otherwise. + */ + function has_site_logo() { + return jetpack_has_site_logo(); + } endif; if ( ! function_exists( 'get_site_logo' ) ) : -/** - * Unprefixed, backwards-compatible function for getting either the site logo's image URL or its ID. - * - * @param string $show Return the site logo URL or ID. - * @uses jetpack_get_site_logo() - * @return string Site logo ID or URL (the default). - */ -function get_site_logo( $show = 'url' ) { - return jetpack_get_site_logo( $show ); -} + /** + * Unprefixed, backwards-compatible function for getting either the site logo's image URL or its ID. + * + * @param string $show Return the site logo URL or ID. + * @uses jetpack_get_site_logo() + * @return string Site logo ID or URL (the default). + */ + function get_site_logo( $show = 'url' ) { + return jetpack_get_site_logo( $show ); + } endif; diff --git a/plugins/jetpack/modules/theme-tools/site-logo/inc/functions.php b/plugins/jetpack/modules/theme-tools/site-logo/inc/functions.php index 12817e5f..3b27b32f 100644 --- a/plugins/jetpack/modules/theme-tools/site-logo/inc/functions.php +++ b/plugins/jetpack/modules/theme-tools/site-logo/inc/functions.php @@ -41,10 +41,10 @@ function jetpack_get_site_logo( $show = 'url' ) { * @since 3.6.0 * * @return array $dimensions { - * An array of dimensions of the Site Logo. + * An array of dimensions of the Site Logo. * - * @type string $width Width of the logo in pixels. - * @type string $height Height of the logo in pixels. + * @type string $width Width of the logo in pixels. + * @type string $height Height of the logo in pixels. * } */ function jetpack_get_site_logo_dimensions() { @@ -54,8 +54,8 @@ function jetpack_get_site_logo_dimensions() { // If the size is the default `thumbnail`, get its dimensions. Otherwise, get them from $_wp_additional_image_sizes if ( empty( $size ) ) { return false; - } else if ( 'thumbnail' == $size ) { - $dimensions = array( + } elseif ( 'thumbnail' == $size ) { + $dimensions = array( 'width' => get_option( 'thumbnail_size_w' ), 'height' => get_option( 'thumbnail_size_h' ), ); @@ -66,9 +66,9 @@ function jetpack_get_site_logo_dimensions() { return false; } - $dimensions = array( - 'width' => $_wp_additional_image_sizes[ $size ][ 'width' ], - 'height' => $_wp_additional_image_sizes[ $size ][ 'height' ], + $dimensions = array( + 'width' => $_wp_additional_image_sizes[ $size ]['width'], + 'height' => $_wp_additional_image_sizes[ $size ]['height'], ); } @@ -101,16 +101,17 @@ function jetpack_has_site_logo() { * @since 1.0 */ function jetpack_the_site_logo() { - $logo = site_logo()->logo; + $logo = site_logo()->logo; $logo_id = get_theme_mod( 'custom_logo' ); // Check for WP 4.5 Site Logo $logo_id = $logo_id ? $logo_id : $logo['id']; // Use WP Core logo if present, otherwise use Jetpack's. - $size = site_logo()->theme_size(); - $html = ''; + $size = site_logo()->theme_size(); + $html = ''; // If no logo is set, but we're in the Customizer, leave a placeholder (needed for the live preview). if ( ! jetpack_has_site_logo() ) { if ( jetpack_is_customize_preview() ) { - $html = sprintf( '<a href="%1$s" class="site-logo-link" style="display:none;"><img class="site-logo" data-size="%2$s" /></a>', + $html = sprintf( + '<a href="%1$s" class="site-logo-link" style="display:none;"><img class="site-logo" data-size="%2$s" /></a>', esc_url( home_url( '/' ) ), esc_attr( $size ) ); @@ -119,7 +120,8 @@ function jetpack_the_site_logo() { // We have a logo. Logo is go. else { - $html = sprintf( '<a href="%1$s" class="site-logo-link" rel="home" itemprop="url">%2$s</a>', + $html = sprintf( + '<a href="%1$s" class="site-logo-link" rel="home" itemprop="url">%2$s</a>', esc_url( home_url( '/' ) ), wp_get_attachment_image( $logo_id, @@ -128,7 +130,7 @@ function jetpack_the_site_logo() { array( 'class' => "site-logo attachment-$size", 'data-size' => $size, - 'itemprop' => "logo" + 'itemprop' => 'logo', ) ) ); diff --git a/plugins/jetpack/modules/theme-tools/social-links.php b/plugins/jetpack/modules/theme-tools/social-links.php index 8b38814a..44b2cbc8 100644 --- a/plugins/jetpack/modules/theme-tools/social-links.php +++ b/plugins/jetpack/modules/theme-tools/social-links.php @@ -20,220 +20,233 @@ add_action( 'init', 'jetpack_theme_supports_social_links', 30 ); if ( ! class_exists( 'Social_Links' ) ) { -class Social_Links { - - /** - * The links the user set for each service. - * - * @var array - */ - private $links; - - /** - * A Publicize object. - * - * @var Publicize - */ - private $publicize; - - /** - * An array with all services that are supported by both Publicize and the - * currently active theme. - * - * @var array - */ - private $services = array(); - - /** - * An array of the services the theme supports - * - * @var array - */ - private $theme_supported_services = array(); - - /** - * Constructor. - */ - public function __construct() { - $theme_support = get_theme_support( 'social-links' ); - - /* An array of named arguments must be passed as the second parameter - * of add_theme_support(). + class Social_Links { + + /** + * The links the user set for each service. + * + * @var array */ - if ( empty( $theme_support[0] ) ) - return; + private $links; - $this->theme_supported_services = $theme_support[0]; - $this->links = Jetpack_Options::get_option( 'social_links', array() ); + /** + * A Publicize object. + * + * @var Publicize + */ + private $publicize; - $this->admin_setup(); + /** + * An array with all services that are supported by both Publicize and the + * currently active theme. + * + * @var array + */ + private $services = array(); - add_filter( 'jetpack_has_social_links', array( $this, 'has_social_links' ) ); - add_filter( 'jetpack_get_social_links', array( $this, 'get_social_links' ) ); + /** + * An array of the services the theme supports + * + * @var array + */ + private $theme_supported_services = array(); - foreach ( $theme_support[0] as $service ) { - add_filter( "pre_option_jetpack-$service", array( $this, 'get_social_link_filter' ) ); // get_option( 'jetpack-service' ); - add_filter( "theme_mod_jetpack-$service", array( $this, 'get_social_link_filter' ) ); // get_theme_mod( 'jetpack-service' ); - } - } + /** + * Constructor. + */ + public function __construct() { + $theme_support = get_theme_support( 'social-links' ); + + /* + An array of named arguments must be passed as the second parameter + * of add_theme_support(). + */ + if ( empty( $theme_support[0] ) ) { + return; + } + + $this->theme_supported_services = $theme_support[0]; + $this->links = Jetpack_Options::get_option( 'social_links', array() ); + + $this->admin_setup(); - public function admin_setup() { - if ( ! current_user_can( 'manage_options' ) ) { - return; + add_filter( 'jetpack_has_social_links', array( $this, 'has_social_links' ) ); + add_filter( 'jetpack_get_social_links', array( $this, 'get_social_links' ) ); + + foreach ( $theme_support[0] as $service ) { + add_filter( "pre_option_jetpack-$service", array( $this, 'get_social_link_filter' ) ); // get_option( 'jetpack-service' ); + add_filter( "theme_mod_jetpack-$service", array( $this, 'get_social_link_filter' ) ); // get_theme_mod( 'jetpack-service' ); + } } - if ( ! is_admin() && ! $this->is_customize_preview() ) { - return; + public function admin_setup() { + if ( ! current_user_can( 'manage_options' ) ) { + return; + } + + if ( ! is_admin() && ! $this->is_customize_preview() ) { + return; + } + + $this->publicize = publicize_init(); + $publicize_services = $this->publicize->get_services( 'connected' ); + $this->services = array_intersect( array_keys( $publicize_services ), $this->theme_supported_services ); + + add_action( 'publicize_connected', array( $this, 'check_links' ), 20 ); + add_action( 'publicize_disconnected', array( $this, 'check_links' ), 20 ); + add_action( 'customize_register', array( $this, 'customize_register' ) ); + add_filter( 'sanitize_option_jetpack_options', array( $this, 'sanitize_link' ) ); } - $this->publicize = publicize_init(); - $publicize_services = $this->publicize->get_services( 'connected' ); - $this->services = array_intersect( array_keys( $publicize_services ), $this->theme_supported_services ); + /** + * Compares the currently saved links with the connected services and removes + * links from services that are no longer connected. + * + * @return void + */ + public function check_links() { + $active_links = array_intersect_key( $this->links, array_flip( $this->services ) ); - add_action( 'publicize_connected', array( $this, 'check_links' ), 20 ); - add_action( 'publicize_disconnected', array( $this, 'check_links' ), 20 ); - add_action( 'customize_register', array( $this, 'customize_register' ) ); - add_filter( 'sanitize_option_jetpack_options', array( $this, 'sanitize_link' ) ); - } + if ( $active_links !== $this->links ) { + $this->links = $active_links; + Jetpack_Options::update_option( 'social_links', $active_links ); + } + } + + /** + * Add social link dropdown to the Customizer. + * + * @param WP_Customize_Manager $wp_customize Theme Customizer object. + */ + public function customize_register( $wp_customize ) { + $wp_customize->add_section( + 'jetpack_social_links', + array( + 'title' => esc_html__( 'Connect', 'jetpack' ), + 'priority' => 35, + ) + ); + + foreach ( array_keys( $this->publicize->get_services( 'all' ) ) as $service ) { + $choices = $this->get_customize_select( $service ); + + if ( empty( $choices ) ) { + continue; + } - /** - * Compares the currently saved links with the connected services and removes - * links from services that are no longer connected. - * - * @return void - */ - public function check_links() { - $active_links = array_intersect_key( $this->links, array_flip( $this->services ) ); - - if ( $active_links !== $this->links ) { - $this->links = $active_links; - Jetpack_Options::update_option( 'social_links', $active_links ); + $wp_customize->add_setting( + "jetpack_options[social_links][$service]", + array( + 'type' => 'option', + 'default' => '', + ) + ); + + $wp_customize->add_control( + "jetpack-$service", + array( + 'label' => $this->publicize->get_service_label( $service ), + 'section' => 'jetpack_social_links', + 'settings' => "jetpack_options[social_links][$service]", + 'type' => 'select', + 'choices' => $choices, + ) + ); + } } - } - /** - * Add social link dropdown to the Customizer. - * - * @param WP_Customize_Manager $wp_customize Theme Customizer object. - */ - public function customize_register( $wp_customize ) { - $wp_customize->add_section( 'jetpack_social_links', array( - 'title' => esc_html__( 'Connect', 'jetpack' ), - 'priority' => 35, - ) ); - - foreach ( array_keys( $this->publicize->get_services( 'all' ) ) as $service ) { - $choices = $this->get_customize_select( $service ); - - if ( empty( $choices ) ) { - continue; + /** + * Sanitizes social links. + * + * @param array $option The incoming values to be sanitized. + * @returns array + */ + public function sanitize_link( $option ) { + foreach ( $this->services as $service ) { + if ( ! empty( $option['social_links'][ $service ] ) ) { + $option['social_links'][ $service ] = esc_url_raw( $option['social_links'][ $service ] ); + } else { + unset( $option['social_links'][ $service ] ); + } } - $wp_customize->add_setting( "jetpack_options[social_links][$service]", array( - 'type' => 'option', - 'default' => '', - ) ); - - $wp_customize->add_control( "jetpack-$service", array( - 'label' => $this->publicize->get_service_label( $service ), - 'section' => 'jetpack_social_links', - 'settings' => "jetpack_options[social_links][$service]", - 'type' => 'select', - 'choices' => $choices, - ) ); + return $option; } - } - /** - * Sanitizes social links. - * - * @param array $option The incoming values to be sanitized. - * @returns array - */ - public function sanitize_link( $option ) { - foreach ( $this->services as $service ) { - if ( ! empty( $option['social_links'][ $service ] ) ) - $option['social_links'][ $service ] = esc_url_raw( $option['social_links'][ $service ] ); - else - unset( $option['social_links'][ $service ] ); + /** + * Returns whether there are any social links set. + * + * @returns bool + */ + public function has_social_links() { + return ! empty( $this->links ); } - return $option; - } + /** + * Return available social links. + * + * @returns array + */ + public function get_social_links() { + return $this->links; + } - /** - * Returns whether there are any social links set. - * - * @returns bool - */ - public function has_social_links() { - return ! empty( $this->links ); - } + /** + * Short-circuits get_option and get_theme_mod calls. + * + * @param string $link The incoming value to be replaced. + * @returns string $link The social link that we've got. + */ + public function get_social_link_filter( $link ) { + if ( preg_match( '/_jetpack-(.+)$/i', current_filter(), $matches ) && ! empty( $this->links[ $matches[1] ] ) ) { + return $this->links[ $matches[1] ]; + } - /** - * Return available social links. - * - * @returns array - */ - public function get_social_links() { - return $this->links; - } + return $link; + } - /** - * Short-circuits get_option and get_theme_mod calls. - * - * @param string $link The incoming value to be replaced. - * @returns string $link The social link that we've got. - */ - public function get_social_link_filter( $link ) { - if ( preg_match( '/_jetpack-(.+)$/i', current_filter(), $matches ) && ! empty( $this->links[ $matches[1] ] ) ) - return $this->links[ $matches[1] ]; - - return $link; - } + /** + * Puts together an array of choices for a specific service. + * + * @param string $service The social service. + * @return array An associative array with profile links and display names. + */ + private function get_customize_select( $service ) { + $choices = array( + '' => __( '— Select —', 'jetpack' ), + ); - /** - * Puts together an array of choices for a specific service. - * - * @param string $service The social service. - * @return array An associative array with profile links and display names. - */ - private function get_customize_select( $service ) { - $choices = array( - '' => __( '— Select —', 'jetpack' ) - ); - - if ( isset( $this->links[ $service ] ) ) { - $choices[ $this->links[ $service ] ] = $this->links[ $service ]; - } + if ( isset( $this->links[ $service ] ) ) { + $choices[ $this->links[ $service ] ] = $this->links[ $service ]; + } - $connected_services = $this->publicize->get_services( 'connected' ); - if ( isset( $connected_services[ $service ] ) ) { - foreach ( $connected_services[ $service ] as $c ) { - $profile_link = $this->publicize->get_profile_link( $service, $c ); + $connected_services = $this->publicize->get_services( 'connected' ); + if ( isset( $connected_services[ $service ] ) ) { + foreach ( $connected_services[ $service ] as $c ) { + $profile_link = $this->publicize->get_profile_link( $service, $c ); - if ( false === $profile_link ) { - continue; + if ( false === $profile_link ) { + continue; + } + + $choices[ $profile_link ] = $this->publicize->get_display_name( $service, $c ); } + } - $choices[ $profile_link ] = $this->publicize->get_display_name( $service, $c ); + if ( 1 === count( $choices ) ) { + return array(); } - } - if ( 1 === count( $choices ) ) { - return array(); + return $choices; } - return $choices; - } - - /** - * Back-compat function for versions prior to 4.0. - */ - private function is_customize_preview() { - global $wp_customize; - return is_a( $wp_customize, 'WP_Customize_Manager' ) && $wp_customize->is_preview(); + /** + * Back-compat function for versions prior to 4.0. + */ + private function is_customize_preview() { + global $wp_customize; + return is_a( $wp_customize, 'WP_Customize_Manager' ) && $wp_customize->is_preview(); + } } -} } // end if ( ! class_exists( 'Social_Links' ) diff --git a/plugins/jetpack/modules/theme-tools/social-menu.php b/plugins/jetpack/modules/theme-tools/social-menu.php index feb7fada..16c66b6a 100644 --- a/plugins/jetpack/modules/theme-tools/social-menu.php +++ b/plugins/jetpack/modules/theme-tools/social-menu.php @@ -34,16 +34,18 @@ function jetpack_social_menu_init() { $social_menu_description = apply_filters( 'jetpack_social_menu_description', __( 'Social Menu', 'jetpack' ) ); // Register a new menu location - register_nav_menus( array( - 'jetpack-social-menu' => esc_html( $social_menu_description ), - ) ); + register_nav_menus( + array( + 'jetpack-social-menu' => esc_html( $social_menu_description ), + ) + ); // Enqueue CSS add_action( 'wp_enqueue_scripts', 'jetpack_social_menu_style' ); // Load SVG icons related functions and filters if ( 'svg' === jetpack_social_menu_get_type() ) { - require( dirname( __FILE__ ) . '/social-menu/icon-functions.php' ); + require dirname( __FILE__ ) . '/social-menu/icon-functions.php'; } } add_action( 'after_setup_theme', 'jetpack_social_menu_init', 99 ); @@ -96,13 +98,16 @@ function jetpack_social_menu() { } ?> <nav class="jetpack-social-navigation jetpack-social-navigation-<?php echo esc_attr( $menu_type ); ?>" role="navigation" aria-label="<?php esc_html_e( 'Social Links Menu', 'jetpack' ); ?>"> <?php - wp_nav_menu( array( - 'theme_location' => 'jetpack-social-menu', - 'link_before' => '<span class="screen-reader-text">', - 'link_after' => $link_after, - 'depth' => 1, - ) ); + wp_nav_menu( + array( + 'theme_location' => 'jetpack-social-menu', + 'link_before' => '<span class="screen-reader-text">', + 'link_after' => $link_after, + 'depth' => 1, + ) + ); ?> </nav><!-- .jetpack-social-navigation --> - <?php endif; + <?php + endif; } diff --git a/plugins/jetpack/modules/theme-tools/social-menu/icon-functions.php b/plugins/jetpack/modules/theme-tools/social-menu/icon-functions.php index f19e1884..89e4f833 100644 --- a/plugins/jetpack/modules/theme-tools/social-menu/icon-functions.php +++ b/plugins/jetpack/modules/theme-tools/social-menu/icon-functions.php @@ -4,170 +4,170 @@ */ if ( ! function_exists( 'jetpack_social_menu_include_svg_icons' ) ) : -/** - * Add SVG definitions to the footer. - */ -function jetpack_social_menu_include_svg_icons() { - // Define SVG sprite file. - $svg_icons = dirname( __FILE__ ) . '/social-menu.svg'; + /** + * Add SVG definitions to the footer. + */ + function jetpack_social_menu_include_svg_icons() { + // Define SVG sprite file. + $svg_icons = dirname( __FILE__ ) . '/social-menu.svg'; - // If it exists, include it. - if ( file_exists( $svg_icons ) ) { - require_once( $svg_icons ); + // If it exists, include it. + if ( file_exists( $svg_icons ) ) { + require_once $svg_icons; + } } -} -add_action( 'wp_footer', 'jetpack_social_menu_include_svg_icons', 9999 ); + add_action( 'wp_footer', 'jetpack_social_menu_include_svg_icons', 9999 ); endif; if ( ! function_exists( 'jetpack_social_menu_get_svg' ) ) : -/** - * Return SVG markup. - * - * @param array $args { - * Parameters needed to display an SVG. - * - * @type string $icon Required SVG icon filename. - * } - * @return string SVG markup. - */ -function jetpack_social_menu_get_svg( $args = array() ) { - // Make sure $args are an array. - if ( empty( $args ) ) { - return esc_html__( 'Please define default parameters in the form of an array.', 'jetpack' ); - } - - // Define an icon. - if ( false === array_key_exists( 'icon', $args ) ) { - return esc_html__( 'Please define an SVG icon filename.', 'jetpack' ); - } - - // Set defaults. - $defaults = array( - 'icon' => '', - 'fallback' => false, - ); - - // Parse args. - $args = wp_parse_args( $args, $defaults ); - - // Set aria hidden. - $aria_hidden = ' aria-hidden="true"'; - - // Begin SVG markup. - $svg = '<svg class="icon icon-' . esc_attr( $args['icon'] ) . '"' . $aria_hidden . ' role="img">'; - - /* - * Display the icon. + /** + * Return SVG markup. * - * The whitespace around `<use>` is intentional - it is a work around to a keyboard navigation bug in Safari 10. + * @param array $args { + * Parameters needed to display an SVG. * - * See https://core.trac.wordpress.org/ticket/38387. + * @type string $icon Required SVG icon filename. + * } + * @return string SVG markup. */ - $svg .= ' <use href="#icon-' . esc_html( $args['icon'] ) . '" xlink:href="#icon-' . esc_html( $args['icon'] ) . '"></use> '; + function jetpack_social_menu_get_svg( $args = array() ) { + // Make sure $args are an array. + if ( empty( $args ) ) { + return esc_html__( 'Please define default parameters in the form of an array.', 'jetpack' ); + } - // Add some markup to use as a fallback for browsers that do not support SVGs. - if ( $args['fallback'] ) { - $svg .= '<span class="svg-fallback icon-' . esc_attr( $args['icon'] ) . '"></span>'; - } + // Define an icon. + if ( false === array_key_exists( 'icon', $args ) ) { + return esc_html__( 'Please define an SVG icon filename.', 'jetpack' ); + } + + // Set defaults. + $defaults = array( + 'icon' => '', + 'fallback' => false, + ); + + // Parse args. + $args = wp_parse_args( $args, $defaults ); + + // Set aria hidden. + $aria_hidden = ' aria-hidden="true"'; + + // Begin SVG markup. + $svg = '<svg class="icon icon-' . esc_attr( $args['icon'] ) . '"' . $aria_hidden . ' role="img">'; + + /* + * Display the icon. + * + * The whitespace around `<use>` is intentional - it is a work around to a keyboard navigation bug in Safari 10. + * + * See https://core.trac.wordpress.org/ticket/38387. + */ + $svg .= ' <use href="#icon-' . esc_html( $args['icon'] ) . '" xlink:href="#icon-' . esc_html( $args['icon'] ) . '"></use> '; + + // Add some markup to use as a fallback for browsers that do not support SVGs. + if ( $args['fallback'] ) { + $svg .= '<span class="svg-fallback icon-' . esc_attr( $args['icon'] ) . '"></span>'; + } - $svg .= '</svg>'; + $svg .= '</svg>'; - return $svg; -} + return $svg; + } endif; if ( ! function_exists( 'jetpack_social_menu_nav_menu_social_icons' ) ) : -/** - * Display SVG icons in social links menu. - * - * @param string $item_output The menu item output. - * @param WP_Post $item Menu item object. - * @param int $depth Depth of the menu. - * @param array $args wp_nav_menu() arguments. - * @return string $item_output The menu item output with social icon. - */ -function jetpack_social_menu_nav_menu_social_icons( $item_output, $item, $depth, $args ) { - // Get supported social icons. - $social_icons = jetpack_social_menu_social_links_icons(); - - // Change SVG icon inside social links menu if there is supported URL. - if ( 'jetpack-social-menu' === $args->theme_location ) { - foreach ( $social_icons as $attr => $value ) { - if ( false !== strpos( $item_output, $attr ) ) { - $item_output = str_replace( $args->link_after, '</span>' . jetpack_social_menu_get_svg( array( 'icon' => esc_attr( $value ) ) ), $item_output ); + /** + * Display SVG icons in social links menu. + * + * @param string $item_output The menu item output. + * @param WP_Post $item Menu item object. + * @param int $depth Depth of the menu. + * @param array $args wp_nav_menu() arguments. + * @return string $item_output The menu item output with social icon. + */ + function jetpack_social_menu_nav_menu_social_icons( $item_output, $item, $depth, $args ) { + // Get supported social icons. + $social_icons = jetpack_social_menu_social_links_icons(); + + // Change SVG icon inside social links menu if there is supported URL. + if ( 'jetpack-social-menu' === $args->theme_location ) { + foreach ( $social_icons as $attr => $value ) { + if ( false !== strpos( $item_output, $attr ) ) { + $item_output = str_replace( $args->link_after, '</span>' . jetpack_social_menu_get_svg( array( 'icon' => esc_attr( $value ) ) ), $item_output ); + } } } - } - return $item_output; -} -add_filter( 'walker_nav_menu_start_el', 'jetpack_social_menu_nav_menu_social_icons', 10, 4 ); + return $item_output; + } + add_filter( 'walker_nav_menu_start_el', 'jetpack_social_menu_nav_menu_social_icons', 10, 4 ); endif; if ( ! function_exists( 'jetpack_social_menu_social_links_icons' ) ) : -/** - * Returns an array of supported social links (URL and icon name). - * - * @return array $social_links_icons - */ -function jetpack_social_menu_social_links_icons() { - // Supported social links icons. - $social_links_icons = array( - '500px.com' => '500px', - 'amazon.cn' => 'amazon', - 'amazon.in' => 'amazon', - 'amazon.fr' => 'amazon', - 'amazon.de' => 'amazon', - 'amazon.it' => 'amazon', - 'amazon.nl' => 'amazon', - 'amazon.es' => 'amazon', - 'amazon.co' => 'amazon', - 'amazon.ca' => 'amazon', - 'amazon.com' => 'amazon', - 'apple.com' => 'apple', - 'itunes.com' => 'apple', - 'bandcamp.com' => 'bandcamp', - 'behance.net' => 'behance', - 'codepen.io' => 'codepen', - 'deviantart.com' => 'deviantart', - 'digg.com' => 'digg', - 'dribbble.com' => 'dribbble', - 'dropbox.com' => 'dropbox', - 'etsy.com' => 'etsy', - 'facebook.com' => 'facebook', - '/feed/' => 'feed', - 'flickr.com' => 'flickr', - 'foursquare.com' => 'foursquare', - 'goodreads.com' => 'goodreads', - 'plus.google.com' => 'google-plus', - 'google.com' => 'google', - 'github.com' => 'github', - 'instagram.com' => 'instagram', - 'linkedin.com' => 'linkedin', - 'mailto:' => 'mail', - 'meetup.com' => 'meetup', - 'medium.com' => 'medium', - 'pinterest.com' => 'pinterest', - 'getpocket.com' => 'pocket', - 'reddit.com' => 'reddit', - 'skype.com' => 'skype', - 'skype:' => 'skype', - 'slideshare.net' => 'slideshare', - 'snapchat.com' => 'snapchat', - 'soundcloud.com' => 'soundcloud', - 'spotify.com' => 'spotify', - 'stumbleupon.com' => 'stumbleupon', - 'tumblr.com' => 'tumblr', - 'twitch.tv' => 'twitch', - 'twitter.com' => 'twitter', - 'vimeo.com' => 'vimeo', - 'vk.com' => 'vk', - 'wordpress.org' => 'wordpress', - 'wordpress.com' => 'wordpress', - 'yelp.com' => 'yelp', - 'youtube.com' => 'youtube', - ); - - return $social_links_icons; -} + /** + * Returns an array of supported social links (URL and icon name). + * + * @return array $social_links_icons + */ + function jetpack_social_menu_social_links_icons() { + // Supported social links icons. + $social_links_icons = array( + '500px.com' => '500px', + 'amazon.cn' => 'amazon', + 'amazon.in' => 'amazon', + 'amazon.fr' => 'amazon', + 'amazon.de' => 'amazon', + 'amazon.it' => 'amazon', + 'amazon.nl' => 'amazon', + 'amazon.es' => 'amazon', + 'amazon.co' => 'amazon', + 'amazon.ca' => 'amazon', + 'amazon.com' => 'amazon', + 'apple.com' => 'apple', + 'itunes.com' => 'apple', + 'bandcamp.com' => 'bandcamp', + 'behance.net' => 'behance', + 'codepen.io' => 'codepen', + 'deviantart.com' => 'deviantart', + 'digg.com' => 'digg', + 'dribbble.com' => 'dribbble', + 'dropbox.com' => 'dropbox', + 'etsy.com' => 'etsy', + 'facebook.com' => 'facebook', + '/feed/' => 'feed', + 'flickr.com' => 'flickr', + 'foursquare.com' => 'foursquare', + 'goodreads.com' => 'goodreads', + 'plus.google.com' => 'google-plus', + 'google.com' => 'google', + 'github.com' => 'github', + 'instagram.com' => 'instagram', + 'linkedin.com' => 'linkedin', + 'mailto:' => 'mail', + 'meetup.com' => 'meetup', + 'medium.com' => 'medium', + 'pinterest.com' => 'pinterest', + 'getpocket.com' => 'pocket', + 'reddit.com' => 'reddit', + 'skype.com' => 'skype', + 'skype:' => 'skype', + 'slideshare.net' => 'slideshare', + 'snapchat.com' => 'snapchat', + 'soundcloud.com' => 'soundcloud', + 'spotify.com' => 'spotify', + 'stumbleupon.com' => 'stumbleupon', + 'tumblr.com' => 'tumblr', + 'twitch.tv' => 'twitch', + 'twitter.com' => 'twitter', + 'vimeo.com' => 'vimeo', + 'vk.com' => 'vk', + 'wordpress.org' => 'wordpress', + 'wordpress.com' => 'wordpress', + 'yelp.com' => 'yelp', + 'youtube.com' => 'youtube', + ); + + return $social_links_icons; + } endif; |