Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classic Theme Helper: Copy Content Options code to Classic Theme Helper package #39028

Merged
merged 12 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion projects/packages/classic-theme-helper/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@
return [
// # Issue statistics:
// PhanTypeMismatchArgumentInternal : 10+ occurrences
// PhanTypePossiblyInvalidDimOffset : 8 occurrences
// PhanUndeclaredClassMethod : 7 occurrences
// PhanUndeclaredClassReference : 4 occurrences
// PhanTypeInvalidDimOffset : 2 occurrences
// PhanTypeMismatchArgument : 2 occurrences
// PhanTypeComparisonToArray : 1 occurrence
// PhanTypeMismatchArgumentProbablyReal : 1 occurrence
// PhanTypeMismatchProperty : 1 occurrence
// PhanTypePossiblyInvalidDimOffset : 1 occurrence
// PhanUndeclaredTypeProperty : 1 occurrence

// Currently, file_suppressions and directory_suppressions are the only supported suppressions
'file_suppressions' => [
'_inc/lib/tonesque.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchArgumentProbablyReal'],
'src/class-featured-content.php' => ['PhanTypeComparisonToArray', 'PhanTypeInvalidDimOffset', 'PhanTypeMismatchArgument', 'PhanTypeMismatchProperty', 'PhanTypePossiblyInvalidDimOffset'],
'src/class-social-links.php' => ['PhanUndeclaredClassMethod', 'PhanUndeclaredClassReference', 'PhanUndeclaredTypeProperty'],
'src/content-options/featured-images-fallback.php' => ['PhanTypePossiblyInvalidDimOffset'],
],
// 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed.
// (directory_suppressions will currently be ignored by subsequent calls to --save-baseline, but may be preserved in future Phan releases)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Content Options: Moving content to Classic Theme Helper package.
2 changes: 1 addition & 1 deletion projects/packages/classic-theme-helper/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-classic-theme-helper",
"version": "0.5.3",
"version": "0.5.4-alpha",

Check failure on line 4 in projects/packages/classic-theme-helper/package.json

View workflow job for this annotation

GitHub Actions / Changelogger validity

Version mismatch, expected 0.5.3 but found 0.5.4-alpha! Before you can merge your PR, please run `tools/fixup-project-versions.sh`, commit, and push the generated changes to your branch to fix this.
"description": "Features used with classic themes",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/classic-theme-helper/#readme",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/classic-theme-helper/src/class-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
class Main {

const PACKAGE_VERSION = '0.5.3';
const PACKAGE_VERSION = '0.5.4-alpha';

Check failure on line 17 in projects/packages/classic-theme-helper/src/class-main.php

View workflow job for this annotation

GitHub Actions / Changelogger validity

Version mismatch, expected 0.5.3 but found 0.5.4-alpha! Before you can merge your PR, please run `tools/fixup-project-versions.sh`, commit, and push the generated changes to your branch to fix this.

/**
* Modules to include.
Expand Down
170 changes: 170 additions & 0 deletions projects/packages/classic-theme-helper/src/content-options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<?php
/**
* Jetpack Compatibility File
* See: https://jetpack.com/
*
* @package automattic/jetpack-classic-theme-helper
*/

/**
* Content Options.
*
* This feature will only be activated for themes that declare their support.
* This can be done by adding code similar to the following during the
* 'after_setup_theme' action:
*
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.
'author-bio' => true, // display or not the author bio: true or false.
'author-bio-default' => false, // the default setting of the author bio, if it's being displayed or not: true or false (only required if false).
'avatar-default' => true, // display or not the default avatar for the author bio: true or false.
'masonry' => '.site-main', // a CSS selector matching the elements that triggers a masonry refresh if the theme is using a masonry layout.
'post-details' => array(
'stylesheet' => 'themeslug-style', // name of the theme's stylesheet.
'date' => '.posted-on', // a CSS selector matching the elements that display the post date.
'categories' => '.cat-links', // a CSS selector matching the elements that display the post categories.
'tags' => '.tags-links', // a CSS selector matching the elements that display the post tags.
'author' => '.byline', // a CSS selector matching the elements that display the post author.
'comment' => '.comments-link', // a CSS selector matching the elements that display the comment link.
),
'featured-images' => array(
'archive' => true, // enable or not the featured image check for archive pages: true or false.
'archive-default' => false, // the default setting of the featured image on archive pages, if it's being displayed or not: true or false (only required if false).
'post' => true, // enable or not the featured image check for single posts: true or false.
'post-default' => false, // the default setting of the featured image on single posts, if it's being displayed or not: true or false (only required if false).
'page' => true, // enable or not the featured image check for single pages: true or false.
'page-default' => false, // the default setting of the featured image on single pages, if it's being displayed or not: true or false (only required if false).
'portfolio' => true, // enable or not the featured image check for single projects: true or false.
'portfolio-default' => false, // the default setting of the featured image on single projects, if it's being displayed or not: true or false (only required if false).
'fallback' => true, // enable or not the featured image fallback: true or false.
'fallback-default' => true, // the default setting for featured image fallbacks: true or false (only required if false)
),
) );
*/

if ( ! function_exists( 'jetpack_content_options_init' ) ) {

/**
* Activate the Content Options plugin.
*
* @uses current_theme_supports()
*/
function jetpack_content_options_init() {
// If the theme doesn't support 'jetpack-content-options', don't continue.
if ( ! current_theme_supports( 'jetpack-content-options' ) ) {
return;
}

// Load the Customizer options.
require __DIR__ . '/content-options/customizer.php';

// Load Blog Display function.
require __DIR__ . '/content-options/blog-display.php';

// Load Author Bio function.
require __DIR__ . '/content-options/author-bio.php';

// Load Post Details function.
require __DIR__ . '/content-options/post-details.php';

// Load Featured Images function.
if ( jetpack_featured_images_should_load() ) {
require __DIR__ . '/content-options/featured-images.php';
}

// Load Featured Images Fallback function.
if ( jetpack_featured_images_fallback_should_load() ) {
require __DIR__ . '/content-options/featured-images-fallback.php';
}
}
add_action( 'init', 'jetpack_content_options_init' );

}

if ( ! function_exists( 'jetpack_featured_images_get_settings' ) ) {

/**
* Get featured images settings using the jetpack-content-options theme support.
*/
function jetpack_featured_images_get_settings() {
$options = get_theme_support( 'jetpack-content-options' );

$featured_images = ( ! empty( $options[0]['featured-images'] ) ) ? $options[0]['featured-images'] : null;

$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,
'portfolio' => ( ! empty( $featured_images['portfolio'] ) ) ? $featured_images['portfolio'] : null,
'archive-default' => ( isset( $featured_images['archive-default'] ) && false === $featured_images['archive-default'] ) ? '' : 1,
'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,
'portfolio-default' => ( isset( $featured_images['portfolio-default'] ) && false === $featured_images['portfolio-default'] ) ? '' : 1,
'fallback' => ( ! empty( $featured_images['fallback'] ) ) ? $featured_images['fallback'] : null,
'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'] ),
)
);

return $settings;
}

}

if ( ! function_exists( 'jetpack_featured_images_should_load' ) ) {

/**
* Determine if the Jetpack Featured Images should be load.
*/
function jetpack_featured_images_should_load() {
// If the theme doesn't support post thumbnails, don't continue.
if ( ! current_theme_supports( 'post-thumbnails' ) ) {
return false;
}

$opts = jetpack_featured_images_get_settings();

// If the theme doesn't support archive, post and page or if all the options are ticked and we aren't in the customizer, don't continue.
if (
( true !== $opts['archive'] && true !== $opts['post'] && true !== $opts['page'] )
|| ( 1 === $opts['archive-option'] && 1 === $opts['post-option'] && 1 === $opts['page-option'] && ! is_customize_preview() )
) {
return false;
}

return true;
}

}

if ( ! function_exists( 'jetpack_featured_images_fallback_should_load' ) ) {

/**
* Determine if the Jetpack Featured Images fallback should load.
*/
function jetpack_featured_images_fallback_should_load() {
// If the theme doesn't support post thumbnails, don't continue.
if ( ! current_theme_supports( 'post-thumbnails' ) ) {
return false;
}

$opts = jetpack_featured_images_get_settings();

// If the theme doesn't support fallback, don't continue.
if ( true !== $opts['fallback'] ) {
return false;
}

return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
/**
* Theme Tools: Author Bio functions.
*
* @package automattic/jetpack-classic-theme-helper
*/

if ( ! function_exists( 'jetpack_author_bio' ) ) {

/**
* The function to display Author Bio in a theme.
*/
function jetpack_author_bio() {
// If the theme doesn't support 'jetpack-content-options', don't continue.
if ( ! current_theme_supports( 'jetpack-content-options' ) ) {
return;
}

$options = get_theme_support( 'jetpack-content-options' );
$author_bio = ( ! empty( $options[0]['author-bio'] ) ) ? $options[0]['author-bio'] : null;
$author_bio_default = ( isset( $options[0]['author-bio-default'] ) && false === $options[0]['author-bio-default'] ) ? '' : 1;
$avatar_default = ( isset( $options[0]['avatar-default'] ) && false === $options[0]['avatar-default'] ) ? '' : 1;

// If the theme doesn't support 'jetpack-content-options[ 'author-bio' ]', don't continue.
if ( true !== $author_bio ) {
return;
}

// If 'jetpack_content_author_bio' is false, don't continue.
if ( ! get_option( 'jetpack_content_author_bio', $author_bio_default ) ) {
return;
}

// If we aren't on a single post, don't continue.
if ( ! is_single() ) {
return;
}

// Define class for entry-author.
if ( ! $avatar_default && ! jetpack_has_gravatar( get_the_author_meta( 'user_email' ) ) ) {
$class = 'author-avatar-hide';
} else {
$class = 'author-avatar-show';
}
?>
<div class="entry-author <?php echo esc_attr( $class ); ?>">
<?php if ( 'author-avatar-show' === $class ) : ?>
<div class="author-avatar">
<?php
/**
* Filter the author bio avatar size.
*
* @param int $size The avatar height and width size in pixels.
*
* @module theme-tools
*
* @since 4.5.0
*/
$author_bio_avatar_size = apply_filters( 'jetpack_author_bio_avatar_size', 48 );

echo get_avatar( get_the_author_meta( 'user_email' ), $author_bio_avatar_size );
?>
</div><!-- .author-avatar -->
<?php endif; ?>

<div class="author-heading">
<h2 class="author-title">
<?php
/* translators: %s: post author */
printf( esc_html__( 'Published by %s', 'jetpack-classic-theme-helper' ), '<span class="author-name">' . get_the_author() . '</span>' );
?>
</h2>
</div><!-- .author-heading -->

<p class="author-bio">
<?php the_author_meta( 'description' ); ?>
<a class="author-link" href="<?php echo esc_url( get_author_posts_url( (int) get_the_author_meta( 'ID' ) ) ); ?>" rel="author">
<?php
/* translators: %s: post author */
printf( esc_html__( 'View all posts by %s', 'jetpack-classic-theme-helper' ), get_the_author() );
?>
</a>
</p><!-- .author-bio -->
</div><!-- .entry-auhtor -->
<?php
}

}

if ( ! function_exists( 'jetpack_has_gravatar' ) ) {

/**
* Checks to see if the specified email address has a Gravatar image.
*
* @param string $email The email of the address of the user to check.
* @return bool Whether or not the user has a gravatar
*/
function jetpack_has_gravatar( $email ) {

$url = get_avatar_url( $email, array( 'default' => '404' ) );
$headers = get_headers( $url );

// If 200 is found, the user has a Gravatar; otherwise, they don't.
return preg_match( '|200|', $headers[0] ) ? true : false;
}

}
Loading
Loading