'; if ( is_string( $header_text ) ) { $out[] = sprintf( '
%1s
', $header_text ); } $out[] = '
'; if ( is_array( $out ) ) { return implode( '', $out ); } } /** * Get contributors * * @since 0.0.1 * * @param string $owner Owner (username or organization name) for repo * @param string $repo Repo name * @param bool|string $header_text Optional text to output before the contributors * @param int $total Optional. Total number of contributors to show. Default is 100. * * @return array|mixed */ function acknowledge_me_get( $owner, $repo, $total = 100 ) { $transient_key = md5( implode( '_', array( __FUNCTION__, $owner, $repo, $total ) ) ); $contributors = get_transient( $transient_key ); if ( false !== $contributors ) { return $contributors; } $url = "https://api.github.com/repos/{$owner}/{$repo}/contributors?per_page={$total}"; $response = wp_remote_get( $url ); if ( is_wp_error( $response ) ) { return array(); } $contributors = json_decode( wp_remote_retrieve_body( $response ) ); if ( ! is_array( $contributors ) ) { return array(); } set_transient( $transient_key, $contributors, HOUR_IN_SECONDS ); return (array) $contributors; } /** * Adds a shortcode for this * * @since 0.0.1 */ add_shortcode( 'acknowledge_me', 'acknowledge_me_shortcode' ); function acknowledge_me_shortcode( $atts ) { $atts = shortcode_atts( array( 'owner' => 'pods-framework', 'repo' => 'pods', 'header_text' => '', 'total' => '100' ), $atts, 'acknowledge_me' ); return acknowledge_me_display( $atts[ 'owner' ], $atts[ 'repo' ], $atts[ 'header_text' ], $atts[ 'total'] ); } /** * Add CSS for this * * @since 0.0.1 */ add_action( 'wp_enqueue_scripts', 'acknowledge_me_css' ); function acknowledge_me_css() { if ( ! is_admin() ) { wp_enqueue_style( 'acknowledge_me', plugins_url( 'acknowledge.css', __FILE__ ) ); } }