Advertisement
verygoodplugins

Untitled

Jul 27th, 2021
1,116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.97 KB | None | 0 0
  1. <?php
  2.  
  3. if ( ! defined( 'ABSPATH' ) ) {
  4.     exit; // Exit if accessed directly
  5. }
  6.  
  7.  
  8. class WPF_WP_Ultimo extends WPF_Integrations_Base {
  9.  
  10.     /**
  11.      * Gets things started
  12.      *
  13.      * @access  public
  14.      * @since   1.0
  15.      * @return  void
  16.      */
  17.  
  18.     public function init() {
  19.  
  20.         $this->slug = 'wp-ultimo';
  21.  
  22.         add_action( 'wp_ultimo_registration', array( $this, 'registration' ), 10, 4 );
  23.         add_filter( 'wpf_user_register', array( $this, 'user_register' ), 10, 2 );
  24.  
  25.         add_action( 'wpf_tags_modified', array( $this, 'update_plans' ), 10, 2 );
  26.  
  27.         // Custom fields
  28.         add_filter( 'wpf_meta_field_groups', array( $this, 'add_meta_field_group' ) );
  29.         add_filter( 'wpf_meta_fields', array( $this, 'prepare_meta_fields' ) );
  30.  
  31.         // Plan settings
  32.         add_filter( 'wu_plans_advanced_options_tabs', array( $this, 'add_options_tab' ) );
  33.         add_action( 'wu_plans_advanced_options_after_panels', array( $this, 'options_tab' ) );
  34.         add_action( 'save_post_wpultimo_plan', array( $this, 'save_post' ) );
  35.  
  36.     }
  37.  
  38.     /**
  39.      * Apply tags on registration.
  40.      *
  41.      * @access public
  42.      * @return void
  43.      */
  44.  
  45.     public function registration( $site_id, $user_id, $transient, $plan ) {
  46.  
  47.         $settings = get_post_meta( $plan->id, 'wpf_settings_wu', true );
  48.  
  49.         if ( empty( $settings ) ) {
  50.             return;
  51.         }
  52.  
  53.         if ( ! empty( $settings['apply_tags'] ) ) {
  54.             wp_fusion()->user->apply_tags( $settings['apply_tags'], $user_id );
  55.         }
  56.  
  57.     }
  58.  
  59.     /**
  60.      * Merge the Ultimo transient data into the data being synced to the CRM for
  61.      * the new user registration.
  62.      *
  63.      * @since  3.37.29
  64.      *
  65.      * @param  array $post_data The POSTed data from the registration form.
  66.      * @param  int   $user_id   The user ID.
  67.      * @return array The registration data.
  68.      */
  69.     public function user_register( $post_data, $user_id ) {
  70.  
  71.         $transient = WU_Signup::get_transient( false ); // don't die
  72.  
  73.         /* $transient contains
  74.  
  75.         (
  76.             [honeypot_id] => 60fedfb2b21fa
  77.             [plan_freq] => 1
  78.             [plan_id] => 50
  79.             [blog_title] => TestTwo
  80.             [blogname] => testtwo
  81.             [signup_form_id] => 1
  82.             [save_step] => 1
  83.             [first_name] => J
  84.             [last_name] => A
  85.             [user_name] => testtwo
  86.             [user_email] => testtwo@example.com
  87.             [user_pass] => testtwo
  88.             [user_pass_conf] => testtwo
  89.             [site_url] =>
  90.             [coupon] =>
  91.             [site_id] => 4
  92.             [user_id] => 3
  93.         ) */
  94.  
  95.         $post_data = array_merge( $post_data, $transient );
  96.  
  97.         return $post_data;
  98.  
  99.     }
  100.  
  101.     /**
  102.      * Update user plans when tags are modified (unfinished)
  103.      *
  104.      * @access public
  105.      * @return void
  106.      */
  107.  
  108.     public function update_plans( $user_id, $user_tags ) {
  109.  
  110.         $linked_plans = get_posts(
  111.             array(
  112.                 'post_type'  => 'wpultimo_plan',
  113.                 'nopaging'   => true,
  114.                 'meta_query' => array(
  115.                     array(
  116.                         'key'     => 'wpf_settings_wu',
  117.                         'compare' => 'EXISTS',
  118.                     ),
  119.                 ),
  120.                 'fields'     => 'ids',
  121.             )
  122.         );
  123.  
  124.         if ( empty( $linked_plans ) ) {
  125.             return;
  126.         }
  127.  
  128.     }
  129.  
  130.  
  131.     /**
  132.      * Adds WP Ultimo field group to meta fields list
  133.      *
  134.      * @access  public
  135.      * @return  array Field groups
  136.      */
  137.  
  138.     public function add_meta_field_group( $field_groups ) {
  139.  
  140.         $field_groups['wp_ultimo'] = array(
  141.             'title'  => 'WP Ultimo',
  142.             'fields' => array(),
  143.         );
  144.  
  145.         return $field_groups;
  146.  
  147.     }
  148.  
  149.  
  150.     /**
  151.      * Adds WP Ultimo meta fields to WPF contact fields list
  152.      *
  153.      * @access  public
  154.      * @return  array Meta Fields
  155.      */
  156.  
  157.     public function prepare_meta_fields( $meta_fields ) {
  158.  
  159.         $meta_fields['blog_title'] = array(
  160.             'label' => 'Site Title',
  161.             'type'  => 'text',
  162.             'group' => 'wp_ultimo',
  163.         );
  164.         $meta_fields['blogname']   = array(
  165.             'label' => 'Site URL',
  166.             'type'  => 'text',
  167.             'group' => 'wp_ultimo',
  168.         );
  169.  
  170.         return $meta_fields;
  171.  
  172.     }
  173.  
  174.     /**
  175.      * Register options tab
  176.      *
  177.      * @access public
  178.      * @return array Options tabs
  179.      */
  180.  
  181.     public function add_options_tab( $tabs ) {
  182.  
  183.         $tabs['wp_fusion'] = 'WP Fusion';
  184.  
  185.         return $tabs;
  186.  
  187.     }
  188.  
  189.     /**
  190.      * Output options tab
  191.      *
  192.      * @access public
  193.      * @return mixed Settings output
  194.      */
  195.  
  196.     public function options_tab( $plan ) {
  197.  
  198.         $settings = array(
  199.             'apply_tags' => array(),
  200.             'tag_link'   => array(),
  201.         );
  202.  
  203.         if ( get_post_meta( $plan->id, 'wpf_settings_wu', true ) ) {
  204.             $settings = array_merge( $settings, get_post_meta( $plan->id, 'wpf_settings_wu', true ) );
  205.         }
  206.  
  207.         ?>
  208.  
  209.         <div id="wu_wp_fusion" class="panel wu_options_panel" style="display: none;">
  210.  
  211.         <div class="options_group">
  212.             <p class="form-field">
  213.                 <label><?php _e( 'Apply Tags', 'wp-fusion' ); ?></label>
  214.  
  215.                 <?php
  216.  
  217.                 $args = array(
  218.                     'setting'   => $settings['apply_tags'],
  219.                     'meta_name' => 'wpf_settings_wu',
  220.                     'field_id'  => 'apply_tags',
  221.                 );
  222.  
  223.                 wpf_render_tag_multiselect( $args );
  224.  
  225.                 ?>
  226.  
  227.                 <span class="description"><?php echo sprintf( __( 'The selected tags will be applied in %s when someone registers with this plan.', 'wp-fusion' ), wp_fusion()->crm->name ); ?></span>
  228.  
  229.             </p>
  230.  
  231.             <?php
  232.             /*
  233.  
  234.             <p class="form-field">
  235.                 <label><?php _e( 'Link with Tag', 'wp-fusion' ); ?></label>
  236.  
  237.                 <?php
  238.  
  239.                 $args = array(
  240.                     'setting'     => $settings['tag_link'],
  241.                     'meta_name'   => 'wpf_settings_wu',
  242.                     'field_id'    => 'tag_link',
  243.                     'limit'       => 1,
  244.                     'placeholder' => __( 'Select tag' ),
  245.                 );
  246.  
  247.                 wpf_render_tag_multiselect( $args );
  248.  
  249.                 ?>
  250.  
  251.                 <span class="description"><?php echo sprintf( __( 'This tag will be applied in %s when someone registers with this plan. Likewise, if this tag is applied in %s, the user will automatically be enrolled in this plan. If the tag is removed the user will be unenrolled.', 'wp-fusion' ), wp_fusion()->crm->name, wp_fusion()->crm->name ); ?></span>
  252.  
  253.             </p>
  254.  
  255.             */
  256.             ?>
  257.  
  258.         </div>
  259.  
  260.         <?php
  261.  
  262.     }
  263.  
  264.     /**
  265.      * Save WPF settings
  266.      *
  267.      * @access public
  268.      * @return void
  269.      */
  270.  
  271.     public function save_post( $post_id ) {
  272.  
  273.         if ( ! empty( $_POST['wpf_settings_wu'] ) ) {
  274.             update_post_meta( $post_id, 'wpf_settings_wu', $_POST['wpf_settings_wu'] );
  275.         } else {
  276.             delete_post_meta( $post_id, 'wpf_settings_wu' );
  277.         }
  278.  
  279.     }
  280.  
  281.  
  282. }
  283.  
  284. new WPF_WP_Ultimo();
  285.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement