jetpack
Last commit date
3rd-party
7 years ago
_inc
7 years ago
bin
7 years ago
css
7 years ago
extensions
7 years ago
images
7 years ago
json-endpoints
7 years ago
languages
7 years ago
logs
9 years ago
modules
7 years ago
sal
7 years ago
scss
7 years ago
sync
7 years ago
views
7 years ago
.svnignore
12 years ago
CODE-OF-CONDUCT.md
9 years ago
changelog.txt
7 years ago
class.frame-nonce-preview.php
9 years ago
class.jetpack-admin.php
7 years ago
class.jetpack-affiliate.php
7 years ago
class.jetpack-autoupdate.php
8 years ago
class.jetpack-bbpress-json-api-compat.php
9 years ago
class.jetpack-cli.php
7 years ago
class.jetpack-client-server.php
8 years ago
class.jetpack-client.php
7 years ago
class.jetpack-connection-banner.php
7 years ago
class.jetpack-constants.php
8 years ago
class.jetpack-data.php
7 years ago
class.jetpack-debugger.php
7 years ago
class.jetpack-error.php
10 years ago
class.jetpack-gutenberg.php
7 years ago
class.jetpack-heartbeat.php
7 years ago
class.jetpack-idc.php
8 years ago
class.jetpack-ixr-client.php
10 years ago
class.jetpack-jitm.php
7 years ago
class.jetpack-modules-list-table.php
7 years ago
class.jetpack-network-sites-list-table.php
9 years ago
class.jetpack-network.php
7 years ago
class.jetpack-options.php
7 years ago
class.jetpack-plan.php
7 years ago
class.jetpack-post-images.php
7 years ago
class.jetpack-signature.php
7 years ago
class.jetpack-tracks.php
7 years ago
class.jetpack-twitter-cards.php
7 years ago
class.jetpack-user-agent.php
8 years ago
class.jetpack-xmlrpc-server.php
7 years ago
class.jetpack.php
7 years ago
class.json-api-endpoints.php
7 years ago
class.json-api.php
7 years ago
class.photon.php
7 years ago
composer.json
7 years ago
functions.compat.php
7 years ago
functions.gallery.php
8 years ago
functions.global.php
7 years ago
functions.opengraph.php
7 years ago
functions.photon.php
7 years ago
jetpack.php
7 years ago
json-api-config.php
10 years ago
json-endpoints.php
7 years ago
locales.php
7 years ago
readme.txt
7 years ago
require-lib.php
7 years ago
uninstall.php
8 years ago
wpml-config.xml
10 years ago
class.jetpack-affiliate.php
79 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | // Exit if accessed directly |
| 5 | exit; |
| 6 | } |
| 7 | |
| 8 | /** |
| 9 | * This class introduces routines to get an affiliate code, that might be obtained from: |
| 10 | * - an `jetpack_affiliate_code` option in the WP database |
| 11 | * - an affiliate code returned by a filter bound to the `jetpack_affiliate_code` filter hook |
| 12 | * |
| 13 | * @since 6.9.0 |
| 14 | */ |
| 15 | class Jetpack_Affiliate { |
| 16 | |
| 17 | /** |
| 18 | * @since 6.9.0 |
| 19 | * @var Jetpack_Affiliate This class instance. |
| 20 | **/ |
| 21 | private static $instance = null; |
| 22 | |
| 23 | private function __construct() { |
| 24 | if ( Jetpack::is_development_mode() ) { |
| 25 | return; |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Initializes the class or returns the singleton |
| 31 | * |
| 32 | * @since 6.9.0 |
| 33 | * |
| 34 | * @return Jetpack_Affiliate | false |
| 35 | */ |
| 36 | public static function init() { |
| 37 | if ( is_null( self::$instance ) ) { |
| 38 | self::$instance = new Jetpack_Affiliate; |
| 39 | } |
| 40 | return self::$instance; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Returns the affiliate code from database after filtering it. |
| 45 | * |
| 46 | * @since 6.9.0 |
| 47 | * |
| 48 | * @return string The affiliate code. |
| 49 | */ |
| 50 | public function get_affiliate_code() { |
| 51 | /** |
| 52 | * Allow to filter the affiliate code. |
| 53 | * |
| 54 | * @since 6.9.0 |
| 55 | * |
| 56 | * @param string $aff_code The affiliate code, blank by default. |
| 57 | */ |
| 58 | return apply_filters( 'jetpack_affiliate_code', get_option( 'jetpack_affiliate_code', '' ) ); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Returns the passed URL with the affiliate code added as a URL query arg. |
| 63 | * |
| 64 | * @since 6.9.0 |
| 65 | * |
| 66 | * @param string $url The URL where the code will be added. |
| 67 | * |
| 68 | * @return string The passed URL with the code added. |
| 69 | */ |
| 70 | public function add_code_as_query_arg( $url ) { |
| 71 | if ( '' !== ( $aff = $this->get_affiliate_code() ) ) { |
| 72 | $url = add_query_arg( 'aff', $aff, $url ); |
| 73 | } |
| 74 | return $url; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | add_action( 'init', array( 'Jetpack_Affiliate', 'init' ) ); |
| 79 |