Выполнить add_action в Wordpress через форму? - PullRequest
0 голосов
/ 26 марта 2020

У меня есть это действие в функциях. php. Это действие может отменить подписку при активации.

Как я могу выполнить это через форму?

Спасибо

/*--------------------------------------------------------------
# Unsubscribe user form
--------------------------------------------------------------*/
//logged in user can cancel subscription with a cancel form.
add_action( 'gform_after_submission_11', 'pwm_cancel_subscription', 10, 2 );
function pwm_cancel_subscription( $entry, $form ) {

  //SET SUBSCRIPTION TO CANCEL
  //get original current users entry id from subscription form.

  $entry_id = get_user_meta( get_current_user_id(), 'pwm_subscription_entry_id', true );
  if ( $entry_id > 0 ) {
    //now cancel that old entry's subscription
    $old_entry = GFAPI::get_entry( $entry_id );
    $feed      = is_wp_error( $old_entry ) || ! function_exists( 'gf_stripe' ) ? false : gf_stripe()->get_payment_feed( $old_entry );

    if ( is_array( $feed ) && rgar( $feed, 'addon_slug' ) == 'gravityformsstripe' && gf_stripe()->cancel( $old_entry, $feed ) ) {
      gf_stripe()->cancel_subscription( $old_entry, $feed );

      //destroy entry id so they cant cancel twice... not sure it does anything though if they try to
      update_user_meta( get_current_user_id(), 'pwm_subscription_entry_id', '' );
      //set them to subscribed till period ends. in limbo state.
      update_user_meta( get_current_user_id(), 'pwm_subscribed_till_end', true );
    }
  }



}
...