Route REST API responses through provider interface
This commit is contained in:
+19
-15
@@ -28,8 +28,11 @@ function projects_portfolio_get_projects_data( $request ) {
|
|||||||
$query->the_post();
|
$query->the_post();
|
||||||
|
|
||||||
$project_id = get_the_ID();
|
$project_id = get_the_ID();
|
||||||
$github_url = get_post_meta( $project_id, '_projects_portfolio_github_url', true );
|
$repo_url = get_post_meta( $project_id, '_projects_portfolio_repo_url', true );
|
||||||
$github_data = projects_portfolio_get_github_data( $github_url );
|
if ( '' === $repo_url ) {
|
||||||
|
$repo_url = get_post_meta( $project_id, '_projects_portfolio_github_url', true );
|
||||||
|
}
|
||||||
|
$repo_data = projects_portfolio_get_repo_data( $project_id );
|
||||||
|
|
||||||
// Fetch project-type taxonomy terms (names).
|
// Fetch project-type taxonomy terms (names).
|
||||||
$project_types = wp_get_post_terms( $project_id, 'project-type', [
|
$project_types = wp_get_post_terms( $project_id, 'project-type', [
|
||||||
@@ -44,23 +47,24 @@ function projects_portfolio_get_projects_data( $request ) {
|
|||||||
'thumbnail' => get_the_post_thumbnail_url( $project_id, 'large' ),
|
'thumbnail' => get_the_post_thumbnail_url( $project_id, 'large' ),
|
||||||
'download_count' => (int) get_post_meta( $project_id, '_projects_portfolio_download_count', true ),
|
'download_count' => (int) get_post_meta( $project_id, '_projects_portfolio_download_count', true ),
|
||||||
'download_url' => esc_url( site_url( '/download/' . $project_id ) ),
|
'download_url' => esc_url( site_url( '/download/' . $project_id ) ),
|
||||||
'github_url' => $github_url,
|
'github_url' => $repo_url,
|
||||||
|
'provider' => get_post_meta( $project_id, '_projects_portfolio_provider', true ) ?: 'github',
|
||||||
'github_data' => [
|
'github_data' => [
|
||||||
'owner' => [
|
'owner' => [
|
||||||
'avatar_url' => $github_data['owner']['avatar_url'] ?? '',
|
'avatar_url' => $repo_data['owner']['avatar_url'] ?? '',
|
||||||
'name' => $github_data['owner']['login'] ?? '',
|
'name' => $repo_data['owner']['login'] ?? '',
|
||||||
'profile' => $github_data['owner']['html_url'] ?? '',
|
'profile' => $repo_data['owner']['html_url'] ?? '',
|
||||||
],
|
],
|
||||||
'last_updated' => ! empty( $github_data['updated_at'] )
|
'last_updated' => ! empty( $repo_data['updated_at'] )
|
||||||
? date_i18n( get_option( 'date_format' ), strtotime( $github_data['updated_at'] ) )
|
? date_i18n( get_option( 'date_format' ), strtotime( $repo_data['updated_at'] ) )
|
||||||
: '',
|
: '',
|
||||||
'language' => $github_data['language'] ?? '',
|
'language' => $repo_data['language'] ?? '',
|
||||||
'license' => $github_data['license']['name'] ?? 'None',
|
'license' => $repo_data['license']['name'] ?? 'None',
|
||||||
'stars' => $github_data['stargazers_count'] ?? 0,
|
'stars' => $repo_data['stargazers_count'] ?? 0,
|
||||||
'forks' => $github_data['forks_count'] ?? 0,
|
'forks' => $repo_data['forks_count'] ?? 0,
|
||||||
'issues' => $github_data['open_issues_count'] ?? 0,
|
'issues' => $repo_data['open_issues_count'] ?? 0,
|
||||||
],
|
],
|
||||||
'version' => projects_portfolio_get_version_from_github( $github_url ),
|
'version' => projects_portfolio_get_version( $project_id ),
|
||||||
'project_types' => $project_types,
|
'project_types' => $project_types,
|
||||||
'content' => get_the_content(),
|
'content' => get_the_content(),
|
||||||
];
|
];
|
||||||
@@ -121,7 +125,7 @@ function projects_portfolio_get_popular_projects( $data ) {
|
|||||||
'title' => get_the_title(),
|
'title' => get_the_title(),
|
||||||
'download_count' => (int) get_post_meta( get_the_ID(), '_projects_portfolio_download_count', true ),
|
'download_count' => (int) get_post_meta( get_the_ID(), '_projects_portfolio_download_count', true ),
|
||||||
'download_url' => esc_url( site_url( '/download/' . get_the_ID() ) ),
|
'download_url' => esc_url( site_url( '/download/' . get_the_ID() ) ),
|
||||||
'github_url' => get_post_meta( get_the_ID(), '_projects_portfolio_github_url', true ),
|
'github_url' => ( $url = get_post_meta( get_the_ID(), '_projects_portfolio_repo_url', true ) ?: get_post_meta( get_the_ID(), '_projects_portfolio_github_url', true ) ),
|
||||||
'permalink' => get_permalink(),
|
'permalink' => get_permalink(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user