GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-gravityview-powered-by.php
Go to the documentation of this file.
1 <?php
2 
3 
4 /** If this file is called directly, abort. */
5 if ( ! defined( 'GRAVITYVIEW_DIR' ) ) {
6  die();
7 }
8 
9 /**
10  * Add a Powered By link below Views.
11  *
12  * @since 2.5.3
13  *
14  */
16 
17  const url = 'https://www.gravitykit.com/powered-by/';
18 
19  /**
20  * GravityView_Powered_By constructor.
21  */
22  public function __construct() {
23  add_action( 'gravityview/template/after', array( $this, 'maybe_add_link' ) );
24  }
25 
26  /**
27  * Prints a HTML link to GravityView's site if "Powered By" GravityView setting is enabled
28  *
29  * @return void
30  */
31  public function maybe_add_link() {
32 
33  $powered_by = gravityview()->plugin->settings->get_gravitykit_setting( 'powered_by', 0 );
34 
35  if( empty( $powered_by ) ) {
36  return;
37  }
38 
39  $url = $this->get_url();
40 
41  // Allow disabling link via URL filter
42  if ( empty( $url ) ) {
43  return;
44  }
45 
46  /**
47  * @filter `gravityview/powered_by/text` Modify the anchor text for the Powered By link
48  * @param string $anchor_text Anchor text for the Powered By link. Default: "Powered by GravityView". Will be sanitized before display.
49  */
50  $anchor_text = apply_filters( 'gravityview/powered_by/text', __( 'Powered by GravityView', 'gk-gravityview' ) );
51 
52  printf( '<span class="gv-powered-by"><a href="%s">%s</a></span>', esc_url( $url ), esc_html( $anchor_text ) );
53  }
54 
55  /**
56  * Returns the URL to GravityView
57  *
58  * @return string URL to GravityView (not sanitized)
59  */
60  protected function get_url() {
61 
62  $url = sprintf( self::url, get_bloginfo('name' ) );
63 
64  $affiliate_id = gravityview()->plugin->settings->get_gravitykit_setting( 'affiliate_id', '' );
65 
66  if( $affiliate_id && is_numeric( $affiliate_id ) ) {
67  $url = add_query_arg( array( 'ref' => $affiliate_id ), $url );
68  }
69 
70  $url = add_query_arg( array(
71  'utm_source' => 'powered_by',
72  'utm_term' => get_bloginfo('name' ),
73  ), $url );
74 
75  /**
76  * @filter `gravityview/powered_by/url` Modify the URL returned by the Powered By link
77  * @param $url string The URL passed to the Powered By link
78  */
79  $url = apply_filters( 'gravityview/powered_by/url', $url );
80 
81  return $url;
82  }
83 }
84 
$url
Definition: post_image.php:25
get_url()
Returns the URL to GravityView.
__construct()
GravityView_Powered_By constructor.
If this file is called directly, abort.
gravityview()
The main GravityView wrapper function.
maybe_add_link()
Prints a HTML link to GravityView&#39;s site if "Powered By" GravityView setting is enabled.