Advertisement
Guest User

Untitled

a guest
May 25th, 2015
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 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. add_shortcode ( 'aff_referrer_info', 'aff_referrer_info' );
  15. }
  16. function aff_referrer_info ($attr = array()) {
  17.  
  18. $output = "";
  19. $sep = isset( $attr['separator'] ) ? $attr['separator'] : "<br>";
  20. $direct = isset( $attr['show_direct'] ) ? true : false;
  21.  
  22. $name = isset( $attr['show_name'] ) ? true : false;
  23. $email = isset( $attr['show_email'] ) ? true : false;
  24. $affiliate_id = isset( $attr['show_user_id '] ) ? true : false;
  25.  
  26. if ( !class_exists("Affiliates_Service" ) ) {
  27. require_once( AFFILIATES_CORE_LIB . '/class-affiliates-service.php' );
  28. }
  29.  
  30. $affiliate_id = Affiliates_Service::get_referrer_id();
  31. if ( $affiliate_id ) {
  32. $affiliate = affiliates_get_affiliate( $affiliate_id );
  33.  
  34. if ( $direct || ( $affiliate_id !== affiliates_get_direct_id() ) ) {
  35. if ( $name ) {
  36. $output .= $affiliate['name'] . $sep;
  37. }
  38.  
  39. if ( $affiliate_id ) {
  40. $output .= $affiliate['user_id'] . $sep;
  41. }
  42.  
  43. if ( $email ) {
  44. $output .= $affiliate['email'] . $sep;
  45. }
  46.  
  47. if ( strlen($output)>0 ) { // delete last separator
  48. $output = substr($output, 0, strlen($output)-strlen($sep));
  49. }
  50. }
  51.  
  52. }
  53.  
  54. return $output;
  55.  
  56. }
  57. add_filter ( 'affiliates_service_affiliate_id', 'affiliates_service_affiliate_id_from_url', 10, 2 );
  58.  
  59. function affiliates_service_affiliate_id_from_url ( $affiliate_id, $service ) {
  60. global $wp, $wpdb;
  61.  
  62. $pname = get_option( 'aff_pname', AFFILIATES_PNAME );
  63. $affiliate_id = isset( $_GET[$pname] ) ? affiliates_check_affiliate_id_encoded( trim( $_GET[$pname] ) ) : $affiliate_id;
  64.  
  65. if ( isset( $_GET[$pname] ) ) {
  66. // affiliates-by-username uses this hook
  67. $maybe_affiliate_id = apply_filters( 'affiliates_parse_request_affiliate_id', $_GET[$pname], $affiliate_id );
  68. if ( ( $maybe_affiliate_id !== null ) && $maybe_affiliate_id !== trim( $_GET[$pname] ) ) {
  69. $affiliate_id = $maybe_affiliate_id;
  70. }
  71. }
  72. return $affiliate_id;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement