Advertisement
M4HD1BD

class-data-controller

Dec 1st, 2021
811
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 31.54 KB | None | 0 0
  1. <?php
  2. defined('ABSPATH') || die('Direct access is not allowed.');
  3. /**
  4.  * @since 1.7.4
  5.  * @package Directorist
  6.  */
  7. if (!class_exists('ATPP_Data_Controller')) :
  8.    
  9.     class ATPP_Data_Controller
  10.     {
  11.         public $meta = [];
  12.         public $need_payment = false;
  13.         public function __construct()
  14.         {
  15.             add_action('add_meta_boxes', array($this, 'atpp_add_meta_boxes'));
  16.             add_action('save_post', array($this, 'atpp_save_meta_data'));
  17.             add_filter('atbdp_listing_form_submission_info', array($this, 'atpp_process_the_selected_plans'));
  18.             add_action('atbdp_before_processing_submitted_listing_frontend', array($this, 'validate_submission'));
  19.             add_action('atbdp_order_status_changed', array($this, 'atpp_order_status_changed'), 10, 3);
  20.             add_action('atbdp_before_renewal', array($this, 'atpp_before_renewal'));
  21.             add_filter('atbdp_ultimate_listing_meta_user_submission', array($this, 'listing_meta_user_submission'), 10, 2);
  22.             add_filter('postbox_classes_atbdp_pricing_plans_atbdp-plan-details', array($this, 'add_metabox_classes') );
  23.             add_filter('postbox_classes_atbdp_pricing_plans_directorist-plan-field-details', array($this, 'add_metabox_classes') );
  24.             add_filter('postbox_classes_atbdp_pricing_plans_atbdp-directory-type', array($this, 'add_metabox_type_classes') );
  25.  
  26.             add_action('after_delete_post', array($this, 'update_listing_order'), 10, 2 );
  27.             add_action('trashed_post', array($this, 'update_listing_order_status') );
  28.             add_action('directorist_listing_deleted', array($this, 'update_listing_order_status') );
  29.  
  30.            
  31.         }
  32.  
  33.         public function update_listing_order_status( $post_id ){
  34.             if( ATBDP_POST_TYPE === get_post_type( $post_id ) ){
  35.                 $this->update_order_status( $post_id );
  36.             }
  37.         }
  38.  
  39.         public function update_listing_order( $post_id, $post ){
  40.             if( ATBDP_POST_TYPE === get_post_type( $post_id ) ){
  41.                 $this->update_order_status( $post_id );
  42.             }
  43.         }
  44.  
  45.         public function update_order_status( $post_id ){
  46.             $order_id = get_post_meta( $post_id, '_plan_order_id', true );
  47.             $legacy_order_id = get_post_meta( $post_id, '_plan_order_id', true );
  48.             $$order_id = $order_id ? $order_id : $legacy_order_id;
  49.                 if( ! empty( $order_id ) ){
  50.                     update_post_meta( $order_id, '_order_status', '' );
  51.                 }
  52.         }
  53.  
  54.         public function add_metabox_type_classes( $classes ) {
  55.  
  56.             array_push( $classes, 'directorist_postbox' );
  57.             array_push( $classes, 'directorist_postbox_directory_types' );
  58.  
  59.             return $classes;
  60.         }
  61.  
  62.         public function add_metabox_classes( $classes ) {
  63.  
  64.             array_push( $classes, 'directorist_postbox' );
  65.  
  66.             return $classes;
  67.         }
  68.  
  69.         public function listing_meta_user_submission( $meta, $info ) {
  70.             $meta['_listing_type'] = !empty( $info['listing_type'] ) ? sanitize_text_field( $info['listing_type'] ) : '';
  71.             return $meta;
  72.         }
  73.    
  74.                 /**
  75.          * @since 1.3.2
  76.          */
  77.  
  78.         public function atpp_before_renewal($listing_id)
  79.         {
  80.             update_post_meta( $listing_id, '_refresh_renewal_token', 1 );
  81.             update_post_meta($listing_id, '_renew_with_plan', 1);
  82.             $url = add_query_arg('renew_with_plan', $listing_id, ATBDP_Permalink::get_dashboard_page_link());
  83.             wp_safe_redirect( $url );
  84.             exit;
  85.         }
  86.  
  87.         public function atpp_order_status_changed($new_status, $old_status, $order_id)
  88.         {
  89.             $user_id = get_current_user_id();
  90.             $new_l_status = 'pending';
  91.             $listing_id = get_post_meta($order_id, '_listing_id', true);
  92.             if ('completed' === $new_status) {
  93.                 if( ! empty( $listing_id ) ){
  94.                     if( is_array( $listing_id ) && count( $listing_id ) > 1 ){
  95.                         foreach( $listing_id as $id ){
  96.  
  97.                             $directory_type = get_post_meta( $id, '_directory_type', true );
  98.                             if ( $directory_type ) {
  99.                                 $new_l_status = get_term_meta( $directory_type, 'new_listing_status', true );
  100.                             }
  101.  
  102.                             atpp_need_listing_to_refresh( $user_id, $id, $order_id );
  103.                             wp_update_post(array(
  104.                                 'ID'    =>  $id,
  105.                                 'post_status'   =>  apply_filters( 'atpp_reviewed_listing_status_controller_argument', $new_l_status ),
  106.                             ));
  107.                         }
  108.                     }else{
  109.                         $directory_type = get_post_meta( $listing_id, '_directory_type', true );
  110.                         if ( $directory_type ) {
  111.                             $new_l_status = get_term_meta( $directory_type, 'new_listing_status', true );
  112.                         }
  113.                         atpp_need_listing_to_refresh($user_id, $listing_id, $order_id);
  114.                         wp_update_post(array(
  115.                             'ID'    =>  $listing_id,
  116.                             'post_status'   =>  apply_filters( 'atpp_reviewed_listing_status_controller_argument', $new_l_status ),
  117.                         ));
  118.                     }
  119.                 }
  120.             }
  121.         }
  122.  
  123.         public function validate_submission( $info ){
  124.  
  125.             $is_editing = (  ! empty( $info['edited_listing'] ) ) ? true : false;
  126.             $error      = [];
  127.             $data       = [];
  128.  
  129.             if( ! $is_editing ){
  130.  
  131.                 $plan_id            = isset( $info['plan_id'] ) ? $info['plan_id'] : '';
  132.                 $listing_type       = isset( $info['listing_type'] ) ? $info['listing_type'] : '';
  133.                 $activated_order    = !empty( $info['activated_order'] ) ? $info['activated_order'] : '';
  134.                 $plan_type          = package_or_PPL($plan_id);
  135.  
  136.                 $plan_purchased     = subscribed_package_or_PPL_plans( get_current_user_id(), 'completed', $plan_id );
  137.                 $order_id           = !empty( $activated_order ) ? $activated_order : $plan_purchased[0]->ID;
  138.  
  139.                 if( $order_id ){
  140.                     $remaining          = plans_remaining( $plan_id, $order_id );
  141.                     $featured           = $remaining['featured'];
  142.                     $regular            = $remaining['regular'];
  143.    
  144.                     $package_length     = directorist_plan_lifetime( $plan_id );
  145.                     $package_length     = $package_length ? $package_length : '1';
  146.                     // Current time
  147.                     $start_date         = get_the_date( '', $order_id );
  148.                     // Calculate new date
  149.                     $date               = new DateTime($start_date);
  150.                     $date->add(new DateInterval("P{$package_length}D")); // set the interval in days
  151.                     $expired_date       = $date->format('Y-m-d H:i:s');
  152.                     $current_d          = current_time('mysql');
  153.                     $remaining_days     = ($expired_date > $current_d) ? (floor(strtotime($expired_date) / (60 * 60 * 24)) - floor(strtotime($current_d) / (60 * 60 * 24))) : 0; //calculate the number of days remaining in a plan
  154.    
  155.                     $regular_exit       = ( 'Unlimited' !== $regular ) && empty( $regular ) ? true : false;
  156.                     $featured_exit      = ( 'Unlimited' !== $featured ) && empty( $featured ) ? true : false;
  157.    
  158.                     // wp_send_json([
  159.                     //     'boll' =>  $regular_exit && ( $featured_exit )  || ($remaining_days < 0),
  160.                     //     'featured_exit' => $featured_exit,
  161.                     //     'regular_exit' => $regular_exit,
  162.                     //     'remaining_days' => $remaining_days,
  163.                     // ]);
  164.                     if ( ( $regular_exit &&  $featured_exit )  || ( $remaining_days < 0 ) ) {
  165.                         $msg = __('You have crossed the limit! Please try again', 'directorist-pricing-plans');
  166.                         if (('pay_per_listng' != $plan_type)) {
  167.                             update_post_meta($order_id, '_order_status', 'exit');
  168.                             $this->need_payment = true;
  169.                         }
  170.                     }else{
  171.                         if ( ( 'regular' === $listing_type ) && ( 'package' === $plan_type ) ) {
  172.                             if ( $regular_exit ) {
  173.                                 $msg = __('You have already crossed your limit for regular listing, please try again.', 'directorist-pricing-plans');
  174.                                 array_push( $error, $msg );
  175.                             }
  176.                         }
  177.                        
  178.                         if (('featured' === $listing_type) && ('package' === $plan_type)) {
  179.                             if ( $featured_exit ) {
  180.                                 $msg =  __('You have already crossed your limit for featured listing, please try again', 'directorist-pricing-plans');
  181.                                 array_push( $error, $msg );
  182.                             }
  183.                         }
  184.                     }
  185.    
  186.                     if( $error ) {
  187.                         $data['error_msg'] = $error;
  188.                         $data['error'] = true;
  189.                         wp_send_json( $data );
  190.                     }
  191.                 }
  192.                
  193.             }
  194.         }
  195.  
  196.         /**
  197.         * @return mixed     validate data and handle errors
  198.         * @since     1.8.0
  199.         * @param     string      $info    all submitted data.
  200.         */
  201.         public function atpp_process_the_selected_plans( $data )
  202.         {
  203.             $info = $_POST;
  204.             $error = [];
  205.             $skip_payment = false;
  206.             $listing_id = $data['id'];
  207.             if ( ! get_directorist_option( 'fee_manager_enable', 1 ) ) return $data;
  208.  
  209.             $is_editing = (  ! empty( $data['edited_listing'] ) ) ? true : false;
  210.            
  211.             $user_id = get_current_user_id();
  212.             $old_plan_id = get_post_meta( $listing_id, '_fm_plans', true);
  213.             $listing_type = isset( $info['listing_type'] ) ? $info['listing_type'] : '';
  214.             $plan_id = isset( $info['plan_id'] ) ? $info['plan_id'] : $old_plan_id;
  215.             $activated_order = !empty( $info['activated_order'] ) ? $info['activated_order'] : '';
  216.             $plan_type = package_or_PPL($plan_id);
  217.  
  218.             $plan_purchased = subscribed_package_or_PPL_plans( $user_id, 'completed', $plan_id );
  219.  
  220.             $order_id = !empty( $activated_order ) ? $activated_order : $plan_purchased[0]->ID;
  221.             $order_plan = get_post_meta( $order_id, '_listing_id', true );
  222.             if( directorist_direct_purchase() && ( 'package' !== $plan_type ) && empty( $order_plan ) && $plan_purchased ){
  223.                 $skip_payment = true;
  224.                 update_post_meta( $order_id, '_listing_id', $listing_id );
  225.                 update_post_meta( $listing_id, '_plan_order_id', $order_id );
  226.                 update_post_meta( $listing_id, '_listing_order_id', $order_id );
  227.             }
  228.  
  229.             if( ( 'package' === $plan_type ) && $plan_purchased ){
  230.                 update_post_meta( $order_id, '_listing_id', [ $listing_id ] );
  231.                 update_post_meta( $listing_id, '_plan_order_id', $order_id );
  232.                 update_post_meta( $listing_id, '_listing_order_id', $order_id );
  233.             }
  234.  
  235.             update_post_meta( $listing_id, '_fm_plans', $plan_id );
  236.  
  237.  
  238.             if ( ! $order_id  || $this->need_payment ) {
  239.                 $data['redirect_url'] = ATBDP_Permalink::get_checkout_page_link($listing_id);
  240.                 $data['need_payment'] = true;
  241.  
  242.                 wp_update_post([
  243.                     'ID' => $listing_id,
  244.                     'post_status' => 'pending',
  245.                 ]);
  246.             }
  247.  
  248.             if ( $is_editing ) {
  249.                 return $data;
  250.             }
  251.                
  252.             $package_length = directorist_plan_lifetime( $plan_id );
  253.             $package_length = $package_length ? $package_length : '1';
  254.            
  255.            
  256.  
  257.             $current_d = current_time('mysql');
  258.             // Calculate new date
  259.             $date = new DateTime($current_d);
  260.             $date->add(new DateInterval("P{$package_length}D")); // set the interval in days
  261.             $expired_date = $date->format('Y-m-d H:i:s');
  262.             $is_never_expaired = get_post_meta($plan_id, 'fm_length_unl', true);
  263.             if ($is_never_expaired) {
  264.                 array_push( $this->meta, [ '_plan_order_id' => $order_id ] );
  265.                 update_post_meta($listing_id, '_never_expire', '1');
  266.             } else {
  267.                 update_post_meta($listing_id, '_never_expire', 0);
  268.                 update_post_meta($listing_id, '_expiry_date', $expired_date);
  269.             }
  270.  
  271.             if ( 'featured' == $listing_type ) {
  272.                 update_post_meta( $listing_id, '_featured', '1' );
  273.             }
  274.            
  275.             update_post_meta($listing_id, '_need_to_refresh', '1');
  276.             // for dev
  277.             do_action('atbdp_plan_assigned', $listing_id);
  278.          
  279.             // update the claim status
  280.             $fm_claim = get_post_meta($plan_id, '_fm_claim', true);
  281.             if (!empty($fm_claim)) {
  282.                 update_post_meta($listing_id, '_claimed_by_admin', 1);
  283.             }
  284.  
  285.             if ('pay_per_listng' === package_or_PPL($plan_id)) {
  286.  
  287.                 if (PPL_with_featured($plan_id)) {
  288.                     update_post_meta($listing_id, '_featured', '1');
  289.                 }
  290.                 if( ! $plan_purchased ){
  291.                     $data['redirect_url'] = ATBDP_Permalink::get_checkout_page_link($listing_id);
  292.                     $data['need_payment'] = true;
  293.                     return $data;
  294.                 }
  295.             }
  296.            
  297.             if( $error ) {
  298.                 $data['error_msg'] = $error;
  299.                 $data['error'] = true;
  300.             }
  301.  
  302.             $payment_status = Directorist\Helper::get_listing_payment_status( $listing_id );
  303.             $rejectable_payment_status = [ 'failed', 'cancelled', 'refunded' ];
  304.             $need_payment = ( empty( $payment_status ) || in_array( $payment_status, $rejectable_payment_status ) ) ? true : false;
  305.  
  306.             if ( $need_payment && ! $skip_payment ) {
  307.                 $data['redirect_url'] = ATBDP_Permalink::get_checkout_page_link($listing_id);
  308.                 $data['need_payment'] = true;
  309.  
  310.                 wp_update_post([
  311.                     'ID' => $listing_id,
  312.                     'post_status' => 'pending',
  313.                 ]);
  314.             }
  315.             // return [
  316.             //     'need_payment' => $need_payment,
  317.             //     'skip_payment' => $skip_payment,
  318.             //     'payment_status' => $payment_status,
  319.             // ];
  320.            
  321.             return $data;
  322.         }
  323.  
  324.  
  325.         private function save_listing_meta( $post_id ){
  326.             $p          = $_POST;
  327.             $exp_dt     = !empty($p['exp_date']) ? atbdp_sanitize_array($p['exp_date']) : array();
  328.             $directory  = get_post_meta( $post_id, '_directory_type', true );
  329.             $expiration = get_term_meta( $directory, 'default_expiration', true );
  330.  
  331.             if (!is_empty_v($exp_dt) && !empty($exp_dt['aa'])){
  332.                 $exp_dt = array(
  333.                     'year'  => (int) $exp_dt['aa'],
  334.                     'month' => (int) $exp_dt['mm'],
  335.                     'day'   => (int) $exp_dt['jj'],
  336.                     'hour'  => (int) $exp_dt['hh'],
  337.                     'min'   => (int) $exp_dt['mn']
  338.                 );
  339.                 $exp_dt = get_date_in_mysql_format($exp_dt);
  340.             }else{
  341.                 $exp_dt = calc_listing_expiry_date( '', $expiration ); // get the expiry date in mysql date format using the default expiration date.
  342.             }
  343.             update_post_meta( $post_id, '_expiry_date', $exp_dt );
  344.  
  345.         }
  346.  
  347.  
  348.                 /*
  349.             * save data to database from the metaboxes
  350.             */
  351.  
  352.             public function atpp_save_meta_data($post_id)
  353.             {
  354.                 if( ! isset( $_POST['post_type'] ) ) {
  355.                     return $post_id;
  356.                 }
  357.                
  358.                 // If this is an autosave, our form has not been submitted, so we don't want to do anything
  359.                 if( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
  360.                     return $post_id;
  361.                 }
  362.                
  363.                 // Check the logged in user has permission to edit this post
  364.                 if( ! current_user_can( 'edit_post', $post_id ) ) {
  365.                     return $post_id;
  366.                 }
  367.  
  368.                 if ( !is_admin() ) {
  369.                     return $post_id;
  370.                 }
  371.  
  372.                 if( $_POST['post_type'] === 'at_biz_dir' ){
  373.                    
  374.                     $plan_id        = get_post_meta( $post_id, '_fm_plans', true );
  375.                     $admin_plan     = isset($_POST['admin_plan']) ? $_POST['admin_plan'] : '';
  376.                     $user_id        = isset($_POST['post_author_override']) ? $_POST['post_author_override'] : '';
  377.                     // $sub_plan_id    = get_post_meta($post_id, '_fm_plans', true);
  378.                     $order_id       = get_post_meta($post_id, '_plan_order_id', true);
  379.                
  380.                     update_post_meta($post_id, '_fm_plans_by_admin', 1);
  381.  
  382.                     if( 'null' === $admin_plan ){
  383.                         $this->save_listing_meta( $post_id );
  384.                     }else{
  385.                         atpp_need_listing_to_refresh( $user_id, $post_id, $order_id );
  386.                     }
  387.  
  388.                     if ('pay_per_listng' === package_or_PPL( $plan_id )) {
  389.                        
  390.                         if (PPL_with_featured( $plan_id )) {
  391.                             update_post_meta($post_id, '_featured', '1');
  392.                         }else{
  393.                             update_post_meta($post_id, '_featured', '');
  394.                         }
  395.                     }
  396.                 }
  397.                
  398.                 // Check if "atbdp_fee_details_nonce" nonce is set
  399.                 if( isset( $_POST['atbdp_fee_details_nonce'] ) ) {
  400.                
  401.                     // Verify that the nonce is valid
  402.                     if( wp_verify_nonce( $_POST['atbdp_fee_details_nonce'], 'atbdp_save_fee_details' ) ) {
  403.                
  404.                
  405.                         // OK to save meta data
  406.                         $assign_to_directory =  !empty($_POST['assign_to_directory']) ? $_POST['assign_to_directory'] : default_directory_type();
  407.                         update_post_meta($post_id, '_assign_to_directory', $assign_to_directory);
  408.  
  409.                         $plan_type =  !empty($_POST['plan_type'])?$_POST['plan_type']:'';
  410.                         update_post_meta($post_id, 'plan_type', $plan_type);
  411.                
  412.                         $free_plan =  !empty($_POST['free_plan'])?$_POST['free_plan']:'';
  413.                         update_post_meta($post_id, 'free_plan', $free_plan);
  414.  
  415.                         $fm_price =  !empty($_POST['fm_price'])?$_POST['fm_price']:'';
  416.                         update_post_meta($post_id, 'fm_price', $fm_price);
  417.                
  418.                         $plan_tax = isset($_POST['plan_tax']) ? $_POST['plan_tax'] : '0';
  419.                         update_post_meta($post_id, 'plan_tax', $plan_tax);
  420.  
  421.                         $plan_tax_type = isset($_POST['plan_tax_type']) ? $_POST['plan_tax_type'] : '0';
  422.                         update_post_meta($post_id, 'plan_tax_type', $plan_tax_type);
  423.  
  424.                         $fm_tax = isset($_POST['fm_tax']) ? $_POST['fm_tax'] : '0';
  425.                         update_post_meta($post_id, 'fm_tax', $fm_tax);
  426.                
  427.                         $hide_description = isset($_POST['hide_description'])?sanitize_textarea_field($_POST['hide_description']):'';
  428.                         update_post_meta($post_id, 'hide_description', $hide_description);
  429.                
  430.                         $fm_description = isset($_POST['fm_description'])?sanitize_textarea_field($_POST['fm_description']):'';
  431.                         update_post_meta($post_id, 'fm_description', $fm_description);
  432.                
  433.                         $fm_length = isset($_POST['fm_length']) ? (int)$_POST['fm_length'] : '0';
  434.                         update_post_meta($post_id, 'fm_length', $fm_length);
  435.                
  436.                         $fm_length_unl = isset($_POST['fm_length_unl'])?sanitize_text_field($_POST['fm_length_unl']):'';
  437.                         update_post_meta($post_id, 'fm_length_unl', $fm_length_unl);
  438.                
  439.                         $atpp_recurring = isset($_POST['atpp_recurring'])?sanitize_text_field($_POST['atpp_recurring']):'';
  440.                         update_post_meta($post_id, '_atpp_recurring', $atpp_recurring);
  441.  
  442.                         $hide_recurring = isset($_POST['hide_recurring'])?sanitize_text_field($_POST['hide_recurring']):'';
  443.                         update_post_meta($post_id, 'hide_recurring', $hide_recurring);
  444.                
  445.                        $recurrence_period_term = isset($_POST['recurrence_period_term'])?sanitize_text_field($_POST['recurrence_period_term']):'';
  446.                         update_post_meta($post_id, '_recurrence_period_term', $recurrence_period_term);
  447.                
  448.                         $recurrence_time = isset($_POST['recurrence_time'])?sanitize_text_field($_POST['recurrence_time']):'';
  449.                         update_post_meta($post_id, '_recurrence_time', $recurrence_time);
  450.                
  451.                         $is_featured_listing = isset($_POST['is_featured_listing'])?($_POST['is_featured_listing']):'';
  452.                         update_post_meta($post_id, 'is_featured_listing', $is_featured_listing);
  453.                
  454.                         $hide_listing_featured = isset($_POST['hide_listing_featured'])?($_POST['hide_listing_featured']):'';
  455.                         update_post_meta($post_id, 'hide_listing_featured', $hide_listing_featured);
  456.                
  457.                         $num_regular = isset($_POST['num_regular'])?(int)($_POST['num_regular']):'';
  458.                         update_post_meta($post_id, 'num_regular', $num_regular);
  459.                
  460.                         $hide_listings = isset($_POST['hide_listings'])?sanitize_text_field($_POST['hide_listings']):'';
  461.                         update_post_meta($post_id, 'hide_listings', $hide_listings);
  462.                
  463.                         $num_regular_unl = isset($_POST['num_regular_unl'])?sanitize_text_field($_POST['num_regular_unl']):'';
  464.                         update_post_meta($post_id, 'num_regular_unl', $num_regular_unl);
  465.                
  466.                         $num_featured = isset($_POST['num_featured'])?(int)($_POST['num_featured']):'';
  467.                         update_post_meta($post_id, 'num_featured', $num_featured);
  468.                
  469.                         $num_featured_unl = isset($_POST['num_featured_unl'])?sanitize_text_field($_POST['num_featured_unl']):'';
  470.                         update_post_meta($post_id, 'num_featured_unl', $num_featured_unl);
  471.                
  472.                         $hide_featured = isset($_POST['hide_featured'])?sanitize_text_field($_POST['hide_featured']):'';
  473.                         update_post_meta($post_id, 'hide_featured', $hide_featured);
  474.                          
  475.                         $default_pln = isset($_POST['default_pln'])?sanitize_text_field($_POST['default_pln']):'';
  476.                         update_post_meta($post_id, 'default_pln', $default_pln);
  477.                
  478.                         $hide_from_plans = isset($_POST['hide_from_plans'])?sanitize_text_field($_POST['hide_from_plans']):'';
  479.                         update_post_meta($post_id, '_hide_from_plans', $hide_from_plans);
  480.                
  481.                         $cf_owner = isset($_POST['cf_owner'])?sanitize_text_field($_POST['cf_owner']):'';
  482.                         update_post_meta($post_id, 'cf_owner', $cf_owner);
  483.                
  484.                         $hide_Cowner = isset($_POST['hide_Cowner'])?sanitize_text_field($_POST['hide_Cowner']):'';
  485.                         update_post_meta($post_id, 'hide_Cowner', $hide_Cowner);          
  486.                
  487.                         $fm_cs_review = isset($_POST['fm_cs_review'])?sanitize_text_field($_POST['fm_cs_review']):'';
  488.                         update_post_meta($post_id, 'fm_cs_review', $fm_cs_review);
  489.                
  490.                         $hide_review = isset($_POST['hide_review'])?sanitize_text_field($_POST['hide_review']):'';
  491.                         update_post_meta($post_id, 'hide_review', $hide_review);
  492.                
  493.                         $exclude_categories = isset($_POST['exclude_categories'])?sanitize_text_field($_POST['exclude_categories']):'';
  494.                         $exclude_cat = ($_POST['exclude_cat'] && $exclude_categories ) ? atbdp_sanitize_array($_POST['exclude_cat']) : array();
  495.                         update_post_meta($post_id, 'exclude_cat', $exclude_cat);
  496.                
  497.                         $hide_categories = isset($_POST['hide_categories'])?sanitize_text_field($_POST['hide_categories']):'';
  498.                         update_post_meta($post_id, 'hide_categories', $hide_categories);
  499.                
  500.                         $fm_claim = isset($_POST['fm_claim'])?sanitize_text_field($_POST['fm_claim']):'';
  501.                         update_post_meta($post_id, '_fm_claim', $fm_claim);
  502.                
  503.                         $hide_claim = isset($_POST['hide_claim'])?sanitize_text_field($_POST['hide_claim']):'';
  504.                         update_post_meta($post_id, '_hide_claim', $hide_claim);
  505.  
  506.                         // Booking
  507.                         $fm_booking = isset($_POST['fm_booking']) ? sanitize_text_field($_POST['fm_booking']) :'';
  508.                         update_post_meta($post_id, '_fm_booking', $fm_booking);
  509.                
  510.                         $hide_booking = isset($_POST['hide_booking']) ? sanitize_text_field($_POST['hide_booking']) :'';
  511.                         update_post_meta($post_id, '_hide_booking', $hide_booking);
  512.                        
  513.                         // Live Chat
  514.                         $fm_live_chat = isset($_POST['fm_live_chat']) ? sanitize_text_field($_POST['fm_live_chat']) : '';
  515.                         update_post_meta($post_id, '_fm_live_chat', $fm_live_chat);
  516.                
  517.                         $hide_live_chat = isset($_POST['hide_live_chat']) ? sanitize_text_field($_POST['hide_live_chat']) : '';
  518.                         update_post_meta($post_id, '_hide_live_chat', $hide_live_chat);
  519.                        
  520.                         // Mark as Sold
  521.                         $fm_mark_as_sold = isset($_POST['fm_mark_as_sold']) ? sanitize_text_field($_POST['fm_mark_as_sold']) : '';
  522.                         update_post_meta($post_id, '_fm_mark_as_sold', $fm_mark_as_sold);
  523.                
  524.                         $hide_mark_as_sold = isset($_POST['hide_mark_as_sold']) ? sanitize_text_field($_POST['hide_mark_as_sold']) : '';
  525.                         update_post_meta($post_id, '_hide_mark_as_sold', $hide_mark_as_sold);
  526.  
  527.                         if( !empty( $_POST['form_fields'] ) ) {
  528.                             foreach( $_POST['form_fields'] as $key => $value ) {
  529.                                 update_post_meta( $post_id, '_' . $key, $value );
  530.                             }
  531.                         }
  532.                
  533.                     }
  534.                 }
  535.                
  536.                 return $post_id;
  537.                
  538.    
  539.             }
  540.  
  541.            /**
  542.          * Register meta boxes for Pricing Plans.
  543.          *
  544.          * @since    1.0.0
  545.          * @access   public
  546.          */
  547.         public function atpp_add_meta_boxes()
  548.         {
  549.             $multi_directory = get_directorist_option( 'enable_multi_directory', false );
  550.             if( ( count( $this->directory_types() ) > 1 ) && ( $multi_directory ) ) {
  551.                 remove_meta_box('atbdp-directory-type', 'atbdp_pricing_plans', 'normal');
  552.                 add_meta_box('atbdp-directory-type', __('Select Type', 'directorist-pricing-plans'), array($this, 'directory_type_selection'), 'atbdp_pricing_plans', 'normal', 'high');
  553.             }
  554.             remove_meta_box('atbdp-plan-details', 'atbdp_pricing_plans', 'normal');
  555.             remove_meta_box('directorist-plan-field-details', 'atbdp_pricing_plans', 'normal');
  556.             remove_meta_box( 'slugdiv', 'atbdp_pricing_plans', 'normal' );
  557.            
  558.          
  559.            
  560.             add_meta_box('atbdp-plan-details', __('Basic Configurations', 'directorist-pricing-plans'), array($this, 'atbdp_meta_box_plan_details'), 'atbdp_pricing_plans', 'normal', 'high');
  561.             add_meta_box('directorist-plan-field-details', __('Field Configurations', 'directorist-pricing-plans'), array($this, 'atbdp_meta_box_plan_field_details'), 'atbdp_pricing_plans', 'advanced', 'default');
  562.         }
  563.  
  564.         public function directory_types() {
  565.             $listing_types = get_terms([
  566.                 'taxonomy'   => 'atbdp_listing_types',
  567.                 'hide_empty' => false,
  568.                 'orderby'    => 'date',
  569.                 'order'      => 'DSCE',
  570.               ]);
  571.               return $listing_types;
  572.         }
  573.  
  574.  
  575.         public function directory_type_selection( $post )
  576.         {
  577.             $listing_types   = $this->directory_types();
  578.             $default         = default_directory_type();
  579.             $current_type    =  get_post_meta( $post->ID, '_assign_to_directory', true );
  580.             $value           = $current_type ? $current_type : $default;
  581.               $data = [
  582.                    'post'               => $post,
  583.                    'directory_types'    => $listing_types,
  584.                    'value'              => $value,
  585.                 ];
  586.  
  587.             /**
  588.              * Display the "Field Details" meta box.
  589.              */
  590.             ATBDP_Pricing_Plans()->load_template('plan_directory_type', $data );
  591.  
  592.         }
  593.  
  594.         public function atbdp_meta_box_plan_details( $post )
  595.         {
  596.  
  597.             // Add a nonce field so we can check for it later
  598.             wp_nonce_field('atbdp_save_fee_details', 'atbdp_fee_details_nonce');
  599.             /**
  600.              * Display the "Field Details" meta box.
  601.              */
  602.             ATBDP_Pricing_Plans()->load_template('admin-meta-fields', [ 'post' => $post ] );
  603.  
  604.         }
  605.         public function atbdp_meta_box_plan_field_details( $post )
  606.         {
  607.             $multi_directory = get_directorist_option( 'enable_multi_directory', false );
  608.             $default         = default_directory_type();
  609.             $current_type    =  get_post_meta( $post->ID, '_assign_to_directory', true );
  610.             $value           = $current_type ? $current_type : $default;  
  611.               $data = [
  612.                    'post'           => $post,
  613.                    'default_type'   => !$multi_directory ? $default : $value,
  614.                    'post_meta'      => get_post_meta( $post->ID ),
  615.                 ];
  616.    
  617.             /**
  618.              * Display the "Field Details" meta box.
  619.              */
  620.             ?>
  621.             <div class="plan_dynamic_field">
  622.             <?php
  623.             $this::dynamic_plan_fields( $data );
  624.             ?>
  625.             </div>
  626.             <?php
  627.  
  628.         }
  629.  
  630.         public static function dynamic_plan_fields( $data ) {
  631.             ATBDP_Pricing_Plans()->load_template('admin-meta-form-fields', $data );
  632.         }
  633.  
  634.     }
  635. endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement