Skip to content

Commit

Permalink
Added mechanism to specify a constant for affiliate ID to be used in …
Browse files Browse the repository at this point in the history
…the Extensions page. Fixes #482.
  • Loading branch information
Japh committed Apr 30, 2014
1 parent a8da5b1 commit c0f7551
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions includes/extensions.php
Expand Up @@ -4,6 +4,17 @@
*
* @author Chris Olbekson <chris@x-team.com>
*/
/**
* By defining the WP_STREAM_AFFILIATE_ID constant, links on the Extensions page
* will be appended with the ID specified.
*
* More details on the Stream Premium affiliate program here:
* https://wp-stream.com/affiliates/
*
* Uncomment the line below, and change the "1" to be your affiliate ID.
*/

//define( 'WP_STREAM_AFFILIATE_ID', 1 );

class WP_Stream_Extensions {

Expand Down Expand Up @@ -100,6 +111,15 @@ function get_extension_api() {
return false;
}

/**
* Gets the affiliate reference portion of a URL if the affiliate ID constant is set.
*
* @return string A query string of the format '?ref=1', where 1 is the affiliate ID
*/
function get_affiliate() {
return ( defined( 'WP_STREAM_AFFILIATE_ID' ) ? '?ref=' . urlencode( WP_STREAM_AFFILIATE_ID ) : '' );
}

/**
* Filters the plugin install api
*
Expand Down Expand Up @@ -133,7 +153,7 @@ function filter_plugin_api_info( $false, $action, $args ) {

return $api;
} else {
$message = '<p>' . sprintf( __( 'You must connect to your %s account to install extensions.', 'stream' ), '<strong>' . esc_html__( 'Stream Premium', 'stream' ) . '</strong>' ) . '</p><p>' . esc_html__( "Don't have an account?", 'stream' ) . '</p><p><a href="https://wp-stream.com/join/" target="_blank" class="button">' . esc_html__( 'Join Stream Premium', 'stream' ) . '</a></p>';
$message = '<p>' . sprintf( __( 'You must connect to your %s account to install extensions.', 'stream' ), '<strong>' . esc_html__( 'Stream Premium', 'stream' ) . '</strong>' ) . '</p><p>' . esc_html__( "Don't have an account?", 'stream' ) . '</p><p><a href="https://wp-stream.com/join/' . $this->get_affiliate() . '" target="_blank" class="button">' . esc_html__( 'Join Stream Premium', 'stream' ) . '</a></p>';
wp_die( $message, 'Stream Extension Installation', array( 'response' => 200, 'back_link' => true ) ); // xss ok
}
}
Expand Down Expand Up @@ -210,7 +230,7 @@ function extensions_display_header( $extensions ) {
<?php if ( ! $this->verify_membership() ) : ?>
<p class="description">
<?php esc_html_e( "Connect your Stream Premium account and authorize this domain to install and receive automatic updates for premium extensions. Don't have an account?", 'stream' ) ?>
<a href="<?php echo esc_url( self::API_TRANSPORT . self::API_DOMAIN . '/join/' ) ?>" class="stream-premium-join"><?php esc_html_e( 'Join Stream Premium', 'stream' ) ?></a>
<a href="<?php echo esc_url( self::API_TRANSPORT . self::API_DOMAIN . '/join/' . $this->get_affiliate() ) ?>" class="stream-premium-join"><?php esc_html_e( 'Join Stream Premium', 'stream' ) ?></a>
</p>
<?php else : ?>
<p class="description" style="color: green;">
Expand All @@ -234,7 +254,7 @@ function extensions_display_body( $extensions ) {
<p>
<em><?php esc_html_e( 'Sorry, there was a problem loading the list of extensions.', 'stream' ) ?></em></p>
<p>
<a class="button button-primary" href="<?php echo esc_url( self::API_TRANSPORT . self::API_DOMAIN . '/#extensions' ) ?>" target="_blank"><?php esc_html_e( 'Browse All Extensions', 'stream' ) ?></a>
<a class="button button-primary" href="<?php echo esc_url( self::API_TRANSPORT . self::API_DOMAIN . '/#extensions' . $this->get_affiliate() ) ?>" target="_blank"><?php esc_html_e( 'Browse All Extensions', 'stream' ) ?></a>
</p>
<?php
return;
Expand Down

0 comments on commit c0f7551

Please sign in to comment.