Plugin Directory

Changeset 2927437


Ignore:
Timestamp:
06/18/2023 01:32:40 AM (22 months ago)
Author:
ok9xnirab
Message:

v1.1 released

Location:
subscription
Files:
84 added
5 deleted
42 edited

Legend:

Unmodified
Added
Removed
  • subscription/trunk/assets/css/status.css

    r2797349 r2927437  
    11span.subscrpt-pending {
    2     background: #535050;
    3     color: white;
    4     text-transform: capitalize;
    5     padding: 8px;
     2  background: #535050;
     3  color: white;
     4  text-transform: capitalize;
     5  padding: 8px;
    66}
    77
    88span.subscrpt-active {
    9     background: green;
    10     color: white;
    11     text-transform: capitalize;
    12     padding: 8px;
     9  background: green;
     10  color: white;
     11  text-transform: capitalize;
     12  padding: 8px;
    1313}
    1414
    1515span.subscrpt-expired {
    16     background: red;
    17     color: white;
    18     text-transform: capitalize;
    19     padding: 8px;
     16  background: red;
     17  color: white;
     18  text-transform: capitalize;
     19  padding: 8px;
    2020}
    2121
    2222span.subscrpt-cancelled {
    23     background: #cecece;
    24     color: white;
    25     text-transform: capitalize;
    26     padding: 8px;
     23  background: #cecece;
     24  color: white;
     25  text-transform: capitalize;
     26  padding: 8px;
    2727}
     28
     29span.subscrpt-pe_cancelled {
     30  background: #ecb03e;
     31  color: white;
     32  text-transform: capitalize;
     33  padding: 8px;
     34}
  • subscription/trunk/assets/js/admin.js

    r2685408 r2927437  
    11jQuery(document).ready(() => {
    2     let sdevs_enable_subscription = jQuery("input#subscrpt_enable");
    3     sdevs_enable_subscription.change(() => {
    4         if (sdevs_enable_subscription.is(":checked")) {
    5             jQuery(".show_if_subscription").show();
    6         } else {
    7             jQuery(".show_if_subscription").hide();
    8         }
    9     });
     2  let sdevs_enable_subscription = jQuery("input#subscrpt_enable");
     3  sdevs_enable_subscription.change(() => {
    104    if (sdevs_enable_subscription.is(":checked")) {
    11         jQuery(".show_if_subscription").show();
     5      jQuery(".show_if_subscription").show();
    126    } else {
    13         jQuery(".show_if_subscription").hide();
     7      jQuery(".show_if_subscription").hide();
    148    }
     9  });
     10  if (sdevs_enable_subscription.is(":checked")) {
     11    jQuery(".show_if_subscription").show();
     12  } else {
     13    jQuery(".show_if_subscription").hide();
     14  }
    1515
    16     jQuery(document).on("woocommerce_variations_loaded", () => {
    17         let total_variations = JSON.parse(jQuery(".woocommerce_variations").attr("data-total"));
    18         for (let index = 0; index < total_variations; index++) {
    19             let element = document.getElementById("subscrpt_enable[" + index + "]");
    20             if (element && element.checked) {
    21                 jQuery("div#show_if_subscription_" + index).show();
    22             } else {
    23                 jQuery("div#show_if_subscription_" + index).hide();
    24             }
    25         }
    26     });
     16  jQuery(document).on("woocommerce_variations_loaded", () => {
     17    let total_variations = JSON.parse(
     18      jQuery(".woocommerce_variations").attr("data-total")
     19    );
     20    for (let index = 0; index < total_variations; index++) {
     21      let element = document.getElementById("subscrpt_enable[" + index + "]");
     22      if (element && element.checked) {
     23        jQuery("div#show_if_subscription_" + index).show();
     24      } else {
     25        jQuery("div#show_if_subscription_" + index).hide();
     26      }
     27    }
     28  });
     29
     30  let subscrpt_renewal_process = jQuery("#subscrpt_renewal_process");
     31  subscrpt_renewal_process.change(() => {
     32    if (subscrpt_renewal_process.val() === "manual") {
     33      jQuery("#sdevs_renewal_cart_tr").show();
     34    } else {
     35      jQuery("#sdevs_renewal_cart_tr").hide();
     36    }
     37  });
     38  if (subscrpt_renewal_process.val() === "manual") {
     39    jQuery("#sdevs_renewal_cart_tr").show();
     40  } else {
     41    jQuery("#sdevs_renewal_cart_tr").hide();
     42  }
    2743});
    2844
    2945function hellochange(index) {
    30     if (document.getElementById("subscrpt_enable[" + index + "]").checked) {
    31         jQuery("div#show_if_subscription_" + index).show();
     46  if (document.getElementById("subscrpt_enable[" + index + "]").checked) {
     47    jQuery("div#show_if_subscription_" + index).show();
     48  } else {
     49    jQuery("div#show_if_subscription_" + index).hide();
     50  }
     51}
     52
     53let subscrpt_product_type = jQuery("#product-type");
     54let latest_value_of_subscrpt_product_type = subscrpt_product_type.val();
     55
     56subscrpt_product_type.change(() => {
     57  if (
     58    "simple" === latest_value_of_subscrpt_product_type &&
     59    "simple" !== subscrpt_product_type.val() &&
     60    "variable" !== subscrpt_product_type.val()
     61  ) {
     62    const confirmTypeChange = confirm(
     63      "Are you sure to change the product type ? If product type changed then You'll lose related subscriptions beacuse of they can't be renewed !"
     64    );
     65    if (confirmTypeChange) {
     66      latest_value_of_subscrpt_product_type = subscrpt_product_type.val();
    3267    } else {
    33         jQuery("div#show_if_subscription_" + index).hide();
     68      subscrpt_product_type.val("simple");
    3469    }
    35 }
     70  }
     71});
  • subscription/trunk/includes/Admin.php

    r2797349 r2927437  
    1111use SpringDevs\Subscription\Admin\Subscriptions;
    1212use SpringDevs\Subscription\Illuminate\Comments;
    13 use SpringDevs\Subscription\Illuminate\Cron;
    1413use SpringDevs\Subscription\Illuminate\Email;
    1514use SpringDevs\Subscription\Illuminate\Order;
    16 use SpringDevs\Subscription\Illuminate\RegisterPostStatus;
    17 use SpringDevs\Subscription\Illuminate\Subscriptions as IlluminateSubscriptions;
    1815
    1916/**
    2017 * The admin class
    2118 */
    22 class Admin {
     19class Admin
     20{
    2321
    2422
     
    2624     * Initialize the class
    2725     */
    28     public function __construct() {
     26    public function __construct()
     27    {
    2928        $this->dispatch_actions();
    3029        new Required();
    31         new IlluminateSubscriptions();
    32         new Cron();
     30        new Illuminate();
    3331        new Menu();
    3432        new Product();
    3533        new Subscriptions();
    36         new RegisterPostStatus();
    3734        new Order();
    3835        new AdminOrder();
     
    4845     * @return void
    4946     */
    50     public function dispatch_actions() {
     47    public function dispatch_actions()
     48    {
    5149    }
    5250}
  • subscription/trunk/includes/Admin/Links.php

    r2797349 r2927437  
    1212class Links {
    1313
    14     public function __construct() {
     14    /**
     15     * Initialize the class
     16     */
     17    public function __construct() {
    1518        add_filter( 'plugin_action_links_' . plugin_basename( SUBSCRPT_FILE ), array( $this, 'plugin_action_links' ) );
    1619    }
    1720
    18     /**
     21    /**
    1922     * Add plugin action links
    2023     *
    21      * @param array $links array
     24     * @param array $links Plugin Links.
    2225     */
    2326    public function plugin_action_links( $links ) {
  • subscription/trunk/includes/Admin/Menu.php

    r2708268 r2927437  
    1010class Menu {
    1111
     12    /**
     13     * Initialize the class
     14     */
    1215    public function __construct() {
    1316        add_action( 'admin_menu', array( $this, 'create_admin_menu' ) );
    1417    }
    1518
     19    /**
     20     * Create Subscriptions Menu.
     21     */
    1622    public function create_admin_menu() {
    1723        $parent_slug = 'edit.php?post_type=subscrpt_order';
  • subscription/trunk/includes/Admin/Order.php

    r2708268 r2927437  
    22
    33namespace SpringDevs\Subscription\Admin;
     4
     5use SpringDevs\Subscription\Illuminate\Helper;
    46
    57/**
     
    1012class Order {
    1113
     14    /**
     15     * Initialize the class
     16     */
    1217    public function __construct() {
    1318        add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
    1419    }
    1520
     21    /**
     22     * Related Subscriptions meta box on Orders.
     23     */
    1624    public function add_meta_boxes() {
    17         $order_id   = get_the_ID();
    18         $order_meta = get_post_meta( $order_id, '_order_subscrpt_data', true );
    19         if ( ! empty( $order_meta ) && is_array( $order_meta ) && isset( $order_meta['status'] ) ) {
     25        $order_id  = get_the_ID();
     26        $histories = Helper::get_subscriptions_from_order( $order_id );
     27        if ( is_array( $histories ) ) {
     28            $order = wc_get_order( $order_id );
    2029            add_meta_box(
    2130                'subscrpt_order_related',
     
    2433                'shop_order',
    2534                'normal',
    26                 'default'
     35                'default',
     36                array(
     37                    'histories' => $histories,
     38                    'order'     => $order,
     39                )
    2740            );
    2841        }
    2942    }
    3043
    31     public function subscrpt_order_related() {
    32         $order_id   = get_the_ID();
    33         $order_meta = get_post_meta( $order_id, '_order_subscrpt_data', true );
    34         if ( empty( $order_meta ) && ! is_array( $order_meta ) && ! isset( $order_meta['status'] ) ) {
    35             return;
    36         }
     44    /**
     45     * Display content related subscriptions.
     46     *
     47     * @param mixed $order_post Current Order.
     48     * @param mixed $info Meta box Info.
     49     */
     50    public function subscrpt_order_related( $order_post, $info ) {
     51        $histories = $info['args']['histories'];
     52        $order     = $info['args']['order'];
    3753
    3854        include 'views/related-subscriptions.php';
  • subscription/trunk/includes/Admin/Product.php

    r2797349 r2927437  
    1010class Product {
    1111
    12     public function __construct() {
    13         add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
    14         add_filter( 'product_type_options', array( $this, 'add_product_type_options' ) );
    15         add_action( 'woocommerce_product_options_general_product_data', array( $this, 'subscription_forms' ) );
    16         add_action( 'save_post_product', array( $this, 'save_subscrpt_data' ) );
    17     }
     12    /**
     13     * Initialize the class
     14     */
     15    public function __construct() {
     16        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
     17        add_filter( 'product_type_options', array( $this, 'add_product_type_options' ) );
     18        add_action( 'woocommerce_product_options_general_product_data', array( $this, 'subscription_forms' ) );
     19        add_action( 'save_post_product', array( $this, 'save_subscrpt_data' ) );
     20    }
    1821
    19     public function enqueue_assets() {
    20         wp_enqueue_script( 'sdevs_subscription_admin' );
    21     }
     22    /**
     23     * Enqueue Assets.
     24     */
     25    public function enqueue_assets() {
     26        wp_enqueue_script( 'sdevs_subscription_admin' );
     27    }
    2228
    23     public function add_product_type_options( $product_type_options ) {
    24         $screen = get_current_screen();
    25         $value  = 'no';
    26         if ( $screen->parent_base == 'edit' ) {
    27             $post_meta = get_post_meta( get_the_ID(), 'subscrpt_general', true );
    28             $value     = ! empty( $post_meta ) && $post_meta['enable'] ? 'yes' : 'no';
    29         }
     29    /**
     30     * Display Enable Subscription Checkbox on product data tab.
     31     *
     32     * @param array $product_type_options Product Type options on Data tab.
     33     *
     34     * @return array
     35     */
     36    public function add_product_type_options( $product_type_options ) {
     37        $screen = get_current_screen();
     38        $value  = 'no';
     39        if ( 'edit' === $screen->parent_base ) {
     40            $post_meta = get_post_meta( get_the_ID(), '_subscrpt_meta', true );
     41            $value     = ! empty( $post_meta ) && $post_meta['enable'] ? 'yes' : 'no';
     42        }
    3043
    31         $wrapper_class                           = apply_filters( 'subscrpt_simple_enable_checkbox_classes', 'show_if_simple' );
    32         $product_type_options['subscrpt_enable'] = array(
    33             'id'            => 'subscrpt_enable',
    34             'wrapper_class' => $wrapper_class,
    35             'label'         => __( 'Subscription', 'sdevs_subscrpt' ),
    36             'description'   => __( 'Enable Subscriptions', 'sdevs_subscrpt' ),
    37             'default'       => $value,
    38         );
     44        $wrapper_class                           = apply_filters( 'subscrpt_simple_enable_checkbox_classes', 'show_if_simple' );
     45        $product_type_options['subscrpt_enable'] = array(
     46            'id'            => 'subscrpt_enable',
     47            'wrapper_class' => $wrapper_class,
     48            'label'         => __( 'Subscription', 'sdevs_subscrpt' ),
     49            'description'   => __( 'Enable Subscriptions', 'sdevs_subscrpt' ),
     50            'default'       => $value,
     51        );
    3952
    40         return $product_type_options;
    41     }
     53        return $product_type_options;
     54    }
    4255
    43     public function subscription_forms() {
    44         if ( function_exists( 'subscrpt_pro_activated' ) ) {
    45             if ( subscrpt_pro_activated() ) {
    46                 do_action( 'subscrpt_simple_pro_fields', get_the_ID() );
    47             } else {
    48                 $timing_types          = array(
    49                     'days'   => 'Daily',
    50                     'weeks'  => 'Weekly',
    51                     'months' => 'Monthly',
    52                     'years'  => 'Yearly',
    53                 );
    54                 $subscrpt_timing       = null;
    55                 $subscrpt_cart_txt     = 'subscribe';
    56                 $subscrpt_user_cancell = 'yes';
     56    /**
     57     * Display forms on product create/edit.
     58     */
     59    public function subscription_forms() {
     60        if ( function_exists( 'subscrpt_pro_activated' ) ) {
     61            if ( subscrpt_pro_activated() ) {
     62                do_action( 'subscrpt_simple_pro_fields', get_the_ID() );
     63            } else {
     64                $timing_types          = array(
     65                    'days'   => __( 'Daily', 'sdevs_subscrpt' ),
     66                    'weeks'  => __( 'Weekly', 'sdevs_subscrpt' ),
     67                    'months' => __( 'Monthly', 'sdevs_subscrpt' ),
     68                    'years'  => __( 'Yearly', 'sdevs_subscrpt' ),
     69                );
     70                $subscrpt_timing       = null;
     71                $subscrpt_cart_txt     = 'subscribe';
     72                $subscrpt_user_cancell = 'yes';
    5773
    58                 $screen = get_current_screen();
    59                 if ( $screen->parent_base == 'edit' ) {
    60                     $post_meta = get_post_meta( get_the_ID(), 'subscrpt_general', true );
    61                     if ( ! empty( $post_meta ) && is_array( $post_meta ) ) {
    62                         $subscrpt_timing       = $post_meta['type'];
    63                         $subscrpt_cart_txt     = $post_meta['cart_txt'];
    64                         $subscrpt_user_cancell = $post_meta['user_cancell'];
    65                     }
    66                 }
    67                 include 'views/product-form.php';
    68             }
    69         }
    70     }
     74                $screen = get_current_screen();
     75                if ( $screen->parent_base == 'edit' ) {
     76                    $post_meta = get_post_meta( get_the_ID(), '_subscrpt_meta', true );
     77                    if ( ! empty( $post_meta ) && is_array( $post_meta ) ) {
     78                        $subscrpt_timing       = $post_meta['type'];
     79                        $subscrpt_cart_txt     = $post_meta['cart_txt'];
     80                        $subscrpt_user_cancell = $post_meta['user_cancell'];
     81                    }
     82                }
     83                include 'views/product-form.php';
     84            }
     85        }
     86    }
    7187
    72     public function save_subscrpt_data( $post_id ) {
    73         if ( ! isset( $_POST['subscrpt_enable'] ) ) {
    74             return;
    75         }
    76         if ( function_exists( 'subscrpt_pro_activated' ) ) {
    77             if ( subscrpt_pro_activated() ) {
    78                 return;
    79             }
    80         }
    81         $subscrpt_enable       = (bool) $_POST['subscrpt_enable'];
    82         $subscrpt_time         = 1;
    83         $subscrpt_timing       = sanitize_text_field( $_POST['subscrpt_timing'] );
    84         $subscrpt_trial_time   = null;
    85         $subscrpt_trial_timing = null;
    86         $subscrpt_cart_txt     = sanitize_text_field( $_POST['subscrpt_cart_txt'] );
    87         $subscrpt_user_cancell = sanitize_text_field( $_POST['subscrpt_user_cancell'] );
    88         $data                  = array(
    89             'enable'       => $subscrpt_enable,
    90             'time'         => $subscrpt_time,
    91             'type'         => $subscrpt_timing,
    92             'trial_time'   => $subscrpt_trial_time,
    93             'trial_type'   => $subscrpt_trial_timing,
    94             'cart_txt'     => $subscrpt_cart_txt,
    95             'user_cancell' => $subscrpt_user_cancell,
    96         );
    97         update_post_meta( $post_id, 'subscrpt_general', $data );
    98     }
     88    public function save_subscrpt_data( $post_id ) {
     89        if ( ! isset( $_POST['subscrpt_enable'] ) ) {
     90            return;
     91        }
     92        if ( function_exists( 'subscrpt_pro_activated' ) ) {
     93            if ( subscrpt_pro_activated() ) {
     94                return;
     95            }
     96        }
     97        $subscrpt_enable       = (bool) $_POST['subscrpt_enable'];
     98        $subscrpt_time         = 1;
     99        $subscrpt_timing       = sanitize_text_field( $_POST['subscrpt_timing'] );
     100        $subscrpt_trial_time   = null;
     101        $subscrpt_trial_timing = null;
     102        $subscrpt_cart_txt     = sanitize_text_field( $_POST['subscrpt_cart_txt'] );
     103        $subscrpt_user_cancell = sanitize_text_field( $_POST['subscrpt_user_cancell'] );
     104        $data                  = array(
     105            'enable'       => $subscrpt_enable,
     106            'time'         => $subscrpt_time,
     107            'type'         => $subscrpt_timing,
     108            'trial_time'   => $subscrpt_trial_time,
     109            'trial_type'   => $subscrpt_trial_timing,
     110            'cart_txt'     => $subscrpt_cart_txt,
     111            'user_cancell' => $subscrpt_user_cancell,
     112        );
     113
     114        update_post_meta( $post_id, '_subscrpt_meta', $data );
     115    }
    99116}
  • subscription/trunk/includes/Admin/Settings.php

    r2708268 r2927437  
    1010class Settings {
    1111
     12    /**
     13     * Initialize the class.
     14     */
    1215    public function __construct() {
    1316        add_action( 'admin_menu', array( $this, 'admin_menu' ) );
     
    2124
    2225    /**
    23      * register settings options
     26     * Register settings options.
    2427     **/
    2528    public function register_settings() {
     29        register_setting( 'subscrpt_settings', 'subscrpt_renewal_process' );
     30        register_setting( 'subscrpt_settings', 'subscrpt_manual_renew_cart_notice' );
    2631        register_setting( 'subscrpt_settings', 'subscrpt_active_role' );
    2732        register_setting( 'subscrpt_settings', 'subscrpt_unactive_role' );
     
    2934    }
    3035
     36    /**
     37     * Settings HTML.
     38     */
    3139    public function settings_content() {
    3240        include 'views/settings.php';
  • subscription/trunk/includes/Admin/Subscriptions.php

    r2797349 r2927437  
    1212class Subscriptions {
    1313
     14    /**
     15     * Initialize the class.
     16     */
    1417    public function __construct() {
    1518        add_action( 'admin_enqueue_scripts', array( $this, 'custom_enqueue_scripts' ) );
     
    2528        add_action( 'save_post', array( $this, 'save_subscrpt_order' ) );
    2629        add_filter( 'woocommerce_order_item_get_formatted_meta_data', array( $this, 'remove_order_meta' ), 10, 1 );
     30        add_filter( 'bulk_actions-edit-subscrpt_order', array( $this, 'remove_bulk_actions' ) );
     31    }
     32
     33    public function remove_bulk_actions( $actions ) {
     34        unset( $actions['edit'] );
     35        return $actions;
    2736    }
    2837
     
    6574        $columns['subscrpt_status']     = __( 'Status', 'sdevs_subscrpt' );
    6675        unset( $columns['date'] );
     76        unset( $columns['cb'] );
    6777        return $columns;
    6878    }
    6979
    7080    public function add_custom_columns_data( $column, $post_id ) {
    71         $post_meta = get_post_meta( $post_id, '_subscrpt_order_general', true );
     81        $post_meta = get_post_meta( $post_id, '_order_subscrpt_meta', true );
    7282        $order     = wc_get_order( $post_meta['order_id'] );
    7383        if ( $order ) {
     
    8595                echo date( 'F d, Y', $post_meta['next_date'] );
    8696            } elseif ( $column == 'subscrpt_status' ) {
     97                $status_obj = get_post_status_object( get_post_status( $post_id ) );
    8798                ?>
    88                 <span class="subscrpt-<?php echo esc_html( get_post_status( $post_id ) ); ?>"><?php echo esc_html( get_post_status( $post_id ) ); ?></span>
     99                <span class="subscrpt-<?php echo esc_html( $status_obj->name ); ?>"><?php echo esc_html( $status_obj->label ); ?></span>
    89100                <?php
    90101            }
     
    94105    }
    95106
     107    /**
     108     * Create metaboxes for admin subscriptions.
     109     */
    96110    public function create_meta_boxes() {
    97111        remove_meta_box( 'submitdiv', 'subscrpt_order', 'side' );
    98         // Save Data
    99112        add_meta_box(
    100113            'subscrpt_order_save_post',
     
    144157
    145158    public function subscrpt_order_history() {
    146         $order_histories = get_post_meta( get_the_ID(), '_subscrpt_order_history', true );
    147         rsort( $order_histories );
     159        $subscription_id = get_the_ID();
     160        global $wpdb;
     161        $table_name = $wpdb->prefix . 'subscrpt_order_relation';
     162        // @phpcs:ignore
     163        $order_histories = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %i WHERE subscription_id=%d', array( $table_name, $subscription_id ) ) );
     164
    148165        include 'views/order-history.php';
    149166    }
     
    163180    }
    164181
     182    /**
     183     * Save subscription HTML.
     184     */
    165185    public function subscrpt_order_save_post() {
    166186        $actions = array(
     
    178198            ),
    179199            array(
     200                'label' => __( 'Pending Cancel Subscription', 'sdevs_subscrpt' ),
     201                'value' => 'pe_cancelled',
     202            ),
     203            array(
    180204                'label' => __( 'Cancel Subscription', 'sdevs_subscrpt' ),
    181205                'value' => 'cancelled',
     
    187211
    188212    public function subscrpt_customer_info() {
    189         $post_meta = get_post_meta( get_the_ID(), '_subscrpt_order_general', true );
     213        $post_meta = get_post_meta( get_the_ID(), '_order_subscrpt_meta', true );
    190214        $order     = wc_get_order( $post_meta['order_id'] );
    191215        if ( ! $order ) {
     
    196220
    197221    public function subscrpt_order_info() {
    198         $post_meta  = get_post_meta( get_the_ID(), '_subscrpt_order_general', true );
    199         $order_item = null;
    200         $order      = wc_get_order( $post_meta['order_id'] );
     222        $post_meta = get_post_meta( get_the_ID(), '_order_subscrpt_meta', true );
     223        $order     = wc_get_order( $post_meta['order_id'] );
    201224        if ( ! $order ) {
    202225            return;
    203226        }
    204         foreach ( $order->get_items() as $cart_item ) {
    205             if ( $cart_item['product_id'] == $post_meta['product_id'] ) {
    206                 $order_item = $cart_item;
    207                 break;
    208             }
    209         }
     227        $order_item = $order->get_item( $post_meta['order_item_id'] );
    210228        include 'views/subscription-order-info.php';
    211229    }
     
    263281        );
    264282
    265         $post_meta = get_post_meta( $post_id, '_subscrpt_order_general', true );
     283        $post_meta = get_post_meta( $post_id, '_order_subscrpt_meta', true );
    266284        if ( $action === 'active' ) {
    267285            $order = wc_get_order( $post_meta['order_id'] );
    268286            $order->update_status( 'completed' );
    269287        }
    270         $data = array(
    271             'post'    => $post_id,
    272             'product' => $post_meta['product_id'],
    273         );
    274         if ( isset( $post_meta['variation_id'] ) ) {
    275             $data['variation'] = $post_meta['variation_id'];
    276         }
    277         Action::status( $action, sanitize_text_field( $_POST['post_author'] ), $data );
     288
     289        Action::status( $action, $post_id );
    278290    }
    279291}
  • subscription/trunk/includes/Admin/views/order-history.php

    r2708268 r2927437  
    22    <thead>
    33        <tr>
    4             <th><?php _e( 'Order', 'sdevs_subscrpt' ); ?></th>
     4            <th><?php
     5
     6            use SpringDevs\Subscription\Illuminate\Helper;
     7
     8            _e( 'Order', 'sdevs_subscrpt' ); ?></th>
    59            <th></th>
    610            <th><?php _e( 'Date', 'sdevs_subscrpt' ); ?></th>
     
    1216        <?php foreach ( $order_histories as $order_history ) : ?>
    1317            <?php
    14             $order = wc_get_order( $order_history['order_id'] );
     18            $order      = wc_get_order( $order_history->order_id );
     19            $order_item = $order->get_item( $order_history->order_item_id );
    1520            ?>
    1621            <tr>
    17                 <td><a href="<?php echo wp_kses_post( get_edit_post_link( $order_history['order_id'] ) ); ?>" target="_blank"><?php echo wp_kses_post( $order_history['order_id'] ); ?></a></td>
    18                 <td><?php echo wp_kses_post( $order_history['stats'] ); ?></td>
     22                <td><a href="<?php echo wp_kses_post( get_edit_post_link( $order_history->order_id ) ); ?>" target="_blank"><?php echo wp_kses_post( $order_history->order_id ); ?></a></td>
     23                <td><?php echo wp_kses_post( order_relation_type_cast( $order_history->type ) ); ?></td>
    1924                <td>
    2025                    <?php
    2126                    if ( $order ) {
    22                         echo wp_kses_post( date( 'F d, Y', strtotime( $order->get_date_created() ) ) );}
     27                        echo wp_kses_post( gmdate( 'F d, Y', strtotime( $order->get_date_created() ) ) );}
    2328                    ?>
    2429                </td>
     
    2934                ?>
    3035                </td>
    31                 <td><?php echo wp_kses_post( $order_history['subtotal_price_html'] ); ?></td>
     36                <td><?php echo wp_kses_post( Helper::format_price_with_order_item( $order_item->get_total(), $order_item->get_id() ) ); ?></td>
    3237            </tr>
    3338        <?php endforeach; ?>
  • subscription/trunk/includes/Admin/views/product-form.php

    r2708268 r2927437  
    1 <div class="option_group sdevs-form sdevs_panel show_if_subscription hide" style="padding: 10px;">
     1<div class="option_group sdevs-form sdevs_panel show_if_simple hide" style="padding: 10px;">
     2<div class="show_if_subscription">
     3    <input name="_subscript_nonce" type="hidden" value="<?php echo esc_attr( wp_create_nonce( '_subscript_edit_product_nonce' ) ); ?>" />
    24    <strong style="margin: 10px;"><?php _e( 'Subscription Settings', 'sdevs_subscrpt' ); ?></strong>
    35    <?php
     
    4042    ?>
    4143</div>
     44</div>
  • subscription/trunk/includes/Admin/views/related-subscriptions.php

    r2708268 r2927437  
    33        <tr>
    44            <th></th>
    5             <th><?php _e( 'Started on', 'sdevs_subscrpt' ); ?></th>
     5            <th><?php
     6
     7            use SpringDevs\Subscription\Illuminate\Helper;
     8
     9            _e( 'Started on', 'sdevs_subscrpt' ); ?></th>
    610            <th><?php _e( 'Recurring', 'sdevs_subscrpt' ); ?></th>
    711            <th><?php _e( 'Expiry date', 'sdevs_subscrpt' ); ?></th>
     
    1115    <tbody>
    1216        <?php
    13         foreach ( $order_meta['posts'] as $post ) :
    14             if ( get_the_title( $post ) != '' ) :
    15                 $post_meta = get_post_meta( $post, '_subscrpt_order_general', true );
    16                 ?>
     17        foreach ( $histories as $history ) :
     18                $post_meta  = get_post_meta( $history->subscription_id, '_order_subscrpt_meta', true );
     19                $order_item = $order->get_item( $history->order_item_id );
     20            ?>
    1721                <tr>
    1822                    <td>
    19                         <a href="<?php echo wp_kses_post( get_edit_post_link( $post ) ); ?>" target="_blank">#<?php echo esc_html( $post ); ?> - <?php echo esc_html( get_the_title( $post_meta['product_id'] ) ); ?></a>
     23                        <a href="<?php echo wp_kses_post( get_edit_post_link( $history->subscription_id ) ); ?>" target="_blank">#<?php echo esc_html( $history->subscription_id ); ?> - <?php echo esc_html( $order_item->get_name() ); ?></a>
    2024                    </td>
    2125                    <td>
    2226                        <?php echo $post_meta['trial'] == null ? esc_html( date( 'F d, Y', $post_meta['start_date'] ) ) : '+' . esc_html( $post_meta['trial'] ) . ' ' . __( 'free trial', 'sdevs_subscrpt' ); ?>
    2327                    </td>
    24                     <td><?php echo wp_kses_post( $post_meta['total_price_html'] ); ?></td>
     28                    <td><?php echo wp_kses_post( Helper::format_price_with_order_item( $order_item->get_total(), $order_item->get_id() ) ); ?></td>
    2529                    <td><?php echo esc_html( $post_meta['trial'] == null ? date( 'F d, Y', $post_meta['next_date'] ) : date( 'F d, Y', $post_meta['start_date'] ) ); ?></td>
    26                     <td><?php echo esc_html( get_post_status( $post ) ); ?></td>
     30                    <td><?php echo esc_html( get_post_status( $history->subscription_id ) ); ?></td>
    2731                </tr>
    2832                <?php
    29         endif;
    3033        endforeach;
    3134        ?>
  • subscription/trunk/includes/Admin/views/settings.php

    r2708268 r2927437  
    11<div class="wrap">
    22    <?php settings_errors(); ?>
    3     <h1><?php _e( 'Subscription Settings', 'sdevs_subscrpt' ); ?></h1>
    4     <p><?php _e( 'These settings can effect Subscription', 'sdevs_subscrpt' ); ?></p>
     3    <h1><?php esc_html_e( 'Subscription Settings', 'sdevs_subscrpt' ); ?></h1>
     4    <p><?php esc_html_e( 'These settings can effect Subscription', 'sdevs_subscrpt' ); ?></p>
    55    <form method="post" action="options.php">
    66        <?php settings_fields( 'subscrpt_settings' ); ?>
     
    1010                <tr>
    1111                    <th scope="row">
     12                        <label for="subscrpt_renewal_process">
     13                            <?php esc_html_e( 'Renewal Process', 'sdevs_subscrpt' ); ?>
     14                        </label>
     15                    </th>
     16                    <td>
     17                        <select name="subscrpt_renewal_process" id="subscrpt_renewal_process"
     18                        <?php
     19                        if ( ! subscrpt_pro_activated() ) {
     20                            echo esc_attr( 'disabled' );}
     21                        ?>
     22                        >
     23                            <option value="auto">Automatic</option>
     24                            <option value="manual"
     25                            <?php
     26                            if ( ! subscrpt_pro_activated() || 'manual' === get_option( 'subscrpt_renewal_process', 'auto' ) ) {
     27                                echo esc_attr( 'selected' );
     28                            }
     29                            ?>
     30                            >Manual</option>
     31                        </select>
     32                        <?php if ( ! subscrpt_pro_activated() ) : ?>
     33                        <p style="color: red;" class="description"><?php echo wp_kses_post( '<b>Automatic</b> renewal is available for Pro version only !!' ); ?></p>
     34                        <?php else : ?>
     35                        <p class="description"><?php esc_html_e( 'How renewal process will be done after Subscription Expired !!', 'sdevs_subscrpt' ); ?></p>
     36                        <?php endif; ?>
     37                    </td>
     38                </tr>
     39                <tr id="sdevs_renewal_cart_tr">
     40                    <th scope="row">
     41                        <label for="subscrpt_manual_renew_cart_notice">
     42                            <?php esc_html_e( 'Renewal Cart Notice', 'sdevs_subscrpt' ); ?>
     43                        </label>
     44                    </th>
     45                    <td>
     46                        <input id="subscrpt_manual_renew_cart_notice" name="subscrpt_manual_renew_cart_notice" class="large-text" value="<?php echo wp_kses_post( get_option( 'subscrpt_manual_renew_cart_notice' ) ); ?>" type="text"/>
     47                        <p class="description"><?php echo wp_kses_post( 'Display Notice when Renewal Subscription product add to cart !! It\'s only available for <b>Manual Renewal Process</b>.', 'sdevs_subscrpt' ); ?></p>
     48                    </td>
     49                </tr>
     50                <tr>
     51                    <th scope="row">
    1252                        <label for="subscrpt_active_role">
    13                             <?php _e( 'Subscriber Default Role', 'sdevs_subscrpt' ); ?>
     53                            <?php esc_html_e( 'Subscriber Default Role', 'sdevs_subscrpt' ); ?>
    1454                        </label>
    1555                    </th>
     
    1858                            <?php wp_dropdown_roles( get_option( 'subscrpt_active_role', 'subscriber' ) ); ?>
    1959                        </select>
    20                         <p class="description"><?php _e( 'When a subscription is activated, either manually or after a successful purchase, new users will be assigned this role.', 'sdevs_subscrpt' ); ?></p>
     60                        <p class="description"><?php esc_html_e( 'When a subscription is activated, either manually or after a successful purchase, new users will be assigned this role.', 'sdevs_subscrpt' ); ?></p>
    2161                    </td>
    2262                </tr>
     
    2464                    <th scope="row">
    2565                        <label for="subscrpt_unactive_role">
    26                             <?php _e( 'Subscriber Unactive Role', 'sdevs_subscrpt' ); ?>
     66                            <?php esc_html_e( 'Subscriber Unactive Role', 'sdevs_subscrpt' ); ?>
    2767                        </label>
    2868                    </th>
     
    3171                            <?php wp_dropdown_roles( get_option( 'subscrpt_unactive_role', 'customer' ) ); ?>
    3272                        </select>
    33                         <p class="description"><?php _e( "If a subscriber's subscription is manually cancelled or expires, will be assigned this role.", 'sdevs_subscrpt' ); ?></p>
     73                        <p class="description"><?php esc_html_e( "If a subscriber's subscription is manually cancelled or expires, will be assigned this role.", 'sdevs_subscrpt' ); ?></p>
    3474                    </td>
    3575                </tr>
  • subscription/trunk/includes/Admin/views/subscription-order-info.php

    r2797349 r2927437  
    33        <tr>
    44            <?php
    5             $product_name = apply_filters( 'subscrpt_filter_product_name', get_the_title( $post_meta['product_id'] ), $post_meta );
    6             $product_link = apply_filters( 'subscrpt_filter_product_permalink', get_the_permalink( $post_meta['product_id'] ), $post_meta );
     5
     6            use SpringDevs\Subscription\Illuminate\Helper;
     7
     8            $product_name = $order_item->get_name();
     9            $product_link = get_the_permalink( $order_item->get_product_id() );
    710            ?>
    811            <th scope="row">Product : </th>
     
    1316        <tr>
    1417            <th scope="row">Cost : </th>
    15             <td><?php echo wp_kses_post( wc_price( $order->get_item_subtotal( $order_item, false, true ), array( 'currency' => $order->get_currency() ) ) ); ?></td>
     18            <td><?php echo wp_kses_post( Helper::format_price_with_order_item( $order_item->get_total(), $order_item->get_id() ) ); ?></td>
    1619        </tr>
    1720        <tr>
    1821            <th scope="row">Qty : </th>
    19             <td>x<?php echo esc_html( $post_meta['qty'] ); ?></td>
    20         </tr>
    21         <tr>
    22             <th scope="row">Amount : </th>
    23             <td><strong><?php echo wp_kses_post( $post_meta['subtotal_price_html'] ); ?></strong></td>
     22            <td>x<?php echo esc_html( $order_item->get_quantity() ); ?></td>
    2423        </tr>
    2524        <?php if ( ! empty( $post_meta['trial'] ) ) : ?>
     
    4342        <tr>
    4443            <th scope="row">Status:</th>
    45             <td><span class="subscrpt-<?php echo get_post_status(); ?>"><?php echo get_post_status(); ?></span></td>
     44            <td><span class="subscrpt-<?php echo get_post_status(); ?>"><?php echo get_post_status_object( get_post_status() )->label; ?></span></td>
    4645        </tr>
    4746        <tr>
  • subscription/trunk/includes/Admin/views/subscription-save-meta.php

    r2708268 r2927437  
    1         <p class="subscrpt_sub_box">
     1<p class="subscrpt_sub_box">
    22            <select id="subscrpt_order_type" name="subscrpt_order_action">
    3                 <option value=""><?php _e( 'choose action', 'sdevs_subscrpt' ); ?></option>
     3                <option value=""><?php esc_html_e( 'Choose Action', 'sdevs_subscrpt' ); ?></option>
    44                <?php foreach ( $actions as $action ) : ?>
    55                    <option value="<?php echo esc_html( $action['value'] ); ?>"
    6                                               <?php
     6                                                <?php
    77                                                if ( $action['value'] == $status ) {
    88                                                    echo 'selected';}
  • subscription/trunk/includes/Ajax.php

    r2797349 r2927437  
    1717    }
    1818
     19    /**
     20     * Install the WooCommerce Plugin.
     21     */
    1922    public function install_woocommerce_plugin() {
    2023        include ABSPATH . 'wp-admin/includes/plugin-install.php';
     
    5760        }
    5861
    59         $title = sprintf( __( 'Installing Plugin: %s', "sdevs_subscrpt" ), $api->name . ' ' . $api->version );
     62        $title = sprintf( __( 'Installing Plugin: %s', 'sdevs_subscrpt' ), $api->name . ' ' . $api->version );
    6063        $nonce = 'install-plugin_' . $plugin;
    6164        $url   = 'update.php?action=install-plugin&plugin=' . urlencode( $plugin );
     
    7073    }
    7174
     75    /**
     76     * Active WooComerce Plugin.
     77     */
    7278    public function activate_woocommerce_plugin() {
    7379        activate_plugin( 'woocommerce/woocommerce.php' );
  • subscription/trunk/includes/Assets.php

    r2797349 r2927437  
    7575                'in_footer' => true,
    7676            ),
    77             'sdevs_installer' => array(
     77            'sdevs_installer'          => array(
    7878                'src'       => $plugin_js_assets_path . 'installer.js',
    7979                'deps'      => array( 'jquery' ),
     
    9494
    9595        $styles = array(
    96             'subscrpt_admin_css' => array(
     96            'subscrpt_admin_css'  => array(
    9797                'src' => $plugin_css_assets_path . 'admin.css',
    9898            ),
     
    100100                'src' => $plugin_css_assets_path . 'status.css',
    101101            ),
    102             'sdevs_installer' => array(
     102            'sdevs_installer'     => array(
    103103                'src' => $plugin_css_assets_path . 'installer.css',
    104104            ),
  • subscription/trunk/includes/Frontend.php

    r2708268 r2927437  
    66use SpringDevs\Subscription\Frontend\Downloadable;
    77use SpringDevs\Subscription\Frontend\MyAccount;
     8use SpringDevs\Subscription\Frontend\Order as FrontendOrder;
    89use SpringDevs\Subscription\Frontend\Product;
    9 use SpringDevs\Subscription\Frontend\Thankyou;
    10 use SpringDevs\Subscription\Illuminate\AutoRenewal;
    1110use SpringDevs\Subscription\Illuminate\Cron;
    1211use SpringDevs\Subscription\Illuminate\Email;
    1312use SpringDevs\Subscription\Illuminate\Order;
    14 use SpringDevs\Subscription\Illuminate\RegisterPostStatus;
    15 use SpringDevs\Subscription\Illuminate\Subscriptions;
    1613
    1714/**
    1815 * Frontend handler class
    1916 */
    20 class Frontend {
     17class Frontend
     18{
    2119
    2220    /**
    2321     * Frontend constructor.
    2422     */
    25     public function __construct() {
    26         new Subscriptions();
    27         new Cron();
    28         new RegisterPostStatus();
     23    public function __construct()
     24    {
     25        new Illuminate();
    2926        new Product();
    30         new Thankyou();
     27        new FrontendOrder();
    3128        new ActionController();
    3229        new MyAccount();
     
    3431        new Order();
    3532        new Email();
    36         new AutoRenewal();
    3733    }
    3834}
  • subscription/trunk/includes/Frontend/ActionController.php

    r2708268 r2927437  
    55
    66use SpringDevs\Subscription\Illuminate\Action;
     7use SpringDevs\Subscription\Illuminate\AutoRenewal;
    78
    89/**
     
    1415
    1516
     17    /**
     18     * Initialize the class
     19     */
    1620    public function __construct() {
    17          add_action( 'before_single_subscrpt_content', array( $this, 'control_action_subscrpt' ) );
     21        add_action( 'before_single_subscrpt_content', array( $this, 'control_action_subscrpt' ) );
    1822    }
    1923
     24    /**
     25     * Take Subscription Action.
     26     */
    2027    public function control_action_subscrpt() {
    2128        if ( ! ( isset( $_GET['subscrpt_id'] ) && isset( $_GET['action'] ) && isset( $_GET['wpnonce'] ) ) ) {
    2229            return;
    2330        }
    24         $subscrpt_id = sanitize_text_field( $_GET['subscrpt_id'] );
    25         $action      = sanitize_text_field( $_GET['action'] );
    26         $wpnonce     = sanitize_text_field( $_GET['wpnonce'] );
     31        $subscrpt_id = sanitize_text_field( wp_unslash( $_GET['subscrpt_id'] ) );
     32        $action      = sanitize_text_field( wp_unslash( $_GET['action'] ) );
     33        $wpnonce     = sanitize_text_field( wp_unslash( $_GET['wpnonce'] ) );
    2734        if ( ! wp_verify_nonce( $wpnonce, 'subscrpt_nonce' ) ) {
    28             wp_die( __( 'Sorry !! You cannot permit to access.', 'sdevs_subscrpt' ) );
     35            wp_die( esc_html( __( 'Sorry !! You cannot permit to access.', 'sdevs_subscrpt' ) ) );
    2936        }
    30         if ( $action == 'renew' ) {
    31             $this->RenewProduct( $subscrpt_id );
    32         } elseif ( $action == 'early-renew' ) {
    33             $post_meta = get_post_meta( $subscrpt_id, '_subscrpt_order_general', true );
    34             $data      = array(
    35                 'post'    => $subscrpt_id,
    36                 'product' => $post_meta['product_id'],
    37             );
    38             if ( isset( $post_meta['variation_id'] ) ) {
    39                 $data['variation'] = $post_meta['variation_id'];
     37        if ( 'renew' === $action && 'manual' === subscrpt_get_renewal_process() ) {
     38                $this->manual_renew_product( $subscrpt_id );
     39        } elseif ( 'cancelled' === $action ) {
     40                $status      = get_post_status( $subscrpt_id );
     41                $user_cancel = get_post_meta( $subscrpt_id, '_subscrpt_user_cancel', true );
     42            if ( 'no' === $user_cancel ) {
     43                return;
     44            } elseif ( 'active' === $status ) {
     45                Action::status( 'pe_cancelled', $subscrpt_id );
     46            } else {
     47                Action::status( $action, $subscrpt_id );
    4048            }
    41             Action::status( 'renew', get_current_user_id(), $data );
    42         } elseif ( $action == 'renew-on' ) {
    43             update_post_meta( $subscrpt_id, '_subscrpt_auto_renew', 1 );
    44         } elseif ( $action == 'renew-off' ) {
    45             update_post_meta( $subscrpt_id, '_subscrpt_auto_renew', 0 );
     49        } elseif ( 'reactive' === $action ) {
     50            Action::status( 'active', $subscrpt_id );
    4651        } else {
    47             $post_meta = get_post_meta( $subscrpt_id, '_subscrpt_order_general', true );
    48             if ( $action == 'cancelled' ) {
    49                 $product_meta = get_post_meta( $post_meta['product_id'], 'subscrpt_general', true );
    50                 if ( $product_meta['user_cancell'] == 'no' ) {
    51                     return;
    52                 }
    53             }
    54             wp_update_post(
    55                 array(
    56                     'ID'          => $subscrpt_id,
    57                     'post_status' => $action,
    58                 )
    59             );
    60             $data = array(
    61                 'post'    => $subscrpt_id,
    62                 'product' => $post_meta['product_id'],
    63             );
    64             if ( isset( $post_meta['variation_id'] ) ) {
    65                 $data['variation'] = $post_meta['variation_id'];
    66             }
    67             Action::status( $action, get_current_user_id(), $data );
     52            do_action( 'subscrpt_execute_actions', $subscrpt_id, $action );
    6853        }
    69         echo ( "<script>location.href = '" . get_permalink( wc_get_page_id( 'myaccount' ) ) . 'view-subscrpt/' . $subscrpt_id . "';</script>" );
     54        // phpcs:ignore
     55        echo ( "<script>location.href = '" . wc_get_endpoint_url( 'view-subscription', $subscrpt_id, wc_get_page_permalink( 'myaccount' ) ) . "';</script>" );
    7056    }
    7157
    72     public function RenewProduct( $subscrpt_id ) {
    73         $post_meta    = get_post_meta( $subscrpt_id, '_subscrpt_order_general', true );
     58    /**
     59     * Manually Renew Subscription.
     60     *
     61     * @param Int $subscrpt_id Subscription ID.
     62     */
     63    public function manual_renew_product( $subscrpt_id ) {
     64        $post_meta  = get_post_meta( $subscrpt_id, '_order_subscrpt_meta', true );
     65        $product_id = get_post_meta( $subscrpt_id, '_subscrpt_product_id', true );
     66
    7467        $variation_id = 0;
    7568        if ( isset( $post_meta['variation_id'] ) ) {
    7669            $variation_id = $post_meta['variation_id'];
    7770        }
     71
     72        WC()->cart->empty_cart();
     73
    7874        WC()->cart->add_to_cart(
    79             $post_meta['product_id'],
     75            $product_id,
    8076            1,
    8177            $variation_id,
     
    8379            array( 'renew_subscrpt' => true )
    8480        );
    85         wc_add_notice( __( 'Product added to cart', 'sdevs_subscrpt' ), 'success' );
     81
     82        wc_add_notice( get_option( 'subscrpt_manual_renew_cart_notice' ), 'success' );
    8683        $this->redirect( wc_get_cart_url() );
    8784    }
    8885
     86    /**
     87     * Redirect on URL.
     88     *
     89     * @param String $url URL.
     90     */
    8991    public function redirect( $url ) {
    9092        ?>
  • subscription/trunk/includes/Frontend/Downloadable.php

    r2709135 r2927437  
    22
    33namespace SpringDevs\Subscription\Frontend;
     4
     5use SpringDevs\Subscription\Illuminate\Helper;
    46
    57/**
     
    1517
    1618    public function check_download_items( $downloads ) {
    17         $expired_items   = get_user_meta( get_current_user_id(), '_subscrpt_expired_items', true );
    18         $pending_items   = get_user_meta( get_current_user_id(), '_subscrpt_pending_items', true );
    19         $cancelled_items = get_user_meta( get_current_user_id(), '_subscrpt_cancelled_items', true );
     19        foreach ( $downloads as $key => $download ) {
     20            $unactive_items = Helper::subscription_exists( $download['product_id'], array( 'expired', 'cancelled', 'pending' ) );
    2021
    21         if ( ! is_array( $expired_items ) ) {
    22             $expired_items = array();
    23         }
    24         if ( ! is_array( $pending_items ) ) {
    25             $pending_items = array();
    26         }
    27         if ( ! is_array( $cancelled_items ) ) {
    28             $cancelled_items = array();
    29         }
    30 
    31         $expired_products = array();
    32         foreach ( $expired_items as $expired_item ) {
    33             $expired_products[] = $expired_item['product'];
    34         }
    35 
    36         $pending_products = array();
    37         foreach ( $pending_items as $pending_item ) {
    38             $pending_products[] = $pending_item['product'];
    39         }
    40 
    41         $cancelled_products = array();
    42         foreach ( $cancelled_items as $cancelled_item ) {
    43             $cancelled_products[] = $cancelled_item['product'];
    44         }
    45 
    46         foreach ( $downloads as $key => $download ) {
    47             if ( in_array( $download['product_id'], $expired_products ) ) {
    48                 unset( $downloads[ $key ] );
    49             }
    50             if ( in_array( $download['product_id'], $pending_products ) ) {
    51                 unset( $downloads[ $key ] );
    52             }
    53             if ( in_array( $download['product_id'], $cancelled_products ) ) {
     22            if ( $unactive_items ) {
    5423                unset( $downloads[ $key ] );
    5524            }
  • subscription/trunk/includes/Frontend/MyAccount.php

    r2797349 r2927437  
    11<?php
    2 
    32
    43namespace SpringDevs\Subscription\Frontend;
     
    98 * @package SpringDevs\Subscription\Frontend
    109 */
    11 class MyAccount {
     10class MyAccount
     11{
    1212
    13     public function __construct() {
    14         add_action( 'init', array( $this, 'flush_rewrite_rules' ) );
    15         add_filter( 'woocommerce_account_menu_items', array( $this, 'custom_my_account_menu_items' ) );
    16         add_filter( 'the_title', array( $this, 'change_endpoint_title' ), 10, 2 );
    17         add_filter( 'woocommerce_get_query_vars', array( $this, 'custom_query_vars' ) );
    18         add_action( 'woocommerce_account_view-subscrpt_endpoint', array( $this, 'view_subscrpt_content' ) );
    19         add_action( 'woocommerce_account_subscrpt-endpoint_endpoint', array( $this, 'subscrpt_endpoint_content' ) );
    20         add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
     13    /**
     14     * Initialize the class
     15     */
     16    public function __construct()
     17    {
     18        add_action('init', array($this, 'flush_rewrite_rules'));
     19        add_filter('woocommerce_account_menu_items', array($this, 'custom_my_account_menu_items'));
     20        add_filter('woocommerce_endpoint_view-subscription_title', array($this, 'change_single_title'));
     21        add_filter('the_title', array($this, 'change_lists_title'), 10);
     22        add_filter('woocommerce_get_query_vars', array($this, 'custom_query_vars'));
     23        add_action('woocommerce_account_view-subscription_endpoint', array($this, 'view_subscrpt_content'));
     24        add_action('woocommerce_account_subscriptions_endpoint', array($this, 'subscrpt_endpoint_content'));
     25        add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
    2126    }
    2227
    23     public function custom_query_vars( $query_vars ) {
    24         $query_vars['view-subscrpt'] = 'view-subscrpt';
     28    /**
     29     * Add custom url on MyAccount.
     30     *
     31     * @param array $query_vars query_vars.
     32     *
     33     * @return array
     34     */
     35    public function custom_query_vars(array $query_vars): array
     36    {
     37        $query_vars['view-subscription'] = 'view-subscription';
    2538        return $query_vars;
    2639    }
    2740
    28     public function view_subscrpt_content( $value ) {
    29         wc_get_template( 'myaccount/single-subscrpt.php', array( 'id' => $value ), 'simple-subscription', SUBSCRPT_TEMPLATES );
     41    /**
     42     * Display Subscription Content.
     43     *
     44     * @param Int $id Post ID.
     45     */
     46    public function view_subscrpt_content(int $id)
     47    {
     48        $post_meta   = get_post_meta($id, '_order_subscrpt_meta', true);
     49        $order       = wc_get_order($post_meta['order_id']);
     50        $order_item  = $order->get_item($post_meta['order_item_id']);
     51        $status      = get_post_status($id);
     52        $user_cancel = get_post_meta($id, '_subscrpt_user_cancel', true);
     53
     54        $subscrpt_nonce = wp_create_nonce('subscrpt_nonce');
     55        $action_buttons = array();
     56
     57        if ('cancelled' !== $status) {
     58            if (in_array($status, array('pending', 'active', 'on_hold'), true) && 'yes' === $user_cancel) {
     59                $action_buttons['cancel'] = array(
     60                    'url'   => subscrpt_get_action_url('cancelled', $subscrpt_nonce, $id),
     61                    'label' => __('Cancel', 'sdevs_subscrpt'),
     62                    'class' => 'cancel',
     63                );
     64            } elseif (trim($status) === trim('pe_cancelled')) {
     65                $action_buttons['reactive'] = array(
     66                    'url'   => subscrpt_get_action_url('reactive', $subscrpt_nonce, $id),
     67                    'label' => __('Reactive', 'sdevs_subscrpt'),
     68                );
     69            } elseif ('expired' === $status && 'pending' !== $order->get_status()) {
     70                $action_buttons['renew'] = array(
     71                    'url'   => subscrpt_get_action_url('renew', $subscrpt_nonce, $id),
     72                    'label' => __('Renew', 'sdevs_subscrpt'),
     73                );
     74            }
     75
     76            if ('pending' === $order->get_status()) {
     77                $action_buttons['pay_now'] = array(
     78                    'url'   => $order->get_checkout_payment_url(),
     79                    'label' => __('Pay now', 'sdevs_subscrpt'),
     80                );
     81            }
     82        }
     83
     84        $post_status_object = get_post_status_object($status);
     85        $action_buttons     = apply_filters('subscrpt_single_action_buttons', $action_buttons, $id, $subscrpt_nonce, $status);
     86
     87        wc_get_template(
     88            'myaccount/single.php',
     89            array(
     90                'id'              => $id,
     91                'post_meta'       => $post_meta,
     92                'order'           => $order,
     93                'order_item'      => $order_item,
     94                'status'          => $post_status_object,
     95                'user_cancel'     => $user_cancel,
     96                'action_buttons'  => $action_buttons,
     97                'wp_button_class' => wc_wp_theme_get_element_class_name('button') ? ' ' . wc_wp_theme_get_element_class_name('button') : '',
     98            ),
     99            'subscription',
     100            SUBSCRPT_TEMPLATES
     101        );
    30102    }
    31103
     
    33105     * Re-write flush
    34106     */
    35     public function flush_rewrite_rules() {
    36         add_rewrite_endpoint( 'subscrpt-endpoint', EP_ROOT | EP_PAGES );
     107    public function flush_rewrite_rules()
     108    {
     109        add_rewrite_endpoint('subscriptions', EP_ROOT | EP_PAGES);
    37110        flush_rewrite_rules();
    38111    }
    39112
    40     /**
    41      * @param $title
    42      * @param $endpoint
    43      *
    44      * @return string|void
    45      */
    46     public function change_endpoint_title( $title, $endpoint ) {
     113    /**
     114     * Change View Subscription Title
     115     *
     116     * @param String $title Title.
     117     *
     118     * @return String
     119     */
     120    public function change_single_title(string $title): string
     121    {
     122        /* translators: %s: Subscription ID */
     123        return sprintf(__('Subscription #%s', 'sdevs_subscrpt'), get_query_var('view-subscription'));
     124    }
     125
     126    /**
     127     * Change Subscription Lists Title
     128     *
     129     * @param String $title Title.
     130     *
     131     * @return String
     132     */
     133    public function change_lists_title(string $title): string
     134    {
    47135        global $wp_query;
    48         $is_endpoint = isset( $wp_query->query_vars['subscrpt-endpoint'] );
    49         $is_single   = isset( $wp_query->query_vars['view-subscrpt'] );
    50         if ( $is_endpoint && ! is_admin() && is_main_query() && in_the_loop() && is_account_page() ) {
    51             $title = __( 'My Subscriptions', 'sdevs_subscrpt' );
    52             remove_filter( 'the_title', array( $this, 'change_endpoint_title' ) );
    53         } elseif ( $is_single && ! is_admin() && is_main_query() && in_the_loop() && is_account_page() ) {
    54             $title = __( 'Subscription #' . get_query_var( 'view-subscrpt' ), 'sdevs_subscrpt' );
    55             remove_filter( 'the_title', array( $this, 'change_endpoint_title' ) );
     136        $is_endpoint = isset($wp_query->query_vars['subscriptions']);
     137        if ($is_endpoint && !is_admin() && is_account_page()) {
     138            $title = __('My Subscriptions', 'sdevs_subscrpt');
    56139        }
    57140        return $title;
     
    59142
    60143    /**
    61      * @param $items
    62      * @return mixed
     144     * Filter menu items.
     145     *
     146     * @param array $items MyAccount menu items.
     147     * @return array
    63148     */
    64     public function custom_my_account_menu_items( $items ) {
     149    public function custom_my_account_menu_items(array $items): array
     150    {
    65151        $logout = $items['customer-logout'];
    66         unset( $items['customer-logout'] );
    67         $items['subscrpt-endpoint'] = __( 'Subscriptions', 'sdevs_subscrpt' );
    68         $items['customer-logout']   = $logout;
     152        unset($items['customer-logout']);
     153        $items['subscriptions']   = __('Subscriptions', 'sdevs_subscrpt');
     154        $items['customer-logout'] = $logout;
    69155        return $items;
    70156    }
    71157
    72158    /**
    73      * Bookable EndPoint Content
     159     * Subscription Single EndPoint Content
    74160     */
    75     public function subscrpt_endpoint_content() {
    76         wc_get_template( 'myaccount/subscriptions.php', array(), 'simple-subscription', SUBSCRPT_TEMPLATES );
     161    public function subscrpt_endpoint_content()
     162    {
     163        wc_get_template(
     164            'myaccount/subscriptions.php',
     165            array(
     166                'wp_button_class' => wc_wp_theme_get_element_class_name('button') ? ' ' . wc_wp_theme_get_element_class_name('button') : '',
     167            ),
     168            'subscription',
     169            SUBSCRPT_TEMPLATES
     170        );
    77171    }
    78172
     173    /**
     174     * Enqueue assets
     175     */
    79176    public function enqueue_styles()
    80177    {
    81         wp_enqueue_style( 'subscrpt_status_css' );
     178        wp_enqueue_style('subscrpt_status_css');
    82179    }
    83180}
  • subscription/trunk/includes/Frontend/Product.php

    r2797349 r2927437  
    1111class Product {
    1212
    13 
     13    /**
     14     * Initialize the class
     15     */
    1416    public function __construct() {
    1517        add_filter( 'woocommerce_product_single_add_to_cart_text', array( $this, 'change_single_add_to_cart_text' ) );
     
    2325        add_action( 'woocommerce_before_cart_totals', array( $this, 'change_cart_calculates' ) );
    2426        add_action( 'woocommerce_cart_calculate_fees', array( $this, 'add_cart_fee' ) );
    25         add_filter( 'woocommerce_add_cart_item_data', array( $this, 'add_to_cart_item_data' ), 10, 3 );
     27        add_filter( 'woocommerce_add_cart_item_data', array( $this, 'add_to_cart_item_data' ), 10, 2 );
    2628        add_filter( 'woocommerce_is_purchasable', array( $this, 'check_if_purchasable' ), 10, 2 );
    2729        add_filter( 'woocommerce_loop_add_to_cart_link', array( $this, 'remove_button_active_products' ), 10, 2 );
    2830        add_action( 'woocommerce_single_product_summary', array( $this, 'text_if_active' ) );
    29         add_action( 'woocommerce_checkout_create_order_line_item', array( $this, 'save_order_item_product_meta' ), 10, 4 );
     31        add_action( 'woocommerce_checkout_create_order_line_item', array( $this, 'save_order_item_product_meta' ), 10, 3 );
    3032        add_filter( 'woocommerce_cart_get_total', array( $this, 'calculates_cart_total' ) );
    3133    }
    3234
     35    /**
     36     * Update Cart total
     37     *
     38     * @param mixed $total Cart total.
     39     *
     40     * @return mixed
     41     */
    3342    public function calculates_cart_total( $total ) {
    3443        $cart_items = WC()->cart->cart_contents;
    3544        foreach ( $cart_items as $cart_item ) {
    3645            $conditional_key = apply_filters( 'subscrpt_filter_checkout_conditional_key', $cart_item['product_id'], $cart_item );
    37             $post_meta       = get_post_meta( $conditional_key, 'subscrpt_general', true );
    38             $has_trial       = Helper::Check_Trial( $conditional_key );
     46            $post_meta       = get_post_meta( $conditional_key, '_subscrpt_meta', true );
     47            $has_trial       = Helper::check_trial( $conditional_key );
    3948            if ( is_array( $post_meta ) && $post_meta['enable'] ) {
    4049                if ( ! empty( $post_meta['trial_time'] ) && $post_meta['trial_time'] > 0 && $has_trial ) {
     
    4857    }
    4958
     59    /**
     60     * Add signup fee if available
     61     *
     62     * @param \WC_Cart $cart Cart.
     63     */
    5064    public function add_cart_fee( $cart ) {
    5165        $cart_items = WC()->cart->cart_contents;
     
    5367        foreach ( $cart_items as $cart_item ) {
    5468            $conditional_key = apply_filters( 'subscrpt_filter_checkout_conditional_key', $cart_item['product_id'], $cart_item );
    55             $post_meta       = get_post_meta( $conditional_key, 'subscrpt_general', true );
     69            $post_meta       = get_post_meta( $conditional_key, '_subscrpt_meta', true );
    5670            if ( is_array( $post_meta ) && $post_meta['enable'] ) :
    57                 $has_trial = Helper::Check_Trial( $conditional_key );
     71                $has_trial = Helper::check_trial( $conditional_key );
    5872                if ( $has_trial && isset( $post_meta['signup_fee'] ) ) {
    5973                    $signup_fee += (int) $post_meta['signup_fee'];
     
    6680    }
    6781
    68     public function save_order_item_product_meta( $item, $cart_item_key, $cart_item, $order ) {
     82    /**
     83     * Save renew meta
     84     *
     85     * @param Object $item Item.
     86     * @param String $cart_item_key Cart Item Key.
     87     * @param Array  $cart_item Cart Item.
     88     */
     89    public function save_order_item_product_meta( $item, $cart_item_key, $cart_item ) {
    6990        if ( isset( $cart_item['renew_subscrpt'] ) ) {
    7091            $item->update_meta_data( '_renew_subscrpt', $cart_item['renew_subscrpt'] );
     
    7293    }
    7394
     95    /**
     96     * Display notice if already purchased.
     97     */
    7498    public function text_if_active() {
    7599        global $product;
     
    77101            return;
    78102        }
    79         $post_meta = get_post_meta( $product->get_id(), 'subscrpt_general', true );
    80         $unexpired = Helper::Check_un_expired( $product->get_id() );
     103        $post_meta = get_post_meta( $product->get_id(), '_subscrpt_meta', true );
     104        $unexpired = Helper::subscription_exists( $product->get_id(), array( 'active', 'pending' ) );
    81105        if ( is_array( $post_meta ) && isset( $post_meta['limit'] ) ) {
    82             if ( $post_meta['limit'] == 'unlimited' ) {
     106            if ( 'unlimited' === $post_meta['limit'] ) {
    83107                return;
    84108            }
    85             if ( $post_meta['limit'] == 'one' ) {
     109            if ( 'one' === $post_meta['limit'] ) {
    86110                if ( ! $unexpired ) {
    87                     return;
    88                 }
    89             }
    90             if ( $post_meta['limit'] == 'only_one' ) {
    91                 if ( ! subscrpt_check_trial( $product->get_id() ) ) {
    92                     echo '<strong>' . __( 'You Already Purchased These Product!', 'sdevs_subscrpt' ) . '</strong>';
    93                 }
    94             }
    95         }
    96         if ( $unexpired ) {
    97             echo '<strong>' . __( 'You Already Purchased These Product!', 'sdevs_subscrpt' ) . '</strong>';
    98         }
    99     }
    100 
     111                    return false;
     112                } else {
     113                    echo '<strong>' . esc_html_e( 'You Already Subscribed These Product!', 'sdevs_subscrpt' ) . '</strong>';
     114                }
     115            }
     116            if ( 'only_one' === $post_meta['limit'] ) {
     117                if ( ! Helper::check_trial( $product->get_id() ) ) {
     118                    echo '<strong>' . esc_html_e( 'You Already Subscribed These Product!', 'sdevs_subscrpt' ) . '</strong>';
     119                }
     120            }
     121        }
     122    }
     123
     124    /**
     125     * Remove button if product already subscribed.
     126     *
     127     * @param mixed       $button Button.
     128     * @param \Wc_Product $product Product.
     129     *
     130     * @return mixed
     131     */
    101132    public function remove_button_active_products( $button, $product ) {
    102133        if ( $product->is_type( 'variable' ) && ! subscrpt_pro_activated() ) {
    103134            return $button;
    104135        }
    105         $unexpired = Helper::Check_un_expired( $product->get_id() );
     136        $unexpired = Helper::subscription_exists( $product->get_id(), array( 'active', 'pending' ) );
    106137        if ( $unexpired ) {
    107138            return;
     
    110141    }
    111142
     143    /**
     144     * Check if product pruchasable.
     145     *
     146     * @param Boolean     $is_purchasable True\False.
     147     * @param \WC_Product $product Product.
     148     *
     149     * @return Boolean
     150     */
    112151    public function check_if_purchasable( $is_purchasable, $product ) {
    113152        if ( $product->is_type( 'variable' ) ) {
    114153            return $is_purchasable;
    115154        }
    116         $unexpired = Helper::Check_un_expired( $product->get_id() );
     155        $unexpired = Helper::subscription_exists( $product->get_id(), array( 'active', 'pending' ) );
    117156        if ( $unexpired ) {
    118157            return false;
     
    121160    }
    122161
    123     public function add_to_cart_item_data( $cart_item_data, $product_id, $variation_id ) {
    124         $expired = Helper::CheckExpired( $product_id );
     162    /**
     163     * Add renew status.
     164     *
     165     * @param Array $cart_item_data cart_item_data.
     166     * @param Int   $product_id Product ID.
     167     *
     168     * @return Array
     169     */
     170    public function add_to_cart_item_data( $cart_item_data, $product_id ) {
     171        $expired = Helper::subscription_exists( $product_id, 'expired' );
    125172        if ( $expired ) {
    126173            $cart_item_data['renew_subscrpt'] = true;
     
    129176    }
    130177
     178    /**
     179     * Set cart subtotal.
     180     *
     181     * @param \WC_Cart $cart Cart.
     182     */
    131183    public function change_cart_calculates( $cart ) {
    132184        $cart_items = WC()->cart->cart_contents;
    133185        foreach ( $cart_items as $cart_item ) {
    134186            $conditional_key = apply_filters( 'subscrpt_filter_checkout_conditional_key', $cart_item['product_id'], $cart_item );
    135             $post_meta       = get_post_meta( $conditional_key, 'subscrpt_general', true );
    136             $has_trial       = Helper::Check_Trial( $conditional_key );
     187            $post_meta       = get_post_meta( $conditional_key, '_subscrpt_meta', true );
     188            $has_trial       = Helper::check_trial( $conditional_key );
    137189            if ( is_array( $post_meta ) && $post_meta['enable'] ) {
    138190                if ( ! empty( $post_meta['trial_time'] ) && $post_meta['trial_time'] > 0 && $has_trial ) {
    139191                    $subtotal = WC()->cart->get_subtotal() - $cart_item['line_subtotal'];
    140                     // $total = WC()->cart->total - $cart_item["line_subtotal"];
    141192                    WC()->cart->set_subtotal( $subtotal );
    142                     // WC()->cart->set_total($total);
    143                 }
    144             }
    145         }
    146     }
    147 
     193                }
     194            }
     195        }
     196    }
     197
     198    /**
     199     * Change single product add-to-cart button text.
     200     *
     201     * @param String $text Add-to-cart button Text.
     202     */
    148203    public function change_single_add_to_cart_text( $text ) {
    149204        global $product;
    150         if ( ! $product ) {
     205        if ( ! $product || $product->is_type( 'variable' ) || '' === $product->get_price() ) {
    151206            return $text;
    152207        }
    153         if ( $product->is_type( 'variable' ) ) {
    154             return $text;
    155         }
    156         $post_meta = get_post_meta( $product->get_id(), 'subscrpt_general', true );
    157         if ( is_array( $post_meta ) && isset( $post_meta['limit'] ) && $post_meta['limit'] == 'unlimited' ) {
    158             return $post_meta['cart_txt'];
    159         }
    160         $expired = Helper::CheckExpired( $product->get_id() );
     208        $post_meta = get_post_meta( $product->get_id(), '_subscrpt_meta', true );
     209        $expired   = Helper::subscription_exists( $product->get_id(), 'expired' );
    161210        if ( $expired ) :
    162211            $text = __( 'renew', 'sdevs_subscrpt' );
    163         elseif ( is_array( $post_meta ) && $post_meta['enable'] ) :
     212        elseif ( is_array( $post_meta ) && $post_meta['enable'] && '' !== $post_meta['cart_txt'] ) :
    164213            $text = $post_meta['cart_txt'];
    165214        endif;
     
    167216    }
    168217
     218    /**
     219     * Add trial, signup fee etc. with product price.
     220     *
     221     * @param mixed       $price Price.
     222     * @param \WC_Product $product Product.
     223     *
     224     * @return mixed
     225     */
    169226    public function change_price_html( $price, $product ) {
    170         if ( $product->is_type( 'variable' ) ) {
     227        if ( $product->is_type( 'variable' ) || '' === $price ) {
    171228            return $price;
    172229        }
    173         $post_meta = get_post_meta( $product->get_id(), 'subscrpt_general', true );
     230
     231        $post_meta = get_post_meta( $product->get_id(), '_subscrpt_meta', true );
    174232        if ( is_array( $post_meta ) && $post_meta['enable'] ) :
    175             $time            = $post_meta['time'] == 1 ? null : $post_meta['time'];
     233            $time            = '1' === $post_meta['time'] ? null : $post_meta['time'];
    176234            $type            = Helper::get_typos( $post_meta['time'], $post_meta['type'] );
    177             $has_trial       = Helper::Check_Trial( $product->get_id() );
     235            $has_trial       = Helper::check_trial( $product->get_id() );
    178236            $trial           = null;
    179237            $signup_fee_html = null;
    180238            if ( ! empty( $post_meta['trial_time'] ) && $post_meta['trial_time'] > 0 && $has_trial ) {
    181239                $trial = '<br/> + Get ' . $post_meta['trial_time'] . ' ' . Helper::get_typos( $post_meta['trial_time'], $post_meta['trial_type'] ) . ' free trial!';
    182                 if ( isset( $post_meta['signup_fee'] ) ) {
     240                if ( isset( $post_meta['signup_fee'] ) && '' !== $post_meta['signup_fee'] ) {
    183241                    $signup_fee_html = '<br/> + Signup fee of ' . wc_price( $post_meta['signup_fee'] );
    184242                }
     
    196254            return $price;
    197255        }
    198         $post_meta = get_post_meta( $cart_item['product_id'], 'subscrpt_general', true );
     256        $post_meta = get_post_meta( $cart_item['product_id'], '_subscrpt_meta', true );
    199257        if ( is_array( $post_meta ) && $post_meta['enable'] ) :
    200258            $time            = $post_meta['time'] == 1 ? null : $post_meta['time'];
     
    203261            $trial           = null;
    204262            $signup_fee_html = null;
    205             $has_trial       = Helper::Check_Trial( $cart_item['product_id'] );
     263            $has_trial       = Helper::check_trial( $cart_item['product_id'] );
    206264            if ( ! empty( $post_meta['trial_time'] ) && $post_meta['trial_time'] > 0 && $has_trial ) {
    207265                $trial = '<br/><small> + ' . $post_meta['trial_time'] . ' ' . Helper::get_typos( $post_meta['trial_time'], $post_meta['trial_type'] ) . ' free trial!</small>';
     
    221279        $recurrs    = array();
    222280        foreach ( $cart_items as $cart_item ) {
    223             $post_meta = get_post_meta( $cart_item['product_id'], 'subscrpt_general', true );
     281            $post_meta = get_post_meta( $cart_item['product_id'], '_subscrpt_meta', true );
    224282            $product   = wc_get_product( $cart_item['product_id'] );
    225283            if ( ! $product->is_type( 'variable' ) && is_array( $post_meta ) && $post_meta['enable'] ) :
     
    230288                $trial      = null;
    231289                $start_date = null;
    232                 $has_trial  = Helper::Check_Trial( $cart_item['product_id'] );
     290                $has_trial  = Helper::check_trial( $cart_item['product_id'] );
    233291                if ( ! empty( $post_meta['trial_time'] ) && $post_meta['trial_time'] > 0 && $has_trial ) {
    234                     $trial = $post_meta['trial_time'] . ' ' . Helper::get_typos( $post_meta['trial_time'], $post_meta['trial_type'] );
     292                    $trial      = $post_meta['trial_time'] . ' ' . Helper::get_typos( $post_meta['trial_time'], $post_meta['trial_type'] );
     293                    $start_date = Helper::start_date(
     294                        $post_meta['time'] . ' ' . $type,
     295                        $trial
     296                    );
    235297                }
    236298                $trial_status = $trial == null ? false : true;
     
    239301                    $trial
    240302                );
    241                 $next_date = apply_filters( 'subscrpt_next_date_single_cart', $next_date, $cart_item, $trial );
    242                 $recurrs[] = array(
    243                     'trial'      => $trial_status,
    244                     'price_html' => $price_html,
    245                     'start_date' => $start_date,
    246                     'next_date'  => $next_date,
    247                 );
     303                $next_date    = apply_filters( 'subscrpt_next_date_single_cart', $next_date, $cart_item, $trial );
     304                $recurrs[]    = array(
     305                    'trial'      => $trial_status,
     306                    'price_html' => $price_html,
     307                    'start_date' => $start_date,
     308                    'next_date'  => $next_date,
     309                );
    248310            endif;
    249311        }
    250312        $recurrs = apply_filters( 'subscrpt_cart_recurring_items', $recurrs );
    251         if ( count( $recurrs ) == 0 ) {
     313        if ( 0 === count( $recurrs ) ) {
    252314            return;
    253315        }
     
    260322                        <p>
    261323                            <span><?php echo wp_kses_post( $recurr['price_html'] ); ?></span><br />
    262                             <small><?php echo esc_html_e( 'First billing on', 'sdevs_subscrpt' ); ?>: <?php echo esc_html( date( 'F d, Y', $recurr['start_date'] ) ); ?></small>
     324                            <small><?php echo esc_html_e( 'First billing on', 'sdevs_subscrpt' ); ?>: <?php echo esc_html( $recurr['start_date'] ?? wp_date( get_option( 'date_format' ) ) ); ?></small>
    263325                        </p>
    264                     <?php else : ?>
     326                        <?php else : ?>
    265327                        <p>
    266328                            <span><?php echo wp_kses_post( $recurr['price_html'] ); ?></span><br />
  • subscription/trunk/includes/Illuminate/Action.php

    r2797349 r2927437  
    88 * @package SpringDevs\Subscription\Illuminate
    99 */
    10 class Action {
     10class Action
     11{
    1112
    12     private static $expired_items;
    13     private static $active_items;
    14     private static $pending_items;
    15     private static $cancelled_items;
     13    /**
     14     * Did when status changes.
     15     *
     16     * @param string $status Status.
     17     * @param Int    $subscription_id Subscription ID.
     18     */
     19    public static function status(string $status, int $subscription_id)
     20    {
     21        // if (current_user_can('edit_post', $subscription_id)) {
     22        wp_update_post(
     23            array(
     24                'ID'          => $subscription_id,
     25                'post_status' => $status,
     26            )
     27        );
    1628
    17     public static function status( $action, $author, $data = array() ) {
    18         self::get( $author );
    19         self::edit( $action, $data );
    20         self::user( $author, $action );
    21         self::update( $author );
     29        self::write_comment($status, $subscription_id);
     30        self::user($subscription_id);
     31        // }
    2232    }
    2333
    24     private static function get( $author ) {
    25         $expired_items   = get_user_meta( $author, '_subscrpt_expired_items', true );
    26         $active_items    = get_user_meta( $author, '_subscrpt_active_items', true );
    27         $pending_items   = get_user_meta( $author, '_subscrpt_pending_items', true );
    28         $cancelled_items = get_user_meta( $author, '_subscrpt_cancelled_items', true );
    29 
    30         self::$expired_items   = is_array( $expired_items ) ? $expired_items : array();
    31         self::$active_items    = is_array( $active_items ) ? $active_items : array();
    32         self::$pending_items   = is_array( $pending_items ) ? $pending_items : array();
    33         self::$cancelled_items = is_array( $cancelled_items ) ? $cancelled_items : array();
    34     }
    35 
    36     private static function edit( $action, $data ) {
    37         switch ( $action ) {
     34    /**
     35     * Write Comment based on status.
     36     *
     37     * @param string $status Status.
     38     * @param Int    $subscription_id Subscription ID.
     39     */
     40    public static function write_comment(string $status, int $subscription_id)
     41    {
     42        switch ($status) {
    3843            case 'expired':
    39                 self::expired( $data );
     44                self::expired($subscription_id);
    4045                break;
    4146            case 'active':
    42                 self::active( $data );
    43                 break;
    44             case 'renew':
    45                 self::renew( $data );
     47                self::active($subscription_id);
    4648                break;
    4749            case 'pending':
    48                 self::pending( $data );
     50                self::pending($subscription_id);
    4951                break;
    5052            case 'cancelled':
    51                 self::cancelled( $data );
     53                self::cancelled($subscription_id);
     54                break;
     55            case 'pe_cancelled':
     56                self::pe_cancelled($subscription_id);
    5257                break;
    5358        }
    5459    }
    5560
    56     private static function user( $author, $action ) {
    57         $user = new \WP_User( $author );
    58         if ( ! empty( $user->roles ) && is_array( $user->roles ) && in_array( 'administrator', $user->roles ) ) {
    59             return;
    60         }
    61         if ( $action == 'active' ) {
    62             $user->set_role( get_option( 'subscrpt_active_role', 'subscriber' ) );
    63         }
    64         if ( ( $action == 'cancelled' || $action == 'expired' ) && ( count( self::$active_items ) == 0 && count( self::$pending_items ) == 0 ) ) {
    65             $user->set_role( get_option( 'subscrpt_unactive_role', 'customer' ) );
    66         }
    67     }
    68 
    69     private static function expired( $data ) {
    70         if ( ! in_array( $data, self::$expired_items ) ) {
    71             array_push( self::$expired_items, $data );
    72         }
    73 
    74         if ( in_array( $data, self::$active_items ) ) {
    75             $key = array_search( $data, self::$active_items );
    76             unset( self::$active_items[ $key ] );
    77         }
    78 
    79         if ( in_array( $data, self::$pending_items ) ) {
    80             $key = array_search( $data, self::$pending_items );
    81             unset( self::$pending_items[ $key ] );
    82         }
    83 
    84         if ( in_array( $data, self::$cancelled_items ) ) {
    85             $key = array_search( $data, self::$cancelled_items );
    86             unset( self::$cancelled_items[ $key ] );
    87         }
    88 
    89         $post_meta = get_post_meta( $data['post'], '_subscrpt_order_general', true );
    90         if ( $post_meta['trial'] != null && time() >= $post_meta['start_date'] ) {
    91             $post_meta['trial'] = null;
    92             update_post_meta( $data['post'], '_subscrpt_order_general', $post_meta );
    93         }
    94 
     61    /**
     62     * Write Comment About expired Subscription.
     63     *
     64     * @param int $subscription_id Subscription ID.
     65     */
     66    private static function expired(int $subscription_id)
     67    {
    9568        $comment_id = wp_insert_comment(
    9669            array(
    97                 'comment_agent'   => 'simple-subscriptions',
    98                 'comment_author'  => 'simple-subscriptions',
    99                 'comment_content' => __( 'Subscription is Expired ', 'sdevs_subscrpt' ),
    100                 'comment_post_ID' => $data['post'],
     70                'comment_author'  => 'Subscription for WooCommerce',
     71                'comment_content' => 'Subscription is Expired',
     72                'comment_post_ID' => $subscription_id,
    10173                'comment_type'    => 'order_note',
    10274            )
    10375        );
    104         update_comment_meta( $comment_id, 'subscrpt_activity', __( 'Subscription Expired', 'sdevs_subscrpt' ) );
    105         do_action( 'subscrpt_when_product_expired', $data['post'], $data['product'], $data, false );
     76        update_comment_meta($comment_id, '_subscrpt_activity', 'Subscription Expired');
     77
     78        do_action('subscrpt_subscription_expired', $subscription_id);
    10679    }
    10780
    108     private static function active( $data ) {
    109         if ( ! in_array( $data, self::$active_items ) ) {
    110             array_push( self::$active_items, $data );
    111         }
    112 
    113         if ( in_array( $data, self::$expired_items ) ) {
    114             $key = array_search( $data, self::$expired_items );
    115             unset( self::$expired_items[ $key ] );
    116         }
    117 
    118         if ( in_array( $data, self::$pending_items ) ) {
    119             $key = array_search( $data, self::$pending_items );
    120             unset( self::$pending_items[ $key ] );
    121         }
    122 
    123         if ( in_array( $data, self::$cancelled_items ) ) {
    124             $key = array_search( $data, self::$cancelled_items );
    125             unset( self::$cancelled_items[ $key ] );
    126         }
    127 
     81    /**
     82     * Write Comment About Active Subscription.
     83     *
     84     * @param int $subscription_id Subscription ID.
     85     */
     86    private static function active(int $subscription_id)
     87    {
    12888        $comment_id = wp_insert_comment(
    12989            array(
    130                 'comment_agent'   => 'simple-subscriptions',
    131                 'comment_author'  => 'simple-subscriptions',
    132                 'comment_content' => __( 'Subscription activated.Next payment due date set. ', 'sdevs_subscrpt' ),
    133                 'comment_post_ID' => $data['post'],
     90                'comment_author'  => 'Subscription for WooCommerce',
     91                'comment_content' => 'Subscription activated.Next payment due date set.',
     92                'comment_post_ID' => $subscription_id,
    13493                'comment_type'    => 'order_note',
    13594            )
    13695        );
    137         update_comment_meta( $comment_id, 'subscrpt_activity', __( 'Subscription Activated', 'sdevs_subscrpt' ) );
     96        update_comment_meta($comment_id, '_subscrpt_activity', 'Subscription Activated');
    13897
    139         do_action('subscrpt_subscription_activated', $data);
     98        do_action('subscrpt_subscription_activated', $subscription_id);
    14099    }
    141100
    142     private static function renew( $data ) {
    143         $post_meta = get_post_meta( $data['post'], '_subscrpt_order_general', true );
    144         if ( $post_meta['trial'] != null ) {
    145             $post_meta['trial'] = null;
    146             update_post_meta( $data['post'], '_subscrpt_order_general', $post_meta );
    147         }
    148         do_action( 'subscrpt_when_product_expired', $data['post'], $data['product'], $data, true );
    149     }
    150 
    151     private static function pending( $data ) {
    152         if ( ! in_array( $data, self::$pending_items ) ) {
    153             array_push( self::$pending_items, $data );
    154         }
    155 
    156         if ( in_array( $data, self::$expired_items ) ) {
    157             $key = array_search( $data, self::$expired_items );
    158             unset( self::$expired_items[ $key ] );
    159         }
    160 
    161         if ( in_array( $data, self::$active_items ) ) {
    162             $key = array_search( $data, self::$active_items );
    163             unset( self::$active_items[ $key ] );
    164         }
    165 
    166         if ( in_array( $data, self::$cancelled_items ) ) {
    167             $key = array_search( $data, self::$cancelled_items );
    168             unset( self::$cancelled_items[ $key ] );
    169         }
    170 
     101    /**
     102     * Write Comment About Subscription Pending.
     103     *
     104     * @param int $subscription_id Subscription ID.
     105     */
     106    private static function pending(int $subscription_id)
     107    {
    171108        $comment_id = wp_insert_comment(
    172109            array(
    173                 'comment_agent'   => 'simple-subscriptions',
    174                 'comment_author'  => 'simple-subscriptions',
    175                 'comment_content' => __( 'Subscription is pending.', 'sdevs_subscrpt' ),
    176                 'comment_post_ID' => $data['post'],
     110                'comment_author'  => 'Subscription for WooCommerce',
     111                'comment_content' => 'Subscription is pending.',
     112                'comment_post_ID' => $subscription_id,
    177113                'comment_type'    => 'order_note',
    178114            )
    179115        );
    180         update_comment_meta( $comment_id, 'subscrpt_activity', __( 'Subscription Pending', 'sdevs_subscrpt' ) );
     116        update_comment_meta($comment_id, '_subscrpt_activity', 'Subscription Pending');
    181117    }
    182118
    183     private static function cancelled( $data ) {
    184         if ( ! in_array( $data, self::$cancelled_items ) ) {
    185             array_push( self::$cancelled_items, $data );
    186         }
    187 
    188         if ( in_array( $data, self::$expired_items ) ) {
    189             $key = array_search( $data, self::$expired_items );
    190             unset( self::$expired_items[ $key ] );
    191         }
    192 
    193         if ( in_array( $data, self::$active_items ) ) {
    194             $key = array_search( $data, self::$active_items );
    195             unset( self::$active_items[ $key ] );
    196         }
    197 
    198         if ( in_array( $data, self::$pending_items ) ) {
    199             $key = array_search( $data, self::$pending_items );
    200             unset( self::$pending_items[ $key ] );
    201         }
    202 
     119    /**
     120     * Write Comment About Subscription Cancelled.
     121     *
     122     * @param int $subscription_id Subscription ID.
     123     */
     124    private static function cancelled(int $subscription_id)
     125    {
    203126        $comment_id = wp_insert_comment(
    204127            array(
    205                 'comment_agent'   => 'simple-subscriptions',
    206                 'comment_author'  => 'simple-subscriptions',
    207                 'comment_content' => __( 'Subscription is Cancelled.', 'sdevs_subscrpt' ),
    208                 'comment_post_ID' => $data['post'],
     128                'comment_author'  => 'Subscription for WooCommerce',
     129                'comment_content' => 'Subscription is Cancelled.',
     130                'comment_post_ID' => $subscription_id,
    209131                'comment_type'    => 'order_note',
    210132            )
    211133        );
    212         update_comment_meta( $comment_id, 'subscrpt_activity', __( 'Subscription Cancelled', 'sdevs_subscrpt' ) );
     134        update_comment_meta($comment_id, '_subscrpt_activity', 'Subscription Cancelled');
    213135    }
    214136
    215     private static function update( $author ) {
    216         update_user_meta( $author, '_subscrpt_expired_items', self::$expired_items );
    217         update_user_meta( $author, '_subscrpt_active_items', self::$active_items );
    218         update_user_meta( $author, '_subscrpt_pending_items', self::$pending_items );
    219         update_user_meta( $author, '_subscrpt_cancelled_items', self::$cancelled_items );
     137    /**
     138     * Write Comment About Pending Cancellation.
     139     *
     140     * @param int $subscription_id Subscription ID.
     141     */
     142    private static function pe_cancelled(int $subscription_id)
     143    {
     144        $comment_id = wp_insert_comment(
     145            array(
     146                'comment_author'  => 'Subscription for WooCommerce',
     147                'comment_content' => 'Subscription is Pending Cancellation.',
     148                'comment_post_ID' => $subscription_id,
     149                'comment_type'    => 'order_note',
     150            )
     151        );
     152        update_comment_meta($comment_id, '_subscrpt_activity', 'Subscription Pending Cancellation');
     153    }
     154
     155    /**
     156     * Update user role.
     157     *
     158     * @param Int $subscription_id Subscription ID.
     159     */
     160    private static function user($subscription_id)
     161    {
     162        $user = new \WP_User(get_current_user_id());
     163        if (!empty($user->roles) && is_array($user->roles) && in_array('administrator', $user->roles, true)) {
     164            return;
     165        }
     166
     167        if (Helper::subscription_exists($subscription_id, 'active')) {
     168            $user->set_role(get_option('subscrpt_active_role', 'subscriber'));
     169        } elseif (Helper::subscription_exists($subscription_id, array('cancelled', 'expired'))) {
     170            $user->set_role(get_option('subscrpt_unactive_role', 'customer'));
     171        }
    220172    }
    221173}
  • subscription/trunk/includes/Illuminate/Cron.php

    r2708268 r2927437  
    88 * @package SpringDevs\Subscription\Illuminate
    99 */
    10 class Cron {
     10class Cron
     11{
    1112
    12     public function __construct() {
    13         add_action( 'subscrpt_daily_cron', array( $this, 'daily_cron_task' ) );
     13    /**
     14     * Initialize the class.
     15     */
     16    public function __construct()
     17    {
     18        add_action('subscrpt_daily_cron', array($this, 'daily_cron_task'));
    1419    }
    1520
    16     public function daily_cron_task() {
    17         $active_items = get_user_meta( get_current_user_id(), '_subscrpt_active_items', true );
    18         if ( ! is_array( $active_items ) ) {
    19             $active_items = array();
    20         }
    21         foreach ( $active_items as $active_item ) {
    22             $post_meta = get_post_meta( $active_item['post'], '_subscrpt_order_general', true );
    23             if ( time() >= $post_meta['next_date'] || ( $post_meta['trial'] != null && time() >= $post_meta['start_date'] ) ) {
    24                 wp_update_post(
    25                     array(
    26                         'ID'          => $post_meta['post'],
    27                         'post_type'   => 'subscrpt_order',
    28                         'post_status' => 'expired',
    29                     )
    30                 );
    31                 Action::status( 'expired', get_current_user_id(), $active_item );
    32                 do_action( 'subscrpt_cron_expired', $active_item );
     21    /**
     22     * Run daily cron task to check if subscription expired.
     23     */
     24    public function daily_cron_task()
     25    {
     26        $args = array(
     27            'post_type'   => 'subscrpt_order',
     28            'post_status' => array('active', 'pe_cancelled'),
     29            'fields'      => 'ids',
     30            'author'      => get_current_user_id(),
     31        );
     32
     33        $active_subscriptions = get_posts($args);
     34
     35        if ($active_subscriptions && count($active_subscriptions) > 0) {
     36            foreach ($active_subscriptions as $subscription) {
     37                $post_meta = get_post_meta($subscription, '_order_subscrpt_meta', true);
     38
     39                if (time() >= $post_meta['next_date'] || (null !== $post_meta['trial'] && time() >= $post_meta['start_date'])) {
     40                    if ('pe_cancelled' === get_post_status($subscription)) {
     41                        Action::status('cancelled', $subscription);
     42                    } else {
     43                        Action::status('expired', $subscription);
     44                    }
     45                }
    3346            }
    3447        }
  • subscription/trunk/includes/Illuminate/Email.php

    r2708268 r2927437  
    1515
    1616    public function add_subscription_table( $order ) {
    17         $post_meta = get_post_meta(
    18             $order->get_id(),
    19             '_order_subscrpt_full_data',
    20             true
    21         );
    22         if ( ! empty( $post_meta ) && is_array( $post_meta ) && count( $post_meta ) > 0 ) :
     17        $histories = Helper::get_subscriptions_from_order( $order->get_id() );
     18
     19        if ( count( $histories ) > 0 ) :
    2320            ?>
    2421            <div style="margin-bottom: 40px;">
     
    2926                        </tr>
    3027                        <?php
    31                         foreach ( $post_meta as $subscrpt_meta ) :
    32                             if ( ! empty( $subscrpt_meta ) && is_array( $subscrpt_meta ) ) :
    33                                 $post         = $subscrpt_meta['post_id'];
    34                                 $trial_status = $subscrpt_meta['trial'] == null ? false : true;
    35                                 $product_name = apply_filters( 'subscrpt_filter_product_name', get_the_title( $subscrpt_meta['product_id'] ), $subscrpt_meta );
    36                                 $product_link = apply_filters( 'subscrpt_filter_product_permalink', get_the_permalink( $subscrpt_meta['product_id'] ), $subscrpt_meta );
    37                                 ?>
     28                        foreach ( $histories as $history ) :
     29                            $item            = $order->get_item( $history->order_item_id );
     30                            $item_meta       = wc_get_order_item_meta( $history->order_item_id, '_subscrpt_meta', true );
     31                            $subscription_id = $history->subscription_id;
     32                            $has_trial       = isset( $item_meta['trial'] ) && strlen( $item_meta['trial'] ) > 2;
     33                            ?>
    3834                                <tr>
    39                                     <th class="td" scope="row" colspan="3" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: center;"><?php echo get_the_title( $post ); ?></th>
     35                                    <th class="td" scope="row" colspan="3" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: center;"><?php echo get_the_title( $subscription_id ); ?></th>
    4036                                </tr>
    4137                                <tr>
    42                                     <th class="td" scope="row" colspan="3" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><a href="<?php echo $product_link; ?>"><?php echo $product_name; ?></a>
    43                                         <strong class="product-quantity">×&nbsp;<?php echo esc_html( $subscrpt_meta['qty'] ); ?></strong>
     38                                    <th class="td" scope="row" colspan="3" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><a href="<?php echo get_permalink( $item->get_product_id() ); ?>"><?php echo $item->get_name(); ?></a>
     39                                        <strong class="product-quantity">×&nbsp;<?php echo esc_html( $item->get_quantity() ); ?></strong>
    4440                                    </th>
    4541                                </tr>
    4642                                <tr>
    4743                                    <th class="td" scope="row" colspan="2" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><?php _e( 'Status:', 'sdevs_subscrpt' ); ?> </th>
    48                                     <td class="td" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><?php echo get_post_status( $post ); ?></td>
     44                                    <td class="td" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><?php echo get_post_status( $subscription_id ); ?></td>
    4945                                </tr>
    5046                                <tr>
    5147                                    <th class="td" scope="row" colspan="2" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;">
    5248                                        <?php _e( 'Recurring amount:', 'sdevs_subscrpt' ); ?> </th>
    53                                     <td class="td" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><?php echo wp_kses_post( $subscrpt_meta['subtotal_price_html'] ); ?></td>
     49                                    <td class="td" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><?php echo Helper::format_price_with_order_item( $item->get_total(), $item->get_id() ); ?></td>
    5450                                </tr>
    55                                 <?php if ( $trial_status == null ) { ?>
     51                                <?php if ( ! $has_trial ) { ?>
    5652                                    <tr>
    5753                                        <th class="td" scope="row" colspan="2" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><?php _e( 'Next billing on', 'sdevs_subscrpt' ); ?>: </th>
    58                                         <td class="td" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><?php echo date( 'F d, Y', $subscrpt_meta['next_date'] ); ?></td>
     54                                        <td class="td" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><?php echo date( 'F d, Y', $item_meta['next_date'] ); ?></td>
    5955                                    </tr>
    6056                                <?php } else { ?>
    6157                                    <tr>
    6258                                        <th class="td" scope="row" colspan="2" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><?php _e( 'Trial', 'sdevs_subscrpt' ); ?>: </th>
    63                                         <td class="td" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><?php echo esc_html( $subscrpt_meta['trial'] ); ?></td>
     59                                        <td class="td" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><?php echo esc_html( $item_meta['trial'] ); ?></td>
    6460                                    </tr>
    6561                                    <tr>
    6662                                        <th class="td" scope="row" colspan="2" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><?php _e( 'First billing on', 'sdevs_subscrpt' ); ?>: </th>
    67                                         <td class="td" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><?php echo date( 'F d, Y', $subscrpt_meta['start_date'] ); ?></td>
     63                                        <td class="td" style="color: #636363; border: 1px solid #e5e5e5; vertical-align: middle; padding: 12px; text-align: left;"><?php echo date( 'F d, Y', $item_meta['start_date'] ); ?></td>
    6864                                    </tr>
    6965                                <?php } ?>
     
    7268                                </tr>
    7369                                <?php
    74                         endif;
    7570                        endforeach;
    7671                        ?>
  • subscription/trunk/includes/Illuminate/Helper.php

    r2708268 r2927437  
    2424    }
    2525
    26     public static function next_date( $time, $trial = null ) {
    27         if ( $trial == null ) {
     26    /**
     27     * Generate start date
     28     *
     29     * @param mixed       $time Time.
     30     * @param Null|String $trial Trial.
     31     *
     32     * @return String
     33     */
     34    public static function start_date( $time, $trial = null ) {
     35        if ( null === $trial ) {
    2836            $start_date = time();
    2937        } else {
    3038            $start_date = strtotime( $trial );
    3139        }
    32         return date( 'F d, Y', strtotime( $time, $start_date ) );
    33     }
    34 
    35     public static function CheckExpired( $product_id ) {
    36         $user_meta     = get_user_meta( get_current_user_id(), '_subscrpt_expired_items', true );
    37         $expired_items = array();
    38         if ( is_array( $user_meta ) ) {
    39             foreach ( $user_meta as $usermeta ) {
    40                 array_push( $expired_items, $usermeta['product'] );
     40        return wp_date( get_option( 'date_format' ), $start_date );
     41    }
     42
     43    /**
     44     * Generate next date
     45     *
     46     * @param mixed       $time Time.
     47     * @param Null|String $trial Trial.
     48     *
     49     * @return String
     50     */
     51    public static function next_date( $time, $trial = null ) {
     52        if ( null === $trial ) {
     53            $start_date = time();
     54        } else {
     55            $start_date = strtotime( $trial );
     56        }
     57        return wp_date( get_option( 'date_format' ), strtotime( $time, $start_date ) );
     58    }
     59
     60    /**
     61     * Check subscription exists by product ID.
     62     *
     63     * @param Int            $product_id Product ID.
     64     * @param String | array $status Status.
     65     *
     66     * @return \WP_Post | false
     67     */
     68    public static function subscription_exists( int $product_id, $status ) {
     69        $args = array(
     70            'post_type'   => 'subscrpt_order',
     71            'post_status' => $status,
     72            'fields'      => 'ids',
     73            'meta_query'  => array(
     74                array(
     75                    'key'   => '_subscrpt_product_id',
     76                    'value' => $product_id,
     77                ),
     78            ),
     79            'author'      => get_current_user_id(),
     80        );
     81
     82        $posts = get_posts( $args );
     83
     84        if ( count( $posts ) > 0 ) {
     85            return $posts[0];
     86        }
     87
     88        return false;
     89    }
     90
     91    /**
     92     * Check if product trial exixts for an user.
     93     *
     94     * @param Int $product_id Product ID.
     95     *
     96     * @return Boolean
     97     */
     98    public static function check_trial( int $product_id ): bool {
     99        return ! self::subscription_exists( $product_id, array( 'expired', 'pending', 'active', 'on-hold', 'pe_cancelled', 'cancelled' ) );
     100    }
     101
     102    /**
     103     * Rewew when expired.
     104     *
     105     * @param Int $subscription_id Subscription ID.
     106     */
     107    public static function renew( int $subscription_id ) {
     108        $post_meta = get_post_meta( $subscription_id, '_order_subscrpt_meta', true );
     109        if ( null !== $post_meta['trial'] ) {
     110            $post_meta['trial'] = null;
     111            update_post_meta( $subscription_id, '_order_subscrpt_meta', $post_meta );
     112        }
     113
     114        do_action( 'subscrpt_when_product_expired', $subscription_id, true );
     115    }
     116
     117    /**
     118     * Get Subscriptions Histories
     119     *
     120     * @param Int $order_id Order ID.
     121     */
     122    public static function get_subscriptions_from_order( $order_id ) {
     123        global $wpdb;
     124        $table_name = $wpdb->prefix . 'subscrpt_order_relation';
     125        $histories  = $wpdb->get_results(
     126            $wpdb->prepare(
     127                // @phpcs:ignore
     128                'SELECT * FROM %i WHERE order_id=%d',
     129                array( $table_name, $order_id )
     130            )
     131        );
     132
     133        return $histories;
     134    }
     135
     136    /**
     137     * Format price with Subscription
     138     *
     139     * @param mixed $price Price.
     140     * @param Int   $subscription_id Subscription ID.
     141     * @param bool  $display_trial True/False.
     142     *
     143     * @return mixed
     144     */
     145    public static function format_price_with_subscription( $price, $subscription_id, $display_trial = false ) {
     146        $subscription_meta = get_post_meta( $subscription_id, '_order_subscrpt_meta', true );
     147        $item_meta         = wc_get_order_item_meta( $subscription_meta['order_item_id'], '_subscrpt_meta', true );
     148
     149        $order = wc_get_order( $subscription_meta['order_id'] );
     150        $time  = '1' === $item_meta['time'] ? null : $item_meta['time'] . ' ';
     151        $type  = self::get_typos( $item_meta['time'], $item_meta['type'] );
     152
     153        $formatted_price = wc_price(
     154            $price,
     155            array(
     156                'currency' => $order->get_currency(),
     157            )
     158        ) . ' / ' . $time . $type;
     159
     160        if ( $display_trial ) {
     161            $trial     = $item_meta['trial'];
     162            $has_trial = isset( $item_meta['trial'] ) && strlen( $item_meta['trial'] ) > 2;
     163
     164            if ( $has_trial ) {
     165                $trial_html       = '<br/><small> + Got ' . $trial . ' free trial!</small>';
     166                $formatted_price .= $trial_html;
    41167            }
    42168        }
    43         return in_array( $product_id, $expired_items );
    44     }
    45 
    46     public static function Check_un_expired( $product_id ) {
    47         $author        = get_current_user_id();
    48         $active_items  = get_user_meta( $author, '_subscrpt_active_items', true );
    49         $pending_items = get_user_meta( $author, '_subscrpt_pending_items', true );
    50 
    51         if ( ! is_array( $active_items ) ) {
    52             $active_items = array();
    53         }
    54         if ( ! is_array( $pending_items ) ) {
    55             $pending_items = array();
    56         }
    57 
    58         foreach ( $active_items as $active_item ) {
    59             if ( $active_item['product'] == $product_id ) {
    60                 return true;
     169
     170        return apply_filters( 'subscrpt_format_price_with_subscription', $formatted_price, $price, $subscription_id );
     171    }
     172
     173    public static function format_price_with_order_item( $price, $item_id, $display_trial = false ) {
     174        $order_id = wc_get_order_id_by_order_item_id( $item_id );
     175        $order    = wc_get_order( $order_id );
     176
     177        $item_meta = wc_get_order_item_meta( $item_id, '_subscrpt_meta', true );
     178
     179        if ( ! $item_meta || ! is_array( $item_meta ) ) {
     180            return false;
     181        }
     182
     183        $time = $item_meta['time'] == 1 ? null : $item_meta['time'] . ' ';
     184        $type = self::get_typos( $item_meta['time'], $item_meta['type'] );
     185
     186        $formatted_price = wc_price(
     187            $price,
     188            array(
     189                'currency' => $order->get_currency(),
     190            )
     191        ) . ' / ' . $time . $type;
     192
     193        if ( $display_trial ) {
     194            $trial     = $item_meta['trial'];
     195            $has_trial = isset( $item_meta['trial'] ) && strlen( $item_meta['trial'] ) > 2;
     196
     197            if ( $has_trial ) {
     198                $trial_html       = '<br/><small> + Got ' . $trial . ' free trial!</small>';
     199                $formatted_price .= $trial_html;
    61200            }
    62201        }
    63202
    64         foreach ( $pending_items as $pending_item ) {
    65             if ( $pending_item['product'] == $product_id ) {
    66                 return true;
    67             }
    68         }
    69 
    70         return false;
    71     }
    72 
    73     public static function Check_Trial( $product_id ) {
    74         $result  = true;
    75         $author  = get_current_user_id();
    76         $product = wc_get_product( $product_id );
    77         if ( ! $product ) {
    78             return false;
    79         }
    80         $cancelled_items = get_user_meta( $author, '_subscrpt_cancelled_items', true );
    81         $expired_items   = get_user_meta( $author, '_subscrpt_expired_items', true );
    82         $active_items    = get_user_meta( $author, '_subscrpt_active_items', true );
    83         $pending_items   = get_user_meta( $author, '_subscrpt_pending_items', true );
    84 
    85         if ( ! is_array( $cancelled_items ) ) {
    86             $cancelled_items = array();
    87         }
    88         if ( ! is_array( $expired_items ) ) {
    89             $expired_items = array();
    90         }
    91         if ( ! is_array( $active_items ) ) {
    92             $active_items = array();
    93         }
    94         if ( ! is_array( $pending_items ) ) {
    95             $pending_items = array();
    96         }
    97 
    98         foreach ( $cancelled_items as $cancelled_item ) {
    99             if ( $cancelled_item['product'] == $product_id ) {
    100                 $result = false;
    101             }
    102         }
    103 
    104         foreach ( $expired_items as $expired_item ) {
    105             if ( $expired_item['product'] == $product_id ) {
    106                 $result = false;
    107             }
    108         }
    109 
    110         foreach ( $active_items as $active_item ) {
    111             if ( $active_item['product'] == $product_id ) {
    112                 $result = false;
    113             }
    114         }
    115 
    116         foreach ( $pending_items as $pending_item ) {
    117             if ( $pending_item['product'] == $product_id ) {
    118                 $result = false;
    119             }
    120         }
    121 
    122         if ( ! $product->is_type( 'variable' ) ) {
    123             return $result;
    124         }
    125         return apply_filters( 'subscrpt_filter_product_trial', $result, $product_id, $active_items, $pending_items, $cancelled_items, $expired_items );
     203        return apply_filters( 'subscrpt_format_price_with_subscription', $formatted_price, $price, $item_id );
     204    }
     205
     206        /**
     207         * Get total subscriptions by product ID.
     208         *
     209         * @param Int            $product_id Product ID.
     210         * @param String | array $status Status.
     211         *
     212         * @return \WP_Post | false
     213         */
     214    public static function get_total_subscriptions_from_product( int $product_id, $status = array( 'active', 'pending', 'expired', 'pe_cancelled', 'cancelled' ) ) {
     215        $args = array(
     216            'post_type'   => 'subscrpt_order',
     217            'post_status' => $status,
     218            'fields'      => 'ids',
     219            'meta_query'  => array(
     220                array(
     221                    'key'   => '_subscrpt_product_id',
     222                    'value' => $product_id,
     223                ),
     224            ),
     225        );
     226
     227        $posts = get_posts( $args );
     228
     229        return count( $posts );
    126230    }
    127231}
  • subscription/trunk/includes/Illuminate/Order.php

    r2708268 r2927437  
    1010class Order {
    1111
     12    /**
     13     * Initialize the class.
     14     */
    1215    public function __construct() {
    1316        add_filter( 'woocommerce_order_formatted_line_subtotal', array( $this, 'format_order_price' ), 10, 3 );
     
    1518        add_action( 'woocommerce_admin_order_item_values', array( $this, 'admin_order_item_value' ), 10, 2 );
    1619        add_action( 'woocommerce_before_order_itemmeta', array( $this, 'add_order_item_data' ), 10, 3 );
    17         // add_filter('woocommerce_order_amount_item_subtotal', function ($subtotal, $order, $item) {
    18         // $product = wc_get_product($item['product_id']);
    19         // if (!$product->is_type('simple')) return $subtotal;
    20         // $post_meta = get_post_meta($item['product_id'], 'subscrpt_general', true);
    21         // if (is_array($post_meta) && $post_meta['enable']) :
    22         // $time = $post_meta['time'] == 1 ? null : $post_meta['time'];
    23         // $type = Helper::get_typos($post_meta['time'], $post_meta["type"]);
    24         // $trial = null;
    25         // $has_trial = Helper::Check_Trial($item['product_id']);
    26         // if (!empty($post_meta['trial_time']) && $post_meta['trial_time'] > 0 && $has_trial) {
    27         // $trial = "<br/><small> + Get " . $post_meta['trial_time'] . " " . Helper::get_typos($post_meta['trial_time'], $post_meta['trial_type']) . " free trial!</small>";
    28         // }
    29         // $price_html = $subtotal . " / " . $time . " " . $type . $trial;
    30         // return $price_html;
    31         // else :
    32         // return $subtotal;
    33         // endif;
    34         // }, 10, 3);
    3520        add_action( 'woocommerce_order_status_changed', array( $this, 'order_status_changed' ) );
    36         // add_action('subscrpt_gateway_stripe_process_response', function ($response, $order) {
    37         // $order_meta = get_post_meta($order->get_id(), '_order_subscrpt_data', true);
    38         // if (empty($order_meta) || !is_array($order_meta) || !$order_meta['status']) return;
    39         // $post_id = $order_meta['posts'][0];
    40         // $post_meta = get_post_meta($post_id, '_subscrpt_order_general', true);
    41         // $product_meta = get_post_meta($post_meta['product_id'], 'subscrpt_general', true);
    42         // $type = Helper::get_typos($product_meta['time'], $product_meta["type"]);
    43         // if ('succeeded' === $response->status) {
    44         // $post_meta['start_date'] = time();
    45         // $post_meta['next_date'] = strtotime($product_meta['time'] . " " . $type);
    46         // update_post_meta($post_id, '_subscrpt_order_general', $post_meta);
    47         // $data = ["post" => $post_id, "product" => $post_meta['product_id']];
    48         // if (isset($post_meta['variation_id'])) $data['variation'] = $post_meta['variation_id'];
    49         // $order_history = get_post_meta($post_id, '_subscrpt_order_history', true);
    50         // if (!is_array($order_history)) $order_history = [];
    51         // array_push($order_history, $post_meta);
    52         // update_post_meta($post_id, '_subscrpt_order_history', $order_history);
    53         // }
    54         // }, 10, 2);
    5521    }
    5622
    5723    public function format_order_price( $subtotal, $item, $order ) {
    58         $product = wc_get_product( $item['product_id'] );
    59         if ( $product->is_type( 'variable' ) ) {
     24        $price_html = Helper::format_price_with_order_item(
     25            $item->get_subtotal(),
     26            $item->get_id(),
     27            true
     28        );
     29
     30        if ( ! $price_html ) {
    6031            return $subtotal;
    6132        }
    62         $order_data = get_post_meta( $order->get_id(), '_order_subscrpt_full_data', true );
    63         if ( ! is_array( $order_data ) ) {
    64             $order_data = array();
    65         }
    66         foreach ( $order_data as $post_meta ) {
    67             if ( is_array( $post_meta ) && isset( $post_meta['stats'] ) && $item['product_id'] == $post_meta['product_id'] ) :
    68                 $trial           = null;
    69                 $has_trial       = isset( $post_meta['trial'] ) && strlen( $post_meta['trial'] ) > 2;
    70                 $signup_fee_html = null;
    71                 if ( $has_trial ) {
    72                     $trial = '<br/><small> + Get ' . $post_meta['trial'] . ' ' . ' free trial!</small>';
    73                     if ( isset( $post_meta['signup_fee'] ) && $post_meta['signup_fee'] > 0 ) {
    74                         $signup_fee_html = '<br/> + Signup fee of ' . wc_price( $post_meta['signup_fee'] );
    75                     }
    76                 }
    77                 $price_html = $post_meta['subtotal_price_html'] . $signup_fee_html . $trial;
    78                 return $price_html;
    79             endif;
    80         }
    81         return $subtotal;
     33
     34        return $price_html;
    8235    }
    8336
     
    8942
    9043    public function admin_order_item_value( $product, $item ) {
    91         $subtotal   = '-';
    92         $order_data = get_post_meta( $item->get_order_id(), '_order_subscrpt_full_data', true );
    93         if ( ! is_array( $order_data ) ) {
    94             $order_data = array();
     44        if ( ! method_exists( $item, 'get_id' ) || ! method_exists( $item, 'get_subtotal' ) ) {
     45            return;
    9546        }
    96         foreach ( $order_data as $post_meta ) {
    97             if ( is_array( $post_meta ) && isset( $post_meta['stats'] ) && ! is_null( $product ) && $product->get_id() == $post_meta['product_id'] ) :
    98                 $subtotal = $post_meta['subtotal_price_html'];
    99             endif;
    100         }
     47
     48        $subtotal = '-';
     49        $item_id  = $item->get_id();
     50        $subtotal = Helper::format_price_with_order_item( $item->get_subtotal(), $item_id );
    10151        ?>
    10252        <td class="item_recurring" width="15%">
     
    11262            return;
    11363        }
    114         $order_data = get_post_meta( $item->get_order_id(), '_order_subscrpt_full_data', true );
    115         if ( ! is_array( $order_data ) ) {
    116             $order_data = array();
     64
     65        $item_meta = wc_get_order_item_meta( $item_id, '_subscrpt_meta', true );
     66
     67        if ( ! $item_meta || ! is_array( $item_meta ) ) {
     68            return false;
    11769        }
    118         foreach ( $order_data as $post_meta ) {
    119             if ( is_array( $post_meta ) && isset( $post_meta['stats'] ) && $product->get_id() == $post_meta['product_id'] ) :
    120                 $has_trial = isset( $post_meta['trial'] ) && strlen( $post_meta['trial'] ) > 2 ? true : false;
    121                 if ( $has_trial ) {
    122                     if ( isset( $post_meta['signup_fee'] ) && $post_meta['signup_fee'] > 0 ) {
    123                         echo '<small> + Signup fee of ' . wc_price( $post_meta['signup_fee'] ) . '</small><br/>';
    124                     }
    125                     echo '<small> + Get ' . wp_kses_post( $post_meta['trial'] ) . ' ' . ' free trial!</small>';
    126                 }
    127             endif;
     70
     71        $trial     = $item_meta['trial'];
     72        $has_trial = isset( $item_meta['trial'] ) && strlen( $item_meta['trial'] ) > 2;
     73
     74        if ( $has_trial ) {
     75            echo '<br/><small> + Got ' . $trial . ' free trial!</small>';
    12876        }
    12977    }
    13078
     79    /**
     80     * Take some actions based on order status changed.
     81     *
     82     * @param int $order_id Order Id.
     83     */
    13184    public function order_status_changed( $order_id ) {
    13285        $order       = new \WC_Order( $order_id );
     
    13588        switch ( $order->get_status() ) {
    13689            case 'on-hold':
    137             case 'pending';
     90            case 'pending':
    13891                $post_status = 'pending';
    13992                break;
     
    14194            case 'refunded':
    14295            case 'failed':
    143             case 'cancelled';
     96            case 'cancelled':
    14497                $post_status = 'cancelled';
    14598                break;
    14699
    147             default;
     100            default:
    148101                $post_status = 'active';
    149102                break;
    150103        }
    151         $order_meta = get_post_meta( $order_id, '_order_subscrpt_data', true );
    152         if ( empty( $order_meta ) || ! is_array( $order_meta ) ) {
    153             return;
    154         }
    155         if ( ! $order_meta['status'] ) {
    156             return;
    157         }
    158         foreach ( $order_meta['posts'] as $post ) {
    159             if ( get_the_title( $post ) != '' ) {
     104
     105        global $wpdb;
     106        $table_name = $wpdb->prefix . 'subscrpt_order_relation';
     107        // @phpcs:ignore
     108        $histories = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %i WHERE order_id=%d', array( $table_name, $order_id ) ) );
     109
     110        foreach ( $histories as $history ) {
     111            if ( 'new' === $history->type || 'renew' === $history->type ) {
    160112                wp_update_post(
    161113                    array(
    162                         'ID'          => $post,
     114                        'ID'          => $history->subscription_id,
    163115                        'post_status' => $post_status,
    164116                    )
    165117                );
    166                 $post_meta  = get_post_meta( $post, '_subscrpt_order_general', true );
    167                 $await_data = get_post_meta( $post, '_subscrpt_waiting_data', true );
    168                 if ( $order->get_status() == 'completed' ) {
    169                     if ( $await_data && is_array( $await_data ) ) {
    170                         $post_meta['next_date'] = $await_data['next_date'];
    171                         update_post_meta( $post, '_subscrpt_order_general', $post_meta );
    172                     }
    173                 }
    174                 $acdata = array(
    175                     'post'    => $post,
    176                     'product' => $post_meta['product_id'],
    177                 );
    178                 if ( isset( $post_meta['variation_id'] ) ) {
    179                     $acdata['variation'] = $post_meta['variation_id'];
    180                 }
    181                 Action::status( $post_status, $order->get_user_id(), $acdata );
     118
     119                Action::write_comment( $post_status, $history->subscription_id );
     120            } else {
     121                do_action( 'subscrpt_order_status_changed', $order, $history );
    182122            }
    183123        }
  • subscription/trunk/includes/Installer.php

    r2709135 r2927437  
    3535            wp_schedule_event( time(), 'daily', 'subscrpt_daily_cron' );
    3636        }
     37
     38        update_option( 'subscrpt_manual_renew_cart_notice', 'Subscriptional product added to cart. Please complete the checkout to renew subscription.' );
    3739    }
    3840
     
    4648            require_once ABSPATH . 'wp-admin/includes/upgrade.php';
    4749        }
     50
     51        $this->create_histories_table();
     52    }
     53
     54    /**
     55     * Create histories table
     56     *
     57     * @return void
     58     */
     59    public function create_histories_table() {
     60        global $wpdb;
     61
     62        $charset_collate = $wpdb->get_charset_collate();
     63        $table_name      = $wpdb->prefix . 'subscrpt_order_relation';
     64
     65        $schema = "CREATE TABLE IF NOT EXISTS `{$table_name}` (
     66                      `id` INT(255) NOT NULL AUTO_INCREMENT,
     67                      `subscription_id` INT(100) NOT NULL,
     68                      `order_id` INT(100) NOT NULL,
     69                      `order_item_id` INT(100) NOT NULL,
     70                      `type` VARCHAR(50) NOT NULL,
     71                      PRIMARY KEY (`id`)
     72                    ) $charset_collate";
     73
     74        dbDelta( $schema );
    4875    }
    4976}
  • subscription/trunk/includes/functions.php

    r2797349 r2927437  
    11<?php
    22
    3 function subscrpt_get_typos( $number, $typo ) {
    4     if ( $number == 1 && $typo == 'days' ) {
    5         return __( 'day', 'sdevs_subscrpt' );
    6     } elseif ( $number == 1 && $typo == 'weeks' ) {
    7         return __( 'week', 'sdevs_subscrpt' );
    8     } elseif ( $number == 1 && $typo == 'months' ) {
    9         return __( 'month', 'sdevs_subscrpt' );
    10     } elseif ( $number == 1 && $typo == 'years' ) {
    11         return __( 'year', 'sdevs_subscrpt' );
    12     } else {
    13         return $typo;
    14     }
     3/**
     4 * Generate Url for Subscription Action.
     5 *
     6 * @param String $action Action.
     7 * @param String $nonce nonce.
     8 * @param Int    $subscription_id Subscription ID.
     9 *
     10 * @return String
     11 */
     12function subscrpt_get_action_url($action, $nonce, $subscription_id)
     13{
     14    return add_query_arg(
     15        array(
     16            'subscrpt_id' => $subscription_id,
     17            'action'      => $action,
     18            'wpnonce'     => $nonce,
     19        ),
     20        wc_get_endpoint_url('view-subscription', $subscription_id, wc_get_page_permalink('myaccount'))
     21    );
    1522}
    1623
    17 function subscrpt_check_trial( $product_id ) {
    18     $result          = true;
    19     $author          = get_current_user_id();
    20     $product         = wc_get_product( $product_id );
    21     $cancelled_items = get_user_meta( $author, '_subscrpt_cancelled_items', true );
    22     $expired_items   = get_user_meta( $author, '_subscrpt_expired_items', true );
    23     $active_items    = get_user_meta( $author, '_subscrpt_active_items', true );
    24     $pending_items   = get_user_meta( $author, '_subscrpt_pending_items', true );
    2524
    26     if ( ! is_array( $cancelled_items ) ) {
    27         $cancelled_items = array();
    28     }
    29     if ( ! is_array( $expired_items ) ) {
    30         $expired_items = array();
    31     }
    32     if ( ! is_array( $active_items ) ) {
    33         $active_items = array();
    34     }
    35     if ( ! is_array( $pending_items ) ) {
    36         $pending_items = array();
    37     }
    38 
    39     foreach ( $cancelled_items as $cancelled_item ) {
    40         if ( $cancelled_item['product'] == $product_id ) {
    41             $result = false;
    42         }
    43     }
    44 
    45     foreach ( $expired_items as $expired_item ) {
    46         if ( $expired_item['product'] == $product_id ) {
    47             $result = false;
    48         }
    49     }
    50 
    51     foreach ( $active_items as $active_item ) {
    52         if ( $active_item['product'] == $product_id ) {
    53             $result = false;
    54         }
    55     }
    56 
    57     foreach ( $pending_items as $pending_item ) {
    58         if ( $pending_item['product'] == $product_id ) {
    59             $result = false;
    60         }
    61     }
    62 
    63     if ( $product->is_type( 'simple' ) ) {
    64         return $result;
    65     }
    66 
    67     return apply_filters( 'subscrpt_filter_product_trial', $result, $product_id, $active_items, $pending_items, $cancelled_items, $expired_items );
     25function subscrpt_get_typos($number, $typo)
     26{
     27    if ($number == 1 && $typo == 'days') {
     28        return __('day', 'sdevs_subscrpt');
     29    } elseif ($number == 1 && $typo == 'weeks') {
     30        return __('week', 'sdevs_subscrpt');
     31    } elseif ($number == 1 && $typo == 'months') {
     32        return __('month', 'sdevs_subscrpt');
     33    } elseif ($number == 1 && $typo == 'years') {
     34        return __('year', 'sdevs_subscrpt');
     35    } else {
     36        return $typo;
     37    }
    6838}
    6939
    70 function subscrpt_next_date( $time, $trial = null ) {
    71     if ( $trial == null ) {
    72         $start_date = time();
    73     } else {
    74         $start_date = strtotime( $trial );
    75     }
     40/**
     41 * Format time with trial.
     42 *
     43 * @param mixed       $time Time.
     44 * @param null|string $trial Trial.
     45 *
     46 * @return string
     47 */
     48function subscrpt_next_date($time, $trial = null)
     49{
     50    if (null === $trial) {
     51        $start_date = time();
     52    } else {
     53        $start_date = strtotime($trial);
     54    }
    7655
    77     return date( 'F d, Y', strtotime( $time, $start_date ) );
     56    return gmdate('F d, Y', strtotime($time, $start_date));
    7857}
    7958
    80 function subscrpt_check_unexpired( $product_id ) {
    81     $author        = get_current_user_id();
    82     $product       = wc_get_product( $product_id );
    83     $active_items  = get_user_meta( $author, '_subscrpt_active_items', true );
    84     $pending_items = get_user_meta( $author, '_subscrpt_pending_items', true );
    85 
    86     if ( ! is_array( $active_items ) ) {
    87         $active_items = array();
    88     }
    89     if ( ! is_array( $pending_items ) ) {
    90         $pending_items = array();
    91     }
    92 
    93     foreach ( $active_items as $active_item ) {
    94         if ( $active_item['product'] == $product_id ) {
    95             return true;
    96         }
    97     }
    98 
    99     foreach ( $pending_items as $pending_item ) {
    100         if ( $pending_item['product'] == $product_id ) {
    101             return true;
    102         }
    103     }
    104 
    105     if ( $product->is_type( 'simple' ) ) {
    106         return false;
    107     }
    108 
    109     return apply_filters( 'subscrpt_filter_check_unexpired', false, $product_id, $active_items, $pending_items );
     59/**
     60 * Check if subscription-pro activated.
     61 *
     62 * @return bool
     63 */
     64function subscrpt_pro_activated(): bool
     65{
     66    return class_exists('Sdevs_Wc_Subscription_Pro');
    11067}
    11168
    112 function subscrpt_pro_activated(): bool {
    113     return class_exists( 'Sdevs_Wc_Subscription_Pro' );
     69/**
     70 * Get renewal process settings.
     71 *
     72 * @return string
     73 */
     74function subscrpt_get_renewal_process()
     75{
     76    if (!subscrpt_pro_activated()) {
     77        return 'manual';
     78    } else {
     79        return get_option('subscrpt_renewal_process', 'auto');
     80    }
    11481}
     82
     83/**
     84 * Return Label against key.
     85 *
     86 * @param string $key Key to return cast Value.
     87 *
     88 * @return string
     89 */
     90function order_relation_type_cast(string $key)
     91{
     92    $relational_type_keys = apply_filters(
     93        'subscrpt_order_relational_types',
     94        array(
     95            'new'   => __('New Subscription Order', 'sdevs_subscrpt'),
     96            'renew' => __('Renewal Order', 'sdevs_subscrpt'),
     97        )
     98    );
     99
     100    return $relational_type_keys[$key];
     101}
  • subscription/trunk/readme.txt

    r2802189 r2927437  
    55Requires at least: 4.0
    66Tested up to: 5.9
    7 Stable tag: 1.0.3
     7Stable tag: 1.1
    88Requires PHP: 7.0
    99License: GPLv2 or later
     
    4949
    5050
    51 == Frequently Asked Questions ==
    52 
    53 = How to overwrite frontend templates ? =
    54 
    55 Just copy **myaccount** directory which is located in the **templates** folder & paste it to **yourtheme/subscription/**. Now you can customize templates under **myaccount** directory.
    56 
    57 = Is it compatible with all WordPress themes ? =
    58 
    59 Compatibility with all themes is impossible, because there are too many, but generally if themes are developed according to WordPress and WooCommerce guidelines, **Subscription for WooCommerce** is compatible with them.
    60 Sometimes, especially when new versions are released, it might only require some time for them to be all updated, but you can be sure that they will be tested and will be working in a few days.
    61 
    62 = Can I create subscriptions from the backend ? =
    63 
    64 **No** Currently this feature is not available.
    65 
    66 = Is it possible to set a minimum subscription time ? =
    67 
    68 **No** this is not possible, customers can cancel at any time.
    69 
    70 
    7151== Screenshots ==
    7252
     
    8666
    8767== Changelog ==
     68
     69= 1.1 =
     70- **Update:** We rebuild our plugin from scratch to provide better & long terms supports
     71- **Fix:** Severals UI & compatibility issues
    8872
    8973= 1.0.4 =
  • subscription/trunk/subscription.php

    r2797349 r2927437  
    44Plugin URI: https://wordpress.org/plugins/subscription
    55Description: Allow your customers to order once and get their products and services every month/week.
    6 Version: 1.0.4
     6Version: 1.1
    77Author: SpringDevs
    88Author URI: https://springdevs.com/
     
    3939 */
    4040
    41 // don't call the file directly
     41// don't call the file directly.
    4242if ( ! defined( 'ABSPATH' ) ) {
    4343    exit;
     
    5858     * @var string
    5959     */
    60     const version = '1.0.4';
     60    const version = '1.1';
    6161
    6262    /**
     
    103103     * Magic getter to bypass referencing plugin.
    104104     *
    105      * @param $prop
     105     * @param mixed $prop Prop.
    106106     *
    107107     * @return mixed
     
    118118     * Magic isset to bypass referencing plugin.
    119119     *
    120      * @param $prop
     120     * @param mixed $prop Prop.
    121121     *
    122122     * @return bool
    123     */
     123    */
    124124    public function __isset( $prop ) {
    125125        return isset( $this->{$prop} ) || isset( $this->container[ $prop ] );
     
    196196    public function init_hooks() {
    197197        add_action( 'init', array( $this, 'init_classes' ) );
    198 
    199         // Localize our plugin
    200198        add_action( 'init', array( $this, 'localization_setup' ) );
     199        add_action( 'init', array( $this, 'run_update' ) );
     200    }
     201
     202    /**
     203     * Need to do some actions after update plugin
     204     *
     205     * @return void
     206     */
     207    public function run_update() {
     208        $upgrade = new \SpringDevs\Subscription\Upgrade();
     209        $upgrade->run();
    201210    }
    202211
     
    208217    public function init_classes() {
    209218        if ( $this->is_request( 'ajax' ) ) {
    210             $this->container['ajax'] =  new SpringDevs\Subscription\Ajax();
     219            $this->container['ajax'] = new SpringDevs\Subscription\Ajax();
    211220        }
    212221
     
    257266 */
    258267function sdevs_subscription() {
    259      return Sdevs_Subscription::init();
     268    return Sdevs_Subscription::init();
    260269}
    261270
  • subscription/trunk/templates/myaccount/subscriptions.php

    r2797349 r2927437  
    77 */
    88
    9 $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
     9use SpringDevs\Subscription\Illuminate\Helper;
     10
     11$page_num = (get_query_var('paged')) ? get_query_var('paged') : 1;
    1012
    1113$args = array(
    1214    'author'         => get_current_user_id(),
    1315    'posts_per_page' => 10,
    14     'paged'          => $paged,
     16    'paged'          => $page_num,
    1517    'post_type'      => 'subscrpt_order',
    16     'post_status'    => array( 'pending', 'active', 'on_hold', 'cancelled', 'expired', 'pe_cancelled' ),
     18    'post_status'    => array('pending', 'active', 'on_hold', 'cancelled', 'expired', 'pe_cancelled'),
    1719);
    1820
    19 $postslist = new WP_Query( $args );
     21$postslist = new WP_Query($args);
    2022?>
    2123
    22 <table class="shop_table my_account_subscrpt">
     24<table class="woocommerce-orders-table woocommerce-MyAccount-orders shop_table shop_table_responsive my_account_orders account-orders-table my_account_subscrpt">
    2325    <thead>
    2426        <tr>
    25             <th scope="col" class="subscrpt-id"><?php esc_html_e( 'Subscription', 'sdevs_subscrpt' ); ?></th>
    26             <th scope="col" class="order-status"><?php esc_html_e( 'Status', 'sdevs_subscrpt' ); ?></th>
    27             <th scope="col" class="order-product"><?php esc_html_e( 'Product', 'sdevs_subscrpt' ); ?></th>
    28             <th scope="col" class="subscrpt-next-date"><?php esc_html_e( 'Next Payment', 'sdevs_subscrpt' ); ?></th>
    29             <th scope="col" class="subscrpt-total"><?php esc_html_e( 'Total', 'sdevs_subscrpt' ); ?></th>
     27            <th scope="col" class="subscrpt-id"><?php esc_html_e('Subscription', 'sdevs_subscrpt'); ?></th>
     28            <th scope="col" class="order-status"><?php esc_html_e('Status', 'sdevs_subscrpt'); ?></th>
     29            <th scope="col" class="order-product"><?php esc_html_e('Product', 'sdevs_subscrpt'); ?></th>
     30            <th scope="col" class="subscrpt-next-date"><?php esc_html_e('Next Payment', 'sdevs_subscrpt'); ?></th>
     31            <th scope="col" class="subscrpt-total"><?php esc_html_e('Total', 'sdevs_subscrpt'); ?></th>
    3032            <th scope="col" class="subscrpt-action"></th>
    3133        </tr>
     
    3335    <tbody>
    3436        <?php
    35         if ( $postslist->have_posts() ) :
    36             while ( $postslist->have_posts() ) :
     37        if ($postslist->have_posts()) :
     38            while ($postslist->have_posts()) :
    3739                $postslist->the_post();
    38                 $post_meta = get_post_meta( get_the_ID(), '_subscrpt_order_general', true );
    39                 $product   = wc_get_product( $post_meta['product_id'] );
    40                 if ( isset( $post_meta['variation_id'] ) ) {
    41                     $product_meta = get_post_meta( $post_meta['variation_id'], 'subscrpt_general', true );
    42                 } else {
    43                     $product_meta = $product->get_meta( 'subscrpt_general', true );
    44                 }
    45                 $product_name       = get_the_title( $post_meta['product_id'] );
    46                 $product_name       = apply_filters( 'subscrpt_filter_product_name', $product_name, $post_meta );
    47                 $product_link       = get_the_permalink( $post_meta['product_id'] );
    48                 $product_link       = apply_filters( 'subscrpt_filter_product_permalink', $product_link, $post_meta );
    49                 $time               = $product_meta['time'] == 1 ? null : $product_meta['time'];
    50                 $type               = subscrpt_get_typos( $product_meta['time'], $product_meta['type'] );
    51                 $product_price_html = wc_price( $product->get_price() * $post_meta['qty'] ) . ' / ' . $time . ' ' . $type;
    52                 $product_price_html = apply_filters( 'subscrpt_price_recurring', $product_price_html, $product, wc_get_order( $post_meta['order_id'] ), $post_meta['qty'] );
    53                 ?>
     40                $post_meta  = get_post_meta(get_the_ID(), '_order_subscrpt_meta', true);
     41                $product_id = get_post_meta(get_the_ID(), '_subscrpt_product_id', true);
     42                $order      = wc_get_order($post_meta['order_id']);
     43                $order_item = $order->get_item($post_meta['order_item_id']);
     44
     45                $post_status_object = get_post_status_object(get_post_status());
     46                $product_name       = $order_item->get_name();
     47                $product_link       = get_the_permalink($product_id);
     48                $product_price_html = Helper::format_price_with_order_item($order_item->get_total(), $order_item->get_id());
     49        ?>
    5450                <tr>
    5551                    <td><?php the_ID(); ?></td>
    56                     <td><span class="subscrpt-<?php echo get_post_status(); ?>"><?php echo get_post_status(); ?></span></td>
    57                     <td><a href="<?php echo esc_html( $product_link ); ?>" target="_blank"><?php echo esc_html( $product_name ); ?></a></td>
    58                     <?php if ( $post_meta['trial'] == null ) : ?>
    59                         <td><?php echo date( 'F d, Y', $post_meta['next_date'] ); ?></td>
     52                    <td><span class="subscrpt-<?php echo esc_attr($post_status_object->name); ?>"><?php echo esc_html(strlen($post_status_object->label) > 9 ? substr($post_status_object->label, 0, 6) . '...' : $post_status_object->label); ?></span></td>
     53                    <td><a href="<?php echo esc_html($product_link); ?>" target="_blank"><?php echo esc_html($product_name); ?></a></td>
     54                    <?php if ($post_meta['trial'] == null) : ?>
     55                        <td><?php echo date('F d, Y', $post_meta['next_date']); ?></td>
    6056                    <?php else : ?>
    61                         <td><small>First Billing : </small><?php echo date( 'F d, Y', $post_meta['start_date'] ); ?></td>
     57                        <td><small>First Billing : </small><?php echo date('F d, Y', $post_meta['start_date']); ?></td>
    6258                    <?php endif; ?>
    63                     <td><?php echo wp_kses_post( $product_price_html ); ?></td>
     59                    <td><?php echo wp_kses_post($product_price_html); ?></td>
    6460                    <td>
    65                         <a href="<?php echo get_permalink( wc_get_page_id( 'myaccount' ) ) . 'view-subscrpt/' . get_the_ID(); ?>" class="woocommerce-button button view">View</a>
     61                        <a href="<?php echo esc_html(wc_get_endpoint_url('view-subscription', get_the_ID(), wc_get_page_permalink('myaccount'))); ?>" class="woocommerce-button <?php echo esc_attr($wp_button_class); ?> button view"><span class="dashicons dashicons-visibility"></span></a>
    6662                    </td>
    6763                </tr>
    68                 <?php
     64        <?php
    6965            endwhile;
    70             next_posts_link( 'Older Entries', $postslist->max_num_pages );
    71             previous_posts_link( 'Next Entries &raquo;' );
     66            next_posts_link('Older Entries', $postslist->max_num_pages);
     67            previous_posts_link('Next Entries &raquo;');
    7268            wp_reset_postdata();
    7369        endif;
  • subscription/trunk/vendor/autoload.php

    r2797349 r2927437  
    33// autoload.php @generated by Composer
    44
     5if (PHP_VERSION_ID < 50600) {
     6    if (!headers_sent()) {
     7        header('HTTP/1.1 500 Internal Server Error');
     8    }
     9    $err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
     10    if (!ini_get('display_errors')) {
     11        if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
     12            fwrite(STDERR, $err);
     13        } elseif (!headers_sent()) {
     14            echo $err;
     15        }
     16    }
     17    trigger_error(
     18        $err,
     19        E_USER_ERROR
     20    );
     21}
     22
    523require_once __DIR__ . '/composer/autoload_real.php';
    624
    7 return ComposerAutoloaderInit9fa6d4e77b41bba2a0a04174377f1ff7::getLoader();
     25return ComposerAutoloaderInitea22a3b7d201ba553fedb2d49015d434::getLoader();
  • subscription/trunk/vendor/composer/ClassLoader.php

    r2708268 r2927437  
    4343class ClassLoader
    4444{
    45     /** @var ?string */
     45    /** @var \Closure(string):void */
     46    private static $includeFile;
     47
     48    /** @var string|null */
    4649    private $vendorDir;
    4750
    4851    // PSR-4
    4952    /**
    50      * @var array[]
    51      * @psalm-var array<string, array<string, int>>
     53     * @var array<string, array<string, int>>
    5254     */
    5355    private $prefixLengthsPsr4 = array();
    5456    /**
    55      * @var array[]
    56      * @psalm-var array<string, array<int, string>>
     57     * @var array<string, list<string>>
    5758     */
    5859    private $prefixDirsPsr4 = array();
    5960    /**
    60      * @var array[]
    61      * @psalm-var array<string, string>
     61     * @var list<string>
    6262     */
    6363    private $fallbackDirsPsr4 = array();
     
    6565    // PSR-0
    6666    /**
    67      * @var array[]
    68      * @psalm-var array<string, array<string, string[]>>
     67     * List of PSR-0 prefixes
     68     *
     69     * Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2')))
     70     *
     71     * @var array<string, array<string, list<string>>>
    6972     */
    7073    private $prefixesPsr0 = array();
    7174    /**
    72      * @var array[]
    73      * @psalm-var array<string, string>
     75     * @var list<string>
    7476     */
    7577    private $fallbackDirsPsr0 = array();
     
    7981
    8082    /**
    81      * @var string[]
    82      * @psalm-var array<string, string>
     83     * @var array<string, string>
    8384     */
    8485    private $classMap = array();
     
    8889
    8990    /**
    90      * @var bool[]
    91      * @psalm-var array<string, bool>
     91     * @var array<string, bool>
    9292     */
    9393    private $missingClasses = array();
    9494
    95     /** @var ?string */
     95    /** @var string|null */
    9696    private $apcuPrefix;
    9797
    9898    /**
    99      * @var self[]
     99     * @var array<string, self>
    100100     */
    101101    private static $registeredLoaders = array();
    102102
    103103    /**
    104      * @param ?string $vendorDir
     104     * @param string|null $vendorDir
    105105     */
    106106    public function __construct($vendorDir = null)
    107107    {
    108108        $this->vendorDir = $vendorDir;
    109     }
    110 
    111     /**
    112      * @return string[]
     109        self::initializeIncludeClosure();
     110    }
     111
     112    /**
     113     * @return array<string, list<string>>
    113114     */
    114115    public function getPrefixes()
     
    122123
    123124    /**
    124      * @return array[]
    125      * @psalm-return array<string, array<int, string>>
     125     * @return array<string, list<string>>
    126126     */
    127127    public function getPrefixesPsr4()
     
    131131
    132132    /**
    133      * @return array[]
    134      * @psalm-return array<string, string>
     133     * @return list<string>
    135134     */
    136135    public function getFallbackDirs()
     
    140139
    141140    /**
    142      * @return array[]
    143      * @psalm-return array<string, string>
     141     * @return list<string>
    144142     */
    145143    public function getFallbackDirsPsr4()
     
    149147
    150148    /**
    151      * @return string[] Array of classname => path
    152      * @psalm-return array<string, string>
     149     * @return array<string, string> Array of classname => path
    153150     */
    154151    public function getClassMap()
     
    158155
    159156    /**
    160      * @param string[] $classMap Class to filename map
    161      * @psalm-param array<string, string> $classMap
     157     * @param array<string, string> $classMap Class to filename map
    162158     *
    163159     * @return void
     
    176172     * appending or prepending to the ones previously set for this prefix.
    177173     *
    178      * @param string          $prefix  The prefix
    179      * @param string[]|string $paths   The PSR-0 root directories
    180      * @param bool            $prepend Whether to prepend the directories
     174     * @param string              $prefix  The prefix
     175     * @param list<string>|string $paths   The PSR-0 root directories
     176     * @param bool                $prepend Whether to prepend the directories
    181177     *
    182178     * @return void
     
    184180    public function add($prefix, $paths, $prepend = false)
    185181    {
     182        $paths = (array) $paths;
    186183        if (!$prefix) {
    187184            if ($prepend) {
    188185                $this->fallbackDirsPsr0 = array_merge(
    189                     (array) $paths,
     186                    $paths,
    190187                    $this->fallbackDirsPsr0
    191188                );
     
    193190                $this->fallbackDirsPsr0 = array_merge(
    194191                    $this->fallbackDirsPsr0,
    195                     (array) $paths
     192                    $paths
    196193                );
    197194            }
     
    202199        $first = $prefix[0];
    203200        if (!isset($this->prefixesPsr0[$first][$prefix])) {
    204             $this->prefixesPsr0[$first][$prefix] = (array) $paths;
     201            $this->prefixesPsr0[$first][$prefix] = $paths;
    205202
    206203            return;
     
    208205        if ($prepend) {
    209206            $this->prefixesPsr0[$first][$prefix] = array_merge(
    210                 (array) $paths,
     207                $paths,
    211208                $this->prefixesPsr0[$first][$prefix]
    212209            );
     
    214211            $this->prefixesPsr0[$first][$prefix] = array_merge(
    215212                $this->prefixesPsr0[$first][$prefix],
    216                 (array) $paths
     213                $paths
    217214            );
    218215        }
     
    223220     * appending or prepending to the ones previously set for this namespace.
    224221     *
    225      * @param string          $prefix  The prefix/namespace, with trailing '\\'
    226      * @param string[]|string $paths   The PSR-4 base directories
    227      * @param bool            $prepend Whether to prepend the directories
     222     * @param string              $prefix  The prefix/namespace, with trailing '\\'
     223     * @param list<string>|string $paths   The PSR-4 base directories
     224     * @param bool                $prepend Whether to prepend the directories
    228225     *
    229226     * @throws \InvalidArgumentException
     
    233230    public function addPsr4($prefix, $paths, $prepend = false)
    234231    {
     232        $paths = (array) $paths;
    235233        if (!$prefix) {
    236234            // Register directories for the root namespace.
    237235            if ($prepend) {
    238236                $this->fallbackDirsPsr4 = array_merge(
    239                     (array) $paths,
     237                    $paths,
    240238                    $this->fallbackDirsPsr4
    241239                );
     
    243241                $this->fallbackDirsPsr4 = array_merge(
    244242                    $this->fallbackDirsPsr4,
    245                     (array) $paths
     243                    $paths
    246244                );
    247245            }
     
    253251            }
    254252            $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
    255             $this->prefixDirsPsr4[$prefix] = (array) $paths;
     253            $this->prefixDirsPsr4[$prefix] = $paths;
    256254        } elseif ($prepend) {
    257255            // Prepend directories for an already registered namespace.
    258256            $this->prefixDirsPsr4[$prefix] = array_merge(
    259                 (array) $paths,
     257                $paths,
    260258                $this->prefixDirsPsr4[$prefix]
    261259            );
     
    264262            $this->prefixDirsPsr4[$prefix] = array_merge(
    265263                $this->prefixDirsPsr4[$prefix],
    266                 (array) $paths
     264                $paths
    267265            );
    268266        }
     
    273271     * replacing any others previously set for this prefix.
    274272     *
    275      * @param string          $prefix The prefix
    276      * @param string[]|string $paths  The PSR-0 base directories
     273     * @param string              $prefix The prefix
     274     * @param list<string>|string $paths  The PSR-0 base directories
    277275     *
    278276     * @return void
     
    291289     * replacing any others previously set for this namespace.
    292290     *
    293      * @param string          $prefix The prefix/namespace, with trailing '\\'
    294      * @param string[]|string $paths  The PSR-4 base directories
     291     * @param string              $prefix The prefix/namespace, with trailing '\\'
     292     * @param list<string>|string $paths  The PSR-4 base directories
    295293     *
    296294     * @throws \InvalidArgumentException
     
    426424    {
    427425        if ($file = $this->findFile($class)) {
    428             includeFile($file);
     426            $includeFile = self::$includeFile;
     427            $includeFile($file);
    429428
    430429            return true;
     
    477476
    478477    /**
    479      * Returns the currently registered loaders indexed by their corresponding vendor directories.
    480      *
    481      * @return self[]
     478     * Returns the currently registered loaders keyed by their corresponding vendor directories.
     479     *
     480     * @return array<string, self>
    482481     */
    483482    public static function getRegisteredLoaders()
     
    556555        return false;
    557556    }
     557
     558    /**
     559     * @return void
     560     */
     561    private static function initializeIncludeClosure()
     562    {
     563        if (self::$includeFile !== null) {
     564            return;
     565        }
     566
     567        /**
     568         * Scope isolated include.
     569         *
     570         * Prevents access to $this/self from included files.
     571         *
     572         * @param  string $file
     573         * @return void
     574         */
     575        self::$includeFile = \Closure::bind(static function($file) {
     576            include $file;
     577        }, null, null);
     578    }
    558579}
    559 
    560 /**
    561  * Scope isolated include.
    562  *
    563  * Prevents access to $this/self from included files.
    564  *
    565  * @param  string $file
    566  * @return void
    567  * @private
    568  */
    569 function includeFile($file)
    570 {
    571     include $file;
    572 }
  • subscription/trunk/vendor/composer/InstalledVersions.php

    r2708268 r2927437  
    2222 *
    2323 * To require its presence, you can require `composer-runtime-api ^2.0`
     24 *
     25 * @final
    2426 */
    2527class InstalledVersions
     
    2729    /**
    2830     * @var mixed[]|null
    29      * @psalm-var array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}|array{}|null
     31     * @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}|array{}|null
    3032     */
    3133    private static $installed;
     
    3840    /**
    3941     * @var array[]
    40      * @psalm-var array<string, array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
     42     * @psalm-var array<string, array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
    4143     */
    4244    private static $installedByVendor = array();
     
    9799        foreach (self::getInstalled() as $installed) {
    98100            if (isset($installed['versions'][$packageName])) {
    99                 return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']);
     101                return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false;
    100102            }
    101103        }
     
    118120    public static function satisfies(VersionParser $parser, $packageName, $constraint)
    119121    {
    120         $constraint = $parser->parseConstraints($constraint);
     122        $constraint = $parser->parseConstraints((string) $constraint);
    121123        $provided = $parser->parseConstraints(self::getVersionRanges($packageName));
    122124
     
    242244    /**
    243245     * @return array
    244      * @psalm-return array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}
     246     * @psalm-return array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}
    245247     */
    246248    public static function getRootPackage()
     
    256258     * @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect.
    257259     * @return array[]
    258      * @psalm-return array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}
     260     * @psalm-return array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}
    259261     */
    260262    public static function getRawData()
     
    279281     *
    280282     * @return array[]
    281      * @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
     283     * @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
    282284     */
    283285    public static function getAllRawData()
     
    302304     * @return void
    303305     *
    304      * @psalm-param array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>} $data
     306     * @psalm-param array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $data
    305307     */
    306308    public static function reload($data)
     
    312314    /**
    313315     * @return array[]
    314      * @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
     316     * @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
    315317     */
    316318    private static function getInstalled()
     
    327329                    $installed[] = self::$installedByVendor[$vendorDir];
    328330                } elseif (is_file($vendorDir.'/composer/installed.php')) {
    329                     $installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
     331                    /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
     332                    $required = require $vendorDir.'/composer/installed.php';
     333                    $installed[] = self::$installedByVendor[$vendorDir] = $required;
    330334                    if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
    331335                        self::$installed = $installed[count($installed) - 1];
     
    339343            // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
    340344            if (substr(__DIR__, -8, 1) !== 'C') {
    341                 self::$installed = require __DIR__ . '/installed.php';
     345                /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
     346                $required = require __DIR__ . '/installed.php';
     347                self::$installed = $required;
    342348            } else {
    343349                self::$installed = array();
    344350            }
    345351        }
    346         $installed[] = self::$installed;
     352
     353        if (self::$installed !== array()) {
     354            $installed[] = self::$installed;
     355        }
    347356
    348357        return $installed;
  • subscription/trunk/vendor/composer/autoload_classmap.php

    r2685408 r2927437  
    33// autoload_classmap.php @generated by Composer
    44
    5 $vendorDir = dirname(dirname(__FILE__));
     5$vendorDir = dirname(__DIR__);
    66$baseDir = dirname($vendorDir);
    77
  • subscription/trunk/vendor/composer/autoload_files.php

    r2685408 r2927437  
    33// autoload_files.php @generated by Composer
    44
    5 $vendorDir = dirname(dirname(__FILE__));
     5$vendorDir = dirname(__DIR__);
    66$baseDir = dirname($vendorDir);
    77
  • subscription/trunk/vendor/composer/autoload_namespaces.php

    r2685408 r2927437  
    33// autoload_namespaces.php @generated by Composer
    44
    5 $vendorDir = dirname(dirname(__FILE__));
     5$vendorDir = dirname(__DIR__);
    66$baseDir = dirname($vendorDir);
    77
  • subscription/trunk/vendor/composer/autoload_psr4.php

    r2685408 r2927437  
    33// autoload_psr4.php @generated by Composer
    44
    5 $vendorDir = dirname(dirname(__FILE__));
     5$vendorDir = dirname(__DIR__);
    66$baseDir = dirname($vendorDir);
    77
  • subscription/trunk/vendor/composer/autoload_real.php

    r2797349 r2927437  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInit9fa6d4e77b41bba2a0a04174377f1ff7
     5class ComposerAutoloaderInitea22a3b7d201ba553fedb2d49015d434
    66{
    77    private static $loader;
     
    2323        }
    2424
    25         spl_autoload_register(array('ComposerAutoloaderInit9fa6d4e77b41bba2a0a04174377f1ff7', 'loadClassLoader'), true, true);
    26         self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
    27         spl_autoload_unregister(array('ComposerAutoloaderInit9fa6d4e77b41bba2a0a04174377f1ff7', 'loadClassLoader'));
     25        spl_autoload_register(array('ComposerAutoloaderInitea22a3b7d201ba553fedb2d49015d434', 'loadClassLoader'), true, true);
     26        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
     27        spl_autoload_unregister(array('ComposerAutoloaderInitea22a3b7d201ba553fedb2d49015d434', 'loadClassLoader'));
    2828
    29         $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
    30         if ($useStaticLoader) {
    31             require __DIR__ . '/autoload_static.php';
    32 
    33             call_user_func(\Composer\Autoload\ComposerStaticInit9fa6d4e77b41bba2a0a04174377f1ff7::getInitializer($loader));
    34         } else {
    35             $map = require __DIR__ . '/autoload_namespaces.php';
    36             foreach ($map as $namespace => $path) {
    37                 $loader->set($namespace, $path);
    38             }
    39 
    40             $map = require __DIR__ . '/autoload_psr4.php';
    41             foreach ($map as $namespace => $path) {
    42                 $loader->setPsr4($namespace, $path);
    43             }
    44 
    45             $classMap = require __DIR__ . '/autoload_classmap.php';
    46             if ($classMap) {
    47                 $loader->addClassMap($classMap);
    48             }
    49         }
     29        require __DIR__ . '/autoload_static.php';
     30        call_user_func(\Composer\Autoload\ComposerStaticInitea22a3b7d201ba553fedb2d49015d434::getInitializer($loader));
    5031
    5132        $loader->register(true);
    5233
    53         if ($useStaticLoader) {
    54             $includeFiles = Composer\Autoload\ComposerStaticInit9fa6d4e77b41bba2a0a04174377f1ff7::$files;
    55         } else {
    56             $includeFiles = require __DIR__ . '/autoload_files.php';
    57         }
    58         foreach ($includeFiles as $fileIdentifier => $file) {
    59             composerRequire9fa6d4e77b41bba2a0a04174377f1ff7($fileIdentifier, $file);
     34        $filesToLoad = \Composer\Autoload\ComposerStaticInitea22a3b7d201ba553fedb2d49015d434::$files;
     35        $requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
     36            if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
     37                $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
     38
     39                require $file;
     40            }
     41        }, null, null);
     42        foreach ($filesToLoad as $fileIdentifier => $file) {
     43            $requireFile($fileIdentifier, $file);
    6044        }
    6145
     
    6347    }
    6448}
    65 
    66 /**
    67  * @param string $fileIdentifier
    68  * @param string $file
    69  * @return void
    70  */
    71 function composerRequire9fa6d4e77b41bba2a0a04174377f1ff7($fileIdentifier, $file)
    72 {
    73     if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
    74         $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
    75 
    76         require $file;
    77     }
    78 }
  • subscription/trunk/vendor/composer/autoload_static.php

    r2797349 r2927437  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInit9fa6d4e77b41bba2a0a04174377f1ff7
     7class ComposerStaticInitea22a3b7d201ba553fedb2d49015d434
    88{
    99    public static $files = array (
     
    3232    {
    3333        return \Closure::bind(function () use ($loader) {
    34             $loader->prefixLengthsPsr4 = ComposerStaticInit9fa6d4e77b41bba2a0a04174377f1ff7::$prefixLengthsPsr4;
    35             $loader->prefixDirsPsr4 = ComposerStaticInit9fa6d4e77b41bba2a0a04174377f1ff7::$prefixDirsPsr4;
    36             $loader->classMap = ComposerStaticInit9fa6d4e77b41bba2a0a04174377f1ff7::$classMap;
     34            $loader->prefixLengthsPsr4 = ComposerStaticInitea22a3b7d201ba553fedb2d49015d434::$prefixLengthsPsr4;
     35            $loader->prefixDirsPsr4 = ComposerStaticInitea22a3b7d201ba553fedb2d49015d434::$prefixDirsPsr4;
     36            $loader->classMap = ComposerStaticInitea22a3b7d201ba553fedb2d49015d434::$classMap;
    3737
    3838        }, null, ClassLoader::class);
  • subscription/trunk/vendor/composer/installed.php

    r2797349 r2927437  
    11<?php return array(
    22    'root' => array(
     3        'name' => 'springdevs/subscription',
    34        'pretty_version' => 'dev-next',
    45        'version' => 'dev-next',
     6        'reference' => '3bbd57215d40baa7b374ad001eebf3a5b4fa9f3a',
    57        'type' => 'wordpress-plugin',
    68        'install_path' => __DIR__ . '/../../',
    79        'aliases' => array(),
    8         'reference' => 'b79b1432d9114652e0e8fc961f6fd038209499d3',
    9         'name' => 'springdevs/subscription',
    1010        'dev' => false,
    1111    ),
     
    1414            'pretty_version' => 'dev-next',
    1515            'version' => 'dev-next',
     16            'reference' => '3bbd57215d40baa7b374ad001eebf3a5b4fa9f3a',
    1617            'type' => 'wordpress-plugin',
    1718            'install_path' => __DIR__ . '/../../',
    1819            'aliases' => array(),
    19             'reference' => 'b79b1432d9114652e0e8fc961f6fd038209499d3',
    2020            'dev_requirement' => false,
    2121        ),
Note: See TracChangeset for help on using the changeset viewer.