Making WordPress.org


Ignore:
Timestamp:
07/10/2015 08:32:01 PM (11 years ago)
Author:
iandunn
Message:

WordPress.tv: Give credit to video producers.

Fixes #986
Props BrashRebel

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.tv/public_html/wp-content/themes/wptv2/functions.php

    r1712 r1724  
    7777            'args'     => array( 'orderby' => 'term_order' ),
    7878            'rewrite'  => array( 'slug' => 'producer' ),
     79        ) );
     80
     81        register_taxonomy( 'producer-username', array( 'post' ), array(
     82            'label'    => __( 'Producer Username', 'wptv' ),
     83            'template' => __( 'Producer: %l.', 'wptv' ),
     84            'helps'    => __( 'Separate producer usernames with commas.', 'wptv' ),
     85            'sort'     => true,
     86            'args'     => array( 'orderby' => 'term_order' ),
     87            'rewrite'  => array( 'slug' => 'producer-username' ),
    7988        ) );
    8089
     
    819828}
    820829add_filter( 'get_the_excerpt', 'wptv_excerpt_slides' );
     830
     831/**
     832 * Checks if the given username exists on WordPress.org
     833 *
     834 * grav-redirect.php will redirect to a Gravatar image URL. If the WordPress.org username exists, the `d` parameter
     835 * will be 'retro', and if it doesn't it'll be 'mm'.
     836 *
     837 * @param string $username
     838 *
     839 * @return bool
     840 */
     841function wporg_username_exists( $username ) {
     842    $username_exists = false;
     843    $validator_url   = add_query_arg( 'user', $username, 'https://wordpress.org/grav-redirect.php' );
     844    $response        = wp_remote_retrieve_headers( wp_remote_get( $validator_url, array( 'redirection' => 0 ) ) );
     845
     846    if ( array_key_exists( 'location', $response ) ) {
     847        if ( false === strpos( $response['location'], 'd=mm' ) ) {
     848            $username_exists = true;
     849        }
     850    }
     851
     852    return $username_exists;
     853}
Note: See TracChangeset for help on using the changeset viewer.