Advertisement
Guest User

Untitled

a guest
May 25th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Affiliates Referrer Info
  4. Plugin URI: http://www.eggemplo.com
  5. Description: Add a shortcode to show referrer info as lineal text (name and email)
  6. Author: eggemplo
  7. Version: 1.0
  8. Author URI: http://www.eggemplo.com
  9. */
  10. add_action ( 'init', 'add_aff_referrer_info_shortcodes' );
  11. function add_aff_referrer_info_shortcodes($data) {
  12. add_shortcode ( 'aff-referrer-info', 'aff_referrer_info' );
  13. add_shortcode ( 'aff_referrer_info', 'aff_referrer_info' );
  14. }
  15. function aff_referrer_info ($attr = array()) {
  16.  
  17. $output = "";
  18. $sep = isset( $attr['separator'] ) ? $attr['separator'] : "<br>";
  19. $direct = isset( $attr['show_direct'] ) ? true : false;
  20.  
  21. $name = isset( $attr['show_name'] ) ? true : false;
  22. $email = isset( $attr['show_email'] ) ? true : false;
  23.  
  24. if ( !class_exists("Affiliates_Service" ) ) {
  25. require_once( AFFILIATES_CORE_LIB . '/class-affiliates-service.php' );
  26. }
  27.  
  28. $affiliate_id = Affiliates_Service::get_referrer_id();
  29. if ( $affiliate_id ) {
  30. $affiliate = affiliates_get_affiliate( $affiliate_id );
  31.  
  32. if ( $direct || ( $affiliate_id !== affiliates_get_direct_id() ) ) {
  33. if ( $name ) {
  34. $output .= $affiliate['name'] . $sep;
  35. }
  36. if ( $email ) {
  37. $output .= $affiliate['email'] . $sep;
  38. }
  39.  
  40. if ( strlen($output)>0 ) { // delete last separator
  41. $output = substr($output, 0, strlen($output)-strlen($sep));
  42. }
  43. }
  44.  
  45. }
  46.  
  47. return $output;
  48.  
  49. }
  50. add_filter ( 'affiliates_service_affiliate_id', 'affiliates_service_affiliate_id_from_url', 10, 2 );
  51.  
  52. function affiliates_service_affiliate_id_from_url ( $affiliate_id, $service ) {
  53. global $wp, $wpdb;
  54.  
  55. $pname = get_option( 'aff_pname', AFFILIATES_PNAME );
  56. $affiliate_id = isset( $_GET[$pname] ) ? affiliates_check_affiliate_id_encoded( trim( $_GET[$pname] ) ) : $affiliate_id;
  57.  
  58. if ( isset( $_GET[$pname] ) ) {
  59. // affiliates-by-username uses this hook
  60. $maybe_affiliate_id = apply_filters( 'affiliates_parse_request_affiliate_id', $_GET[$pname], $affiliate_id );
  61. if ( ( $maybe_affiliate_id !== null ) && $maybe_affiliate_id !== trim( $_GET[$pname] ) ) {
  62. $affiliate_id = $maybe_affiliate_id;
  63. }
  64. }
  65. return $affiliate_id;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement