forked from Solo-Web-Works/Projects-Portfolio
37 lines
1.3 KiB
PHP
37 lines
1.3 KiB
PHP
<?php
|
|
// If this file is called directly, abort.
|
|
if ( ! defined( 'WPINC' ) ) {
|
|
die;
|
|
}
|
|
|
|
/**
|
|
* Provider factory: selects the right adapter for a project post.
|
|
*
|
|
* @since 1.1.0
|
|
*
|
|
* @param int $post_id
|
|
* @return Repository_Provider
|
|
*/
|
|
function projects_portfolio_get_provider( int $post_id ): Repository_Provider {
|
|
$provider_meta = (string) get_post_meta( $post_id, '_projects_portfolio_provider', true );
|
|
$provider_id = '' !== $provider_meta ? $provider_meta : 'github';
|
|
|
|
$repo_url = (string) get_post_meta( $post_id, '_projects_portfolio_repo_url', true );
|
|
if ( '' === $repo_url ) {
|
|
// Lazy fallback to legacy key.
|
|
$repo_url = (string) get_post_meta( $post_id, '_projects_portfolio_github_url', true );
|
|
}
|
|
|
|
if ( 'gitea' === $provider_id ) {
|
|
$base_url = (string) get_post_meta( $post_id, '_projects_portfolio_gitea_base_url', true );
|
|
if ( '' === $base_url ) {
|
|
$base_url = (string) get_option( 'projects_portfolio_default_gitea_base_url', 'https://codeberg.org' );
|
|
}
|
|
$token = (string) get_option( 'projects_portfolio_gitea_api_token', '' );
|
|
return new Gitea_Provider( $repo_url, $base_url, $token );
|
|
}
|
|
|
|
$token = (string) get_option( 'projects_portfolio_github_api_token', '' );
|
|
return new GitHub_Provider( $repo_url, $token );
|
|
}
|