' ); } 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 ); $github_url = get_post_meta( $project_id, '_projects_portfolio_github_url', true ); $version = 'Unknown'; $github_data = projects_portfolio_get_github_data( $github_url ); // Extract specific GitHub data. $owner_avatar = $github_data['owner']['avatar_url'] ?? ''; $owner_name = $github_data['owner']['login'] ?? ''; $owner_url = $github_data['owner']['html_url'] ?? ''; $last_updated = $github_data['updated_at'] ?? ''; $language = $github_data['language'] ?? ''; $license = $github_data['license']['name'] ?? 'None'; $owner = projects_portfolio_github_owner( $owner_name ); // Fetch the version number from the GitHub API if the URL is set. if ( $github_url ) { // Retrieve the GitHub API token from the plugin settings. $github_token = get_option( 'projects_portfolio_github_api_token', '' ); // Prepare the API URL. $api_url = str_replace( 'https://github.com/', 'https://api.github.com/repos/', rtrim( $github_url, '/' ) ) . '/releases/latest'; // Check if the response is cached. $transient_key = 'github_api_response_' . md5( $api_url ); $response = get_transient( $transient_key ); if ( false === $response ) { // Prepare the request arguments. $args = []; if ( ! empty( $github_token ) ) { $args['headers'] = [ 'Authorization' => 'token ' . $github_token, ]; } // Make the API request. $response = wp_remote_get( $api_url, $args ); // Cache the response for 1 hour if the request is successful. if ( ! is_wp_error( $response ) && 200 === wp_remote_retrieve_response_code( $response ) ) { set_transient( $transient_key, $response, HOUR_IN_SECONDS ); } } // Handle the response. if ( is_wp_error( $response ) ) { error_log( 'GitHub API error: ' . $response->get_error_message() ); } else { $response_code = wp_remote_retrieve_response_code( $response ); $response_body = wp_remote_retrieve_body( $response ); error_log( 'GitHub API response code: ' . $response_code ); error_log( 'GitHub API response body: ' . $response_body ); if ( $response_code === 200 ) { $data = json_decode( $response_body, true ); // Check if tag_name exists in the response. if ( isset( $data['tag_name'] ) ) { $version = esc_html( $data['tag_name'] ); } } else { error_log( "GitHub API error: HTTP $response_code for URL $api_url" ); } } } // Format last updated date. if ( $last_updated ) { $last_updated = date_i18n( get_option( 'date_format' ), strtotime( $last_updated ) ); } ?> >
<?php esc_attr_e( 'Project Banner', 'projects-wp' ); ?>

' ); } else { get_footer(); } ?>