Files
Projects-Portfolio/templates/single-projects.php
T
Keith Solomon 426d60b692
Release / Build & publish plugin zip (push) Successful in 7s
Fix avatar and social icons with bulletproof rendering
Root cause of social icons rendering as alt text: wp_kses() stripped
the 'data:' prefix from data: URIs in img.src, leaving a relative URL
that 404s. Switched to real .svg files under assets/icons/ referenced
via plugins_url() — kses passes img tags with relative URLs cleanly,
and the icons load as standard images.

Root cause of avatar still being cropped: layout-side issues with
inline-styled <img> in a flex layout. Switched to a <span> with
inline background-image, background-size: cover, background-position:
center — no <img> element, no object-fit reliance, no way to crop wrong.

Also removed the outer <a> wrapper around the .project-owner div
(block-level element inside inline <a> is invalid HTML and was likely
contributing to layout weirdness). The owner name is now an explicit
<a> inside its own span.

Reverted kses to the default wp_kses_post() since we're back to
standard HTML elements only — no SVG, no data URIs, no inline styles
that need a custom allowed list.
2026-08-12 17:04:15 -05:00

190 lines
8.8 KiB
PHP

<?php
// Check if the theme is an FSE (block theme)
$is_fse_theme = wp_theme_has_theme_json() && function_exists( 'wp_is_block_theme' ) && wp_is_block_theme();
if ( $is_fse_theme ) {
wp_head();
echo do_blocks( '<!-- wp:template-part {"slug":"header"} /-->' ); // phpcs:ignore
} else {
get_header();
}
$settings = projects_portfolio_settings();
$project_id = get_the_ID();
$download_count = (int) get_post_meta( $project_id, '_projects_portfolio_download_count', true );
$repo_url = get_post_meta( $project_id, '_projects_portfolio_repo_url', true );
if ( '' === $repo_url ) {
$repo_url = get_post_meta( $project_id, '_projects_portfolio_github_url', true );
}
$repo_data = projects_portfolio_get_repo_data( $project_id );
$version = projects_portfolio_get_version( $project_id );
$owner = projects_portfolio_get_owner( $project_id );
$owner_avatar = $repo_data['owner']['avatar_url'] ?? '';
$owner_name = $repo_data['owner']['login'] ?? '';
$owner_url = $repo_data['owner']['html_url'] ?? '';
$last_updated = $repo_data['updated_at'] ?? '';
$language = $repo_data['language'] ?? '';
$license = $repo_data['license']['name'] ?? 'None';
$browse_url = $repo_url ? projects_portfolio_get_repo_browse_url( $project_id ) : '';
if ( $last_updated ) {
$last_updated = date_i18n( get_option( 'date_format' ), strtotime( $last_updated ) );
}
?>
<body <?php body_class(); ?>>
<div class="project-single-container">
<div class="project-header">
<div class="project-banner">
<?php if ( has_post_thumbnail() ) : ?>
<?php the_post_thumbnail( 'full' ); ?>
<?php else : ?>
<img src="<?php echo esc_url( plugin_dir_url( __FILE__ ) . 'assets/images/placeholder-banner.jpg' ); ?>" alt="<?php esc_attr_e( 'Project Banner', 'projects-wp' ); ?>">
<?php endif; ?>
</div>
</div>
<div class="project-main-content">
<div class="project-description">
<h1 class="project-title">
<?php
do_action( 'projects_portfolio_single_title_before' );
the_title();
do_action( 'projects_portfolio_single_title_after' );
?>
</h1>
<?php
do_action( 'projects_portfolio_single_content_before' );
the_content();
do_action( 'projects_portfolio_single_content_after' );
?>
</div>
<div class="project-sidebar">
<div class="project-buttons">
<a href="<?php echo esc_url( site_url( '/download/' . $project_id ) ); ?>" class="button project-download-button">
<?php esc_html_e( 'Download Now', 'projects-wp' ); ?>
</a>
<?php if ( $repo_url ) : ?>
<a href="<?php echo esc_url( $browse_url ); ?>" class="button project-repo-button" target="_blank" rel="noopener noreferrer">
<?php esc_html_e( 'View Repo', 'projects-wp' ); ?>
</a>
<?php else : ?>
<p><?php esc_html_e( 'Repository:', 'projects-wp' ); ?> <?php esc_html_e( 'No repository linked.', 'projects-wp' ); ?></p>
<?php endif; ?>
<?php do_action( 'projects_after_download_button', $project_id ); ?>
</div>
<div class="project-meta">
<?php
do_action( 'projects_portfolio_single_meta_before' );
?>
<table class="project-meta-table">
<tbody>
<?php if ( $settings['templates']['version'] ) : ?>
<tr>
<th><?php esc_html_e( 'Version:', 'projects-wp' ); ?></th>
<td><?php esc_html_e( $version ); ?></td>
</tr>
<?php endif; ?>
<?php if ( $settings['templates']['last_updated'] && $last_updated ) : ?>
<tr>
<th><?php esc_html_e( 'Updated:', 'projects-wp' ); ?></th>
<td><?php esc_html_e( $last_updated ); ?></td>
</tr>
<?php endif; ?>
<?php if ( $settings['templates']['license'] && $license ) : ?>
<tr>
<th><?php esc_html_e( 'License:', 'projects-wp' ); ?></th>
<td><?php esc_html_e( $license ); ?></td>
</tr>
<?php endif; ?>
<?php if ( $settings['templates']['language'] && $language ) : ?>
<tr>
<th><?php esc_html_e( 'Language:', 'projects-wp' ); ?></th>
<td><?php esc_html_e( $language ); ?></td>
</tr>
<?php endif; ?>
<?php if ( $settings['templates']['downloads'] ) : ?>
<tr>
<th><?php esc_html_e( 'Downloads:', 'projects-wp' ); ?></th>
<td><?php esc_html_e( $download_count ); ?></td>
</tr>
<?php endif; ?>
<?php
if ( ! empty( $repo_data ) ) :
if ( isset( $repo_data['stargazers_count'] ) && $settings['templates']['stargazers_count'] ) : ?>
<tr>
<th><?php esc_html_e( 'Stars:', 'projects-wp' ); ?></th>
<td><?php esc_html_e( $repo_data['stargazers_count'] ); ?></td>
</tr>
<?php endif;
if ( isset( $repo_data['forks_count'] ) && $settings['templates']['forks'] ) : ?>
<tr>
<th><?php esc_html_e( 'Forks:', 'projects-wp' ); ?></th>
<td><?php esc_html_e( $repo_data['forks_count'] ); ?></td>
</tr>
<?php endif;
if ( isset( $repo_data['open_issues_count'] ) && $settings['templates']['open_issues_count'] ) : ?>
<tr>
<th><?php esc_html_e( 'Issues:', 'projects-wp' ); ?></th>
<td><?php esc_html_e( $repo_data['open_issues_count'] ); ?></td>
</tr>
<?php endif;
endif;
?>
</tbody>
</table>
</div>
<?php if ( $settings['templates']['github_owner'] && $owner_avatar && $owner_name ) : ?>
<div class="project-owner">
<span class="project-owner-avatar" style="display:block;width:50px;height:50px;border-radius:50%;background-image:url('<?php echo esc_url( $owner_avatar ); ?>');background-size:cover;background-position:center center;flex-shrink:0;" aria-label="<?php echo esc_attr( $owner_name ); ?>" role="img"></span>
<span class="project-owner-name">
<a href="<?php echo esc_url( $owner_url ); ?>" target="_blank" rel="noopener noreferrer"><?php echo esc_html( $owner_name ); ?></a>
</span>
<span class="project-owner-follow">
<a class="button project-follow-button" href="<?php echo esc_url( $owner_url ); ?>" target="_blank" rel="noopener noreferrer"><?php esc_html_e( 'Follow', 'projects-wp' ); ?></a>
</span>
</div>
<?php endif; ?>
<?php
do_action( 'projects_portfolio_single_meta_after' );
?>
</div>
</div>
</div>
<?php
if ( $is_fse_theme ) {
wp_footer();
echo do_blocks( '<!-- wp:template-part {"slug":"footer"} /-->' );
} else {
get_footer();
}
?>
</body>
<?php
/**
* Enqueues theme styles specifically for single and archive pages of the "projects" post type.
*
* @since 1.0.0
* @return void
*/
function projects_portfolio_enqueue_theme_styles() {
if ( is_singular( 'projects' ) || is_post_type_archive( 'projects' ) ) {
// Enqueue the theme's main stylesheet.
wp_enqueue_style( 'theme-style', get_stylesheet_uri() );
// Enqueue additional theme styles if needed.
wp_enqueue_style( 'theme-header-style', get_template_directory_uri() . '/css/header.css' );
wp_enqueue_style( 'theme-footer-style', get_template_directory_uri() . '/css/footer.css' );
}
}
add_action( 'wp_enqueue_scripts', 'projects_portfolio_enqueue_theme_styles' );