Add website fields to project meta box
Adds a 'This project is a website' toggle to the Repository meta box. When checked, site fields (URL, platform, optional screenshot) replace the git-repo fields; when unchecked, repo fields are shown and site fields are cleared. Existing posts default to repo mode. - admin/metabox.php: checkbox, site URL/platform/screenshot inputs with media-library picker, JS toggle, save handler that switches modes - includes/helper-functions.php: projects_portfolio_is_website / get _site_url / get_site_platform / get_site_screenshot_url helpers - templates/single-projects.php: website-mode rendering (Visit Site button, platform row, screenshot) - tests/test-metabox.php: website-mode persistence + mode-switch tests - tests/wp-stubs.php: sanitize_text_field, absint stubs
This commit is contained in:
@@ -104,6 +104,56 @@ function projects_portfolio_get_repo_browse_url( int $post_id ): string {
|
||||
return projects_portfolio_get_provider( $post_id )->get_repo_browse_url();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this project is configured as a website rather than a git repo.
|
||||
*
|
||||
* @since 1.4.0
|
||||
* @param int $post_id
|
||||
* @return bool
|
||||
*/
|
||||
function projects_portfolio_is_website( int $post_id ): bool {
|
||||
return (bool) get_post_meta( $post_id, '_projects_portfolio_is_website', true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Public URL for the project's website (when configured as a website).
|
||||
*
|
||||
* @since 1.4.0
|
||||
* @param int $post_id
|
||||
* @return string
|
||||
*/
|
||||
function projects_portfolio_get_site_url( int $post_id ): string {
|
||||
return (string) get_post_meta( $post_id, '_projects_portfolio_site_url', true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Platform label for the project's website (when configured as a website).
|
||||
*
|
||||
* @since 1.4.0
|
||||
* @param int $post_id
|
||||
* @return string
|
||||
*/
|
||||
function projects_portfolio_get_site_platform( int $post_id ): string {
|
||||
return (string) get_post_meta( $post_id, '_projects_portfolio_site_platform', true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Screenshot attachment URL for the project's website.
|
||||
*
|
||||
* @since 1.4.0
|
||||
* @param int $post_id
|
||||
* @param string $size
|
||||
* @return string
|
||||
*/
|
||||
function projects_portfolio_get_site_screenshot_url( int $post_id, string $size = 'large' ): string {
|
||||
$attachment_id = (int) get_post_meta( $post_id, '_projects_portfolio_site_screenshot_id', true );
|
||||
if ( $attachment_id <= 0 ) {
|
||||
return '';
|
||||
}
|
||||
$src = wp_get_attachment_image_src( $attachment_id, $size );
|
||||
return $src[0] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* GitHub API call for owner data
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user