22 $this->label = esc_html__(
'Unsubscribe',
'gk-gravityview' );
23 $this->
description = esc_attr__(
'Unsubscribe from a Payment-based entry.',
'gk-gravityview' );
27 parent::__construct();
36 add_filter(
'gravityview_entry_default_fields', array( $this,
'filter_gravityview_entry_default_field' ), 10, 3 );
38 add_filter(
'gravityview/field/is_visible', array( $this,
'maybe_not_visible' ), 10, 2 );
40 add_filter(
'gravityview_field_entry_value_unsubscribe', array( $this,
'modify_entry_value_unsubscribe' ), 10, 4 );
62 unset( $field_options[
'only_loggedin'] );
64 unset( $field_options[
'new_window'] );
66 unset( $field_options[
'show_as_link'] );
68 $add_options[
'unsub_all'] = array(
70 'label' => __(
'Allow admins to unsubscribe',
'gk-gravityview' ),
71 'desc' => __(
'Allow users with `gravityforms_edit_entries` to cancel subscriptions',
'gk-gravityview' ),
73 'merge_tags' =>
false,
76 return $field_options + $add_options;
92 if ( $this->name !==
$field->ID ) {
95 return is_user_logged_in() ? $visible :
false;
112 if ( is_array(
$form ) ) {
113 return $entry_default_fields;
116 $feeds = GFAPI::get_feeds( null,
$form );
118 if ( is_wp_error( $feeds ) ) {
119 return $entry_default_fields;
122 static $subscription_addons;
124 if ( is_null( $subscription_addons ) ) {
126 $registered = GFAddon::get_registered_addons();
128 foreach ( $registered as $addon ) {
129 if ( method_exists( $addon,
'cancel_subscription' ) && is_callable( array( $addon,
'get_instance' ) ) ) {
130 $addon = $addon::get_instance();
131 $subscription_addons[ $addon->get_slug() ] = $addon;
136 if ( empty( $subscription_addons ) ) {
137 return $entry_default_fields;
140 foreach ( $feeds as $feed ) {
141 if ( isset( $subscription_addons[ $feed[
'addon_slug'] ] ) &&
'subscription' === \
GV\Utils::get( $feed,
'meta/transactionType' ) ) {
142 if ( ! isset( $entry_default_fields[
"{$this->name}"] ) &&
'edit' !== $context ) {
143 $entry_default_fields[
"{$this->name}"] = array(
144 'label' => $this->label,
146 'type' => $this->name,
154 return $entry_default_fields;
171 if ( ! is_user_logged_in() || !
$entry ) {
175 $can_current_user_edit = is_numeric(
$entry[
'created_by'] ) && ( wp_get_current_user()->ID === intval(
$entry[
'created_by'] ) );
177 if ( ! $can_current_user_edit ) {
183 if ( ! $status = \
GV\Utils::get(
$entry,
'payment_status' ) ) {
191 if (
$entry[
'payment_status'] !== $status ) {
193 return $entry[
'payment_status'];
197 if (
'active' !== mb_strtolower(
$entry[
'payment_status'] ) ) {
202 $current_url = add_query_arg( $wp->query_string,
'', home_url( $wp->request ) );
204 $link = add_query_arg(
'unsubscribe', wp_create_nonce(
'unsubscribe_' .
$entry[
'id'] ), $current_url );
207 return sprintf(
'<a href="%s">%s</a>', esc_url(
$link ), esc_html__(
'Unsubscribe',
'gk-gravityview' ) );
225 if ( ! wp_verify_nonce( \
GV\Utils::_REQUEST(
'unsubscribe' ),
'unsubscribe_' .
$entry[
'id'] ) ) {
229 if ( ( ! $uid = \
GV\Utils::_REQUEST(
'uid' ) ) || ! is_numeric( $uid ) || ( intval( $uid ) !== intval(
$entry[
'id'] ) ) ) {
233 if ( ! $feeds = gform_get_meta( $uid,
'processed_feeds' ) ) {
237 static $subscription_addons;
239 if ( is_null( $subscription_addons ) ) {
241 $registered = GFAddon::get_registered_addons();
243 foreach ( $registered as $addon ) {
244 if ( method_exists( $addon,
'cancel_subscription' ) ) {
245 $addon = $addon::get_instance();
246 $subscription_addons[ $addon->get_slug() ] = $addon;
251 if ( empty( $subscription_addons ) ) {
255 foreach ( $feeds as $slug => $feed_ids ) {
257 if ( ! isset( $subscription_addons[ $slug ] ) ) {
261 foreach ( $feed_ids as $feed_id ) {
263 $feed = $subscription_addons[ $slug ]->get_feed( $feed_id );
265 if ( $feed &&
'subscription' === \
GV\Utils::get( $feed,
'meta/transactionType' ) ) {
267 if ( $subscription_addons[ $slug ]->cancel(
$entry, $feed ) ) {
269 $subscription_addons[ $slug ]->cancel_subscription(
$entry, $feed );
271 return \GFAPI::get_entry(
$entry[
'id'] );
Modify field settings by extending this class.
maybe_not_visible( $visible, $field)
Hide the field from the renderer.
new GravityView_Field_Unsubscribe
filter_gravityview_entry_default_field( $entry_default_fields, $form, $context)
Add the unsubsribe to the configuration fields.
field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id)
Configure the field options.
$field_settings['content']
if( $add_query_args) $link
if(gravityview() ->plugin->is_GF_25()) $form
add_hooks()
Hooks called from constructor.
scale description p description
if(empty( $created_by)) $form_id
static has_cap( $caps='', $object_id=null, $user_id=null)
Alias of GravityView_Roles_Capabilities::has_cap()
maybe_unsubscribe( $entry)
Try to unsubscribe from the entry.
if(false !==strpos( $value, '00:00')) $field_id
string $field_id ID of the field being displayed
modify_entry_value_unsubscribe( $output, $entry, $field_settings, $field)
Modify the render content.