@@ -19,16 +19,16 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | // Define constants. |
| 21 | 21 | if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) { |
| 22 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
| 22 | + define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | if ( ! defined( 'WPINV_VERSION' ) ) { |
| 26 | - define( 'WPINV_VERSION', '2.8.9' ); |
|
| 26 | + define( 'WPINV_VERSION', '2.8.9' ); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | // Include the main Invoicing class. |
| 30 | 30 | if ( ! class_exists( 'WPInv_Plugin', false ) ) { |
| 31 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
| 31 | + require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | $GLOBALS['invoicing'] = new WPInv_Plugin(); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - return $GLOBALS['invoicing']; |
|
| 46 | + return $GLOBALS['invoicing']; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -14,620 +14,620 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class WPInv_Plugin { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * GetPaid version. |
|
| 19 | - * |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - public $version; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Data container. |
|
| 26 | - * |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - protected $data = array(); |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Form elements instance. |
|
| 33 | - * |
|
| 34 | - * @var WPInv_Payment_Form_Elements |
|
| 35 | - */ |
|
| 36 | - public $form_elements; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var array An array of payment gateways. |
|
| 40 | - */ |
|
| 41 | - public $gateways; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Class constructor. |
|
| 45 | - */ |
|
| 46 | - public function __construct() { |
|
| 47 | - $this->define_constants(); |
|
| 48 | - $this->includes(); |
|
| 49 | - $this->init_hooks(); |
|
| 50 | - $this->set_properties(); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Sets a custom data property. |
|
| 55 | - * |
|
| 56 | - * @param string $prop The prop to set. |
|
| 57 | - * @param mixed $value The value to retrieve. |
|
| 58 | - */ |
|
| 59 | - public function set( $prop, $value ) { |
|
| 60 | - $this->data[ $prop ] = $value; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Gets a custom data property. |
|
| 65 | - * |
|
| 66 | - * @param string $prop The prop to set. |
|
| 67 | - * @return mixed The value. |
|
| 68 | - */ |
|
| 69 | - public function get( $prop ) { |
|
| 70 | - if ( isset( $this->data[ $prop ] ) ) { |
|
| 71 | - return $this->data[ $prop ]; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - return null; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Define class properties. |
|
| 79 | - */ |
|
| 80 | - public function set_properties() { |
|
| 81 | - // Sessions. |
|
| 82 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 83 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 84 | - $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
| 85 | - |
|
| 86 | - // Init other objects. |
|
| 87 | - $this->set( 'notes', new WPInv_Notes() ); |
|
| 88 | - $this->set( 'api', new WPInv_API() ); |
|
| 89 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 90 | - $this->set( 'template', new GetPaid_Template() ); |
|
| 91 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
| 92 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 93 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 94 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 95 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 96 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 97 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Define plugin constants. |
|
| 102 | - */ |
|
| 103 | - public function define_constants() { |
|
| 104 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 105 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 106 | - $this->version = WPINV_VERSION; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Hook into actions and filters. |
|
| 111 | - * |
|
| 112 | - * @since 1.0.19 |
|
| 113 | - */ |
|
| 114 | - protected function init_hooks() { |
|
| 115 | - /* Internationalize the text strings used. */ |
|
| 116 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 117 | - |
|
| 118 | - // Init the plugin after WordPress inits. |
|
| 119 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 120 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 121 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 122 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 123 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
| 124 | - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
| 125 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 126 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 127 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 128 | - add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
| 129 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 130 | - |
|
| 131 | - add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
| 132 | - add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
| 133 | - add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
| 134 | - |
|
| 135 | - // Fires after registering actions. |
|
| 136 | - do_action( 'wpinv_actions', $this ); |
|
| 137 | - do_action( 'getpaid_actions', $this ); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - public function plugins_loaded() { |
|
| 141 | - /* Internationalize the text strings used. */ |
|
| 142 | - $this->load_textdomain(); |
|
| 143 | - |
|
| 144 | - do_action( 'wpinv_loaded' ); |
|
| 145 | - |
|
| 146 | - // Fix oxygen page builder conflict |
|
| 147 | - if ( function_exists( 'ct_css_output' ) ) { |
|
| 148 | - wpinv_oxygen_fix_conflict(); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Load Localisation files. |
|
| 154 | - * |
|
| 155 | - * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
| 156 | - * |
|
| 157 | - * Locales found in: |
|
| 158 | - * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
| 159 | - * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
| 160 | - * |
|
| 161 | - * @since 1.0.0 |
|
| 162 | - */ |
|
| 163 | - public function load_textdomain() { |
|
| 164 | - // Determines the current locale. |
|
| 165 | - if ( function_exists( 'determine_locale' ) ) { |
|
| 166 | - $locale = determine_locale(); |
|
| 167 | - } else if ( function_exists( 'get_user_locale' ) ) { |
|
| 168 | - $locale = get_user_locale(); |
|
| 169 | - } else { |
|
| 170 | - $locale = get_locale(); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Filter the locale to use for translations. |
|
| 175 | - */ |
|
| 176 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 177 | - |
|
| 178 | - unload_textdomain( 'invoicing' ); |
|
| 179 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 180 | - load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' ); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * Include required core files used in admin and on the frontend. |
|
| 185 | - */ |
|
| 186 | - public function includes() { |
|
| 187 | - // Start with the settings. |
|
| 188 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
| 189 | - |
|
| 190 | - // Packages/libraries. |
|
| 191 | - require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
| 192 | - require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
| 193 | - |
|
| 194 | - // Load functions. |
|
| 195 | - require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
| 196 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
| 197 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
| 198 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
| 199 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
| 200 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
| 201 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
| 202 | - require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
| 203 | - require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
| 204 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
| 205 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
| 206 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
| 207 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
| 208 | - require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
| 209 | - require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
| 210 | - |
|
| 211 | - // Register autoloader. |
|
| 212 | - try { |
|
| 213 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 214 | - } catch ( Exception $e ) { |
|
| 215 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
| 219 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
| 220 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
| 221 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
| 222 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
| 223 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
| 224 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
| 225 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
| 226 | - require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
| 227 | - require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
| 228 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
| 229 | - require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
| 230 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
| 231 | - require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
| 232 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
| 233 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
| 234 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
| 235 | - require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
| 236 | - require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
| 237 | - require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
| 238 | - require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
| 239 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
| 240 | - |
|
| 241 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 242 | - GetPaid_Post_Types_Admin::init(); |
|
| 243 | - |
|
| 244 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
| 245 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
| 246 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
| 247 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
| 248 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
| 249 | - require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
| 250 | - // load the user class only on the users.php page |
|
| 251 | - global $pagenow; |
|
| 252 | - if ( $pagenow == 'users.php' ) { |
|
| 253 | - new WPInv_Admin_Users(); |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - // Register cli commands |
|
| 258 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 259 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
| 260 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Class autoloader |
|
| 266 | - * |
|
| 267 | - * @param string $class_name The name of the class to load. |
|
| 268 | - * @access public |
|
| 269 | - * @since 1.0.19 |
|
| 270 | - * @return void |
|
| 271 | - */ |
|
| 272 | - public function autoload( $class_name ) { |
|
| 273 | - // Normalize the class name... |
|
| 274 | - $class_name = strtolower( $class_name ); |
|
| 275 | - |
|
| 276 | - // ... and make sure it is our class. |
|
| 277 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 278 | - return; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - // Next, prepare the file name from the class. |
|
| 282 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 283 | - |
|
| 284 | - // Base path of the classes. |
|
| 285 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 286 | - |
|
| 287 | - // And an array of possible locations in order of importance. |
|
| 288 | - $locations = array( |
|
| 289 | - "$plugin_path/includes", |
|
| 290 | - "$plugin_path/includes/data-stores", |
|
| 291 | - "$plugin_path/includes/gateways", |
|
| 292 | - "$plugin_path/includes/payments", |
|
| 293 | - "$plugin_path/includes/geolocation", |
|
| 294 | - "$plugin_path/includes/reports", |
|
| 295 | - "$plugin_path/includes/api", |
|
| 296 | - "$plugin_path/includes/admin", |
|
| 297 | - "$plugin_path/includes/admin/meta-boxes", |
|
| 298 | - ); |
|
| 299 | - |
|
| 300 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 301 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 302 | - include trailingslashit( $location ) . $file_name; |
|
| 303 | - break; |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * Inits hooks etc. |
|
| 310 | - */ |
|
| 311 | - public function init() { |
|
| 312 | - // Fires before getpaid inits. |
|
| 313 | - do_action( 'before_getpaid_init', $this ); |
|
| 314 | - |
|
| 315 | - // Maybe upgrade. |
|
| 316 | - $this->maybe_upgrade_database(); |
|
| 317 | - |
|
| 318 | - // Load default gateways. |
|
| 319 | - $gateways = apply_filters( |
|
| 320 | - 'getpaid_default_gateways', |
|
| 321 | - array( |
|
| 322 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
| 323 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 324 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 325 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 326 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 327 | - ) |
|
| 328 | - ); |
|
| 329 | - |
|
| 330 | - foreach ( $gateways as $id => $class ) { |
|
| 331 | - $this->gateways[ $id ] = new $class(); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
| 335 | - GetPaid_Installer::rename_gateways_label(); |
|
| 336 | - update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - // Fires after getpaid inits. |
|
| 340 | - do_action( 'getpaid_init', $this ); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Checks if this is an IPN request and processes it. |
|
| 345 | - */ |
|
| 346 | - public function maybe_process_ipn() { |
|
| 347 | - // Ensure that this is an IPN request. |
|
| 348 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 349 | - return; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
| 353 | - |
|
| 354 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 355 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 356 | - exit; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - public function enqueue_scripts() { |
|
| 360 | - // Fires before adding scripts. |
|
| 361 | - do_action( 'getpaid_enqueue_scripts' ); |
|
| 362 | - |
|
| 363 | - $localize = array(); |
|
| 364 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 365 | - $localize['thousands'] = wpinv_thousands_separator(); |
|
| 366 | - $localize['decimals'] = wpinv_decimal_separator(); |
|
| 367 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 368 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 369 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 370 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 371 | - $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
| 372 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 373 | - $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
|
| 374 | - |
|
| 375 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 376 | - |
|
| 377 | - // reCaptcha. |
|
| 378 | - if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) { |
|
| 379 | - wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 383 | - wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
| 384 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - public function wpinv_actions() { |
|
| 388 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 389 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
| 393 | - include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * Fires an action after verifying that a user can fire them. |
|
| 399 | - * |
|
| 400 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
| 401 | - * current user owns the invoice/subscription. |
|
| 402 | - */ |
|
| 403 | - public function maybe_do_authenticated_action() { |
|
| 404 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
| 405 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
| 406 | - $data = wp_unslash( $_REQUEST ); |
|
| 407 | - |
|
| 408 | - if ( is_user_logged_in() ) { |
|
| 409 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - public function pre_get_posts( $wp_query ) { |
|
| 417 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 418 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - return $wp_query; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Register widgets |
|
| 426 | - * |
|
| 427 | - */ |
|
| 428 | - public function register_widgets() { |
|
| 429 | - global $pagenow; |
|
| 430 | - |
|
| 431 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
| 432 | - // So we disable our widgets when editing a page with UX Builder. |
|
| 433 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
| 434 | - return; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
| 438 | - |
|
| 439 | - if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
| 440 | - // don't initiate in these conditions. |
|
| 441 | - } else { |
|
| 442 | - // Only load allowed widgets. |
|
| 443 | - $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
| 444 | - $widgets = apply_filters( |
|
| 445 | - 'getpaid_widget_classes', |
|
| 446 | - array( |
|
| 447 | - 'WPInv_Checkout_Widget', |
|
| 448 | - 'WPInv_History_Widget', |
|
| 449 | - 'WPInv_Receipt_Widget', |
|
| 450 | - 'WPInv_Subscriptions_Widget', |
|
| 451 | - 'WPInv_Buy_Item_Widget', |
|
| 452 | - 'WPInv_Messages_Widget', |
|
| 453 | - 'WPInv_GetPaid_Widget', |
|
| 454 | - 'WPInv_Invoice_Widget', |
|
| 455 | - ) |
|
| 456 | - ); |
|
| 457 | - |
|
| 458 | - // For each widget... |
|
| 459 | - foreach ( $widgets as $widget ) { |
|
| 460 | - // Abort early if it is excluded for this page. |
|
| 461 | - if ( in_array( $widget, $exclude ) ) { |
|
| 462 | - continue; |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
| 466 | - if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
| 467 | - register_widget( $widget ); |
|
| 468 | - } else { |
|
| 469 | - new $widget(); |
|
| 470 | - } |
|
| 471 | - } |
|
| 472 | - } |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - /** |
|
| 476 | - * Upgrades the database. |
|
| 477 | - * |
|
| 478 | - * @since 2.0.2 |
|
| 479 | - */ |
|
| 480 | - public function maybe_upgrade_database() { |
|
| 481 | - // Ensure the database tables are up to date. |
|
| 482 | - GetPaid_Installer::maybe_create_db_tables(); |
|
| 483 | - |
|
| 484 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
| 485 | - |
|
| 486 | - if ( $wpi_version == WPINV_VERSION ) { |
|
| 487 | - return; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - $installer = new GetPaid_Installer(); |
|
| 491 | - |
|
| 492 | - if ( empty( $wpi_version ) ) { |
|
| 493 | - return $installer->upgrade_db( 0 ); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - $upgrades = array( |
|
| 497 | - '0.0.5' => '004', |
|
| 498 | - '1.0.3' => '102', |
|
| 499 | - '2.0.0' => '118', |
|
| 500 | - '2.8.0' => '279', |
|
| 501 | - ); |
|
| 502 | - |
|
| 503 | - foreach ( $upgrades as $key => $method ) { |
|
| 504 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
| 505 | - return $installer->upgrade_db( $method ); |
|
| 506 | - } |
|
| 507 | - } |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - /** |
|
| 511 | - * Flushes the permalinks if needed. |
|
| 512 | - * |
|
| 513 | - * @since 2.0.8 |
|
| 514 | - */ |
|
| 515 | - public function maybe_flush_permalinks() { |
|
| 516 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
| 517 | - |
|
| 518 | - if ( ! empty( $flush ) ) { |
|
| 519 | - flush_rewrite_rules(); |
|
| 520 | - delete_option( 'wpinv_flush_permalinks' ); |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * Remove our pages from yoast sitemaps. |
|
| 526 | - * |
|
| 527 | - * @since 1.0.19 |
|
| 528 | - * @param int[] $excluded_posts_ids |
|
| 529 | - */ |
|
| 530 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
| 531 | - // Ensure that we have an array. |
|
| 532 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 533 | - $excluded_posts_ids = array(); |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - // Prepare our pages. |
|
| 537 | - $our_pages = array(); |
|
| 538 | - |
|
| 539 | - // Checkout page. |
|
| 540 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 541 | - |
|
| 542 | - // Success page. |
|
| 543 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 544 | - |
|
| 545 | - // Failure page. |
|
| 546 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 547 | - |
|
| 548 | - // History page. |
|
| 549 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 550 | - |
|
| 551 | - // Subscriptions page. |
|
| 552 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 553 | - |
|
| 554 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 555 | - |
|
| 556 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 557 | - |
|
| 558 | - return array_unique( $excluded_posts_ids ); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * Remove our pages from yoast sitemaps. |
|
| 563 | - * |
|
| 564 | - * @since 1.0.19 |
|
| 565 | - * @param string[] $post_types |
|
| 566 | - */ |
|
| 567 | - public function exclude_invoicing_post_types( $post_types ) { |
|
| 568 | - // Ensure that we have an array. |
|
| 569 | - if ( ! is_array( $post_types ) ) { |
|
| 570 | - $post_types = array(); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - // Remove our post types. |
|
| 574 | - return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * Displays additional footer code. |
|
| 579 | - * |
|
| 580 | - * @since 2.0.0 |
|
| 581 | - */ |
|
| 582 | - public function wp_footer() { |
|
| 583 | - wpinv_get_template( 'frontend-footer.php' ); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - /** |
|
| 587 | - * Displays additional header code. |
|
| 588 | - * |
|
| 589 | - * @since 2.0.0 |
|
| 590 | - */ |
|
| 591 | - public function wp_head() { |
|
| 592 | - wpinv_get_template( 'frontend-head.php' ); |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * Custom query vars. |
|
| 597 | - * |
|
| 598 | - */ |
|
| 599 | - public function custom_query_vars( $vars ) { |
|
| 600 | - $vars[] = 'getpaid-ipn'; |
|
| 601 | - return $vars; |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * Add rewrite tags and rules. |
|
| 606 | - * |
|
| 607 | - */ |
|
| 608 | - public function add_rewrite_rule() { |
|
| 609 | - $tag = 'getpaid-ipn'; |
|
| 610 | - add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
| 611 | - add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - /** |
|
| 615 | - * Processes non-query string ipns. |
|
| 616 | - * |
|
| 617 | - */ |
|
| 618 | - public function maybe_process_new_ipn( $query ) { |
|
| 619 | - if ( is_admin() || ! $query->is_main_query() ) { |
|
| 620 | - return; |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - $gateway = get_query_var( 'getpaid-ipn' ); |
|
| 624 | - |
|
| 625 | - if ( ! empty( $gateway ) ) { |
|
| 626 | - $gateway = sanitize_text_field( $gateway ); |
|
| 627 | - nocache_headers(); |
|
| 628 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 629 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 630 | - exit; |
|
| 631 | - } |
|
| 632 | - } |
|
| 17 | + /** |
|
| 18 | + * GetPaid version. |
|
| 19 | + * |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + public $version; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Data container. |
|
| 26 | + * |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + protected $data = array(); |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Form elements instance. |
|
| 33 | + * |
|
| 34 | + * @var WPInv_Payment_Form_Elements |
|
| 35 | + */ |
|
| 36 | + public $form_elements; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var array An array of payment gateways. |
|
| 40 | + */ |
|
| 41 | + public $gateways; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Class constructor. |
|
| 45 | + */ |
|
| 46 | + public function __construct() { |
|
| 47 | + $this->define_constants(); |
|
| 48 | + $this->includes(); |
|
| 49 | + $this->init_hooks(); |
|
| 50 | + $this->set_properties(); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Sets a custom data property. |
|
| 55 | + * |
|
| 56 | + * @param string $prop The prop to set. |
|
| 57 | + * @param mixed $value The value to retrieve. |
|
| 58 | + */ |
|
| 59 | + public function set( $prop, $value ) { |
|
| 60 | + $this->data[ $prop ] = $value; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Gets a custom data property. |
|
| 65 | + * |
|
| 66 | + * @param string $prop The prop to set. |
|
| 67 | + * @return mixed The value. |
|
| 68 | + */ |
|
| 69 | + public function get( $prop ) { |
|
| 70 | + if ( isset( $this->data[ $prop ] ) ) { |
|
| 71 | + return $this->data[ $prop ]; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + return null; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Define class properties. |
|
| 79 | + */ |
|
| 80 | + public function set_properties() { |
|
| 81 | + // Sessions. |
|
| 82 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
| 83 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
| 84 | + $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
| 85 | + |
|
| 86 | + // Init other objects. |
|
| 87 | + $this->set( 'notes', new WPInv_Notes() ); |
|
| 88 | + $this->set( 'api', new WPInv_API() ); |
|
| 89 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
| 90 | + $this->set( 'template', new GetPaid_Template() ); |
|
| 91 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
| 92 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
| 93 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
| 94 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
| 95 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
| 96 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
| 97 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Define plugin constants. |
|
| 102 | + */ |
|
| 103 | + public function define_constants() { |
|
| 104 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 105 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 106 | + $this->version = WPINV_VERSION; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Hook into actions and filters. |
|
| 111 | + * |
|
| 112 | + * @since 1.0.19 |
|
| 113 | + */ |
|
| 114 | + protected function init_hooks() { |
|
| 115 | + /* Internationalize the text strings used. */ |
|
| 116 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 117 | + |
|
| 118 | + // Init the plugin after WordPress inits. |
|
| 119 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
| 120 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
| 121 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
| 122 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
| 123 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
| 124 | + add_action( 'wp_footer', array( $this, 'wp_footer' ) ); |
|
| 125 | + add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 126 | + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 127 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
| 128 | + add_filter( 'the_seo_framework_sitemap_supported_post_types', array( $this, 'exclude_invoicing_post_types' ) ); |
|
| 129 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 130 | + |
|
| 131 | + add_filter( 'query_vars', array( $this, 'custom_query_vars' ) ); |
|
| 132 | + add_action( 'init', array( $this, 'add_rewrite_rule' ), 10, 0 ); |
|
| 133 | + add_action( 'pre_get_posts', array( $this, 'maybe_process_new_ipn' ), 1 ); |
|
| 134 | + |
|
| 135 | + // Fires after registering actions. |
|
| 136 | + do_action( 'wpinv_actions', $this ); |
|
| 137 | + do_action( 'getpaid_actions', $this ); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + public function plugins_loaded() { |
|
| 141 | + /* Internationalize the text strings used. */ |
|
| 142 | + $this->load_textdomain(); |
|
| 143 | + |
|
| 144 | + do_action( 'wpinv_loaded' ); |
|
| 145 | + |
|
| 146 | + // Fix oxygen page builder conflict |
|
| 147 | + if ( function_exists( 'ct_css_output' ) ) { |
|
| 148 | + wpinv_oxygen_fix_conflict(); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Load Localisation files. |
|
| 154 | + * |
|
| 155 | + * Note: the first-loaded translation file overrides any following ones if the same translation is present. |
|
| 156 | + * |
|
| 157 | + * Locales found in: |
|
| 158 | + * - WP_LANG_DIR/plugins/invoicing-LOCALE.mo |
|
| 159 | + * - WP_PLUGIN_DIR/invoicing/languages/invoicing-LOCALE.mo |
|
| 160 | + * |
|
| 161 | + * @since 1.0.0 |
|
| 162 | + */ |
|
| 163 | + public function load_textdomain() { |
|
| 164 | + // Determines the current locale. |
|
| 165 | + if ( function_exists( 'determine_locale' ) ) { |
|
| 166 | + $locale = determine_locale(); |
|
| 167 | + } else if ( function_exists( 'get_user_locale' ) ) { |
|
| 168 | + $locale = get_user_locale(); |
|
| 169 | + } else { |
|
| 170 | + $locale = get_locale(); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Filter the locale to use for translations. |
|
| 175 | + */ |
|
| 176 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 177 | + |
|
| 178 | + unload_textdomain( 'invoicing' ); |
|
| 179 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 180 | + load_plugin_textdomain( 'invoicing', false, plugin_basename( dirname( WPINV_PLUGIN_FILE ) ) . '/languages/' ); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * Include required core files used in admin and on the frontend. |
|
| 185 | + */ |
|
| 186 | + public function includes() { |
|
| 187 | + // Start with the settings. |
|
| 188 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'; |
|
| 189 | + |
|
| 190 | + // Packages/libraries. |
|
| 191 | + require_once WPINV_PLUGIN_DIR . 'vendor/autoload.php'; |
|
| 192 | + require_once WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'; |
|
| 193 | + |
|
| 194 | + // Load functions. |
|
| 195 | + require_once WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'; |
|
| 196 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'; |
|
| 197 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'; |
|
| 198 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'; |
|
| 199 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'; |
|
| 200 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'; |
|
| 201 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'; |
|
| 202 | + require_once WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'; |
|
| 203 | + require_once WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'; |
|
| 204 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'; |
|
| 205 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'; |
|
| 206 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'; |
|
| 207 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'; |
|
| 208 | + require_once WPINV_PLUGIN_DIR . 'includes/user-functions.php'; |
|
| 209 | + require_once WPINV_PLUGIN_DIR . 'includes/error-functions.php'; |
|
| 210 | + |
|
| 211 | + // Register autoloader. |
|
| 212 | + try { |
|
| 213 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
| 214 | + } catch ( Exception $e ) { |
|
| 215 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'; |
|
| 219 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'; |
|
| 220 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'; |
|
| 221 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'; |
|
| 222 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'; |
|
| 223 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'; |
|
| 224 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'; |
|
| 225 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'; |
|
| 226 | + require_once WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'; |
|
| 227 | + require_once WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'; |
|
| 228 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'; |
|
| 229 | + require_once WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'; |
|
| 230 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'; |
|
| 231 | + require_once WPINV_PLUGIN_DIR . 'widgets/checkout.php'; |
|
| 232 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'; |
|
| 233 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'; |
|
| 234 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'; |
|
| 235 | + require_once WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'; |
|
| 236 | + require_once WPINV_PLUGIN_DIR . 'widgets/buy-item.php'; |
|
| 237 | + require_once WPINV_PLUGIN_DIR . 'widgets/getpaid.php'; |
|
| 238 | + require_once WPINV_PLUGIN_DIR . 'widgets/invoice.php'; |
|
| 239 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'; |
|
| 240 | + |
|
| 241 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 242 | + GetPaid_Post_Types_Admin::init(); |
|
| 243 | + |
|
| 244 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'; |
|
| 245 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'; |
|
| 246 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'; |
|
| 247 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'; |
|
| 248 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'; |
|
| 249 | + require_once WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'; |
|
| 250 | + // load the user class only on the users.php page |
|
| 251 | + global $pagenow; |
|
| 252 | + if ( $pagenow == 'users.php' ) { |
|
| 253 | + new WPInv_Admin_Users(); |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + // Register cli commands |
|
| 258 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 259 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'; |
|
| 260 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Class autoloader |
|
| 266 | + * |
|
| 267 | + * @param string $class_name The name of the class to load. |
|
| 268 | + * @access public |
|
| 269 | + * @since 1.0.19 |
|
| 270 | + * @return void |
|
| 271 | + */ |
|
| 272 | + public function autoload( $class_name ) { |
|
| 273 | + // Normalize the class name... |
|
| 274 | + $class_name = strtolower( $class_name ); |
|
| 275 | + |
|
| 276 | + // ... and make sure it is our class. |
|
| 277 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
| 278 | + return; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + // Next, prepare the file name from the class. |
|
| 282 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
| 283 | + |
|
| 284 | + // Base path of the classes. |
|
| 285 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
| 286 | + |
|
| 287 | + // And an array of possible locations in order of importance. |
|
| 288 | + $locations = array( |
|
| 289 | + "$plugin_path/includes", |
|
| 290 | + "$plugin_path/includes/data-stores", |
|
| 291 | + "$plugin_path/includes/gateways", |
|
| 292 | + "$plugin_path/includes/payments", |
|
| 293 | + "$plugin_path/includes/geolocation", |
|
| 294 | + "$plugin_path/includes/reports", |
|
| 295 | + "$plugin_path/includes/api", |
|
| 296 | + "$plugin_path/includes/admin", |
|
| 297 | + "$plugin_path/includes/admin/meta-boxes", |
|
| 298 | + ); |
|
| 299 | + |
|
| 300 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
| 301 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
| 302 | + include trailingslashit( $location ) . $file_name; |
|
| 303 | + break; |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * Inits hooks etc. |
|
| 310 | + */ |
|
| 311 | + public function init() { |
|
| 312 | + // Fires before getpaid inits. |
|
| 313 | + do_action( 'before_getpaid_init', $this ); |
|
| 314 | + |
|
| 315 | + // Maybe upgrade. |
|
| 316 | + $this->maybe_upgrade_database(); |
|
| 317 | + |
|
| 318 | + // Load default gateways. |
|
| 319 | + $gateways = apply_filters( |
|
| 320 | + 'getpaid_default_gateways', |
|
| 321 | + array( |
|
| 322 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
| 323 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
| 324 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
| 325 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
| 326 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
| 327 | + ) |
|
| 328 | + ); |
|
| 329 | + |
|
| 330 | + foreach ( $gateways as $id => $class ) { |
|
| 331 | + $this->gateways[ $id ] = new $class(); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) { |
|
| 335 | + GetPaid_Installer::rename_gateways_label(); |
|
| 336 | + update_option( 'wpinv_renamed_gateways', 'yes' ); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + // Fires after getpaid inits. |
|
| 340 | + do_action( 'getpaid_init', $this ); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Checks if this is an IPN request and processes it. |
|
| 345 | + */ |
|
| 346 | + public function maybe_process_ipn() { |
|
| 347 | + // Ensure that this is an IPN request. |
|
| 348 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
| 349 | + return; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + $gateway = sanitize_text_field( $_GET['wpi-gateway'] ); |
|
| 353 | + |
|
| 354 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 355 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 356 | + exit; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + public function enqueue_scripts() { |
|
| 360 | + // Fires before adding scripts. |
|
| 361 | + do_action( 'getpaid_enqueue_scripts' ); |
|
| 362 | + |
|
| 363 | + $localize = array(); |
|
| 364 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 365 | + $localize['thousands'] = wpinv_thousands_separator(); |
|
| 366 | + $localize['decimals'] = wpinv_decimal_separator(); |
|
| 367 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 368 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
| 369 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
| 370 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
| 371 | + $localize['loading'] = __( 'Loading...', 'invoicing' ); |
|
| 372 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
| 373 | + $localize['recaptchaSettings'] = getpaid_get_recaptcha_settings(); |
|
| 374 | + |
|
| 375 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 376 | + |
|
| 377 | + // reCaptcha. |
|
| 378 | + if ( getpaid_is_recaptcha_enabled() && ( $recaptcha_js = getpaid_recaptcha_api_url() ) ) { |
|
| 379 | + wp_enqueue_script( 'recaptcha', $recaptcha_js, array(), null, true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
| 383 | + wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ), $version, true ); |
|
| 384 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + public function wpinv_actions() { |
|
| 388 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 389 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + if ( defined( 'WP_ALL_IMPORT_ROOT_DIR' ) ) { |
|
| 393 | + include plugin_dir_path( __FILE__ ) . 'libraries/wp-all-import/class-getpaid-wp-all-import.php'; |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * Fires an action after verifying that a user can fire them. |
|
| 399 | + * |
|
| 400 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
| 401 | + * current user owns the invoice/subscription. |
|
| 402 | + */ |
|
| 403 | + public function maybe_do_authenticated_action() { |
|
| 404 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
| 405 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
| 406 | + $data = wp_unslash( $_REQUEST ); |
|
| 407 | + |
|
| 408 | + if ( is_user_logged_in() ) { |
|
| 409 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + public function pre_get_posts( $wp_query ) { |
|
| 417 | + if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 418 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + return $wp_query; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Register widgets |
|
| 426 | + * |
|
| 427 | + */ |
|
| 428 | + public function register_widgets() { |
|
| 429 | + global $pagenow; |
|
| 430 | + |
|
| 431 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
| 432 | + // So we disable our widgets when editing a page with UX Builder. |
|
| 433 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
| 434 | + return; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + $block_widget_init_screens = function_exists( 'sd_pagenow_exclude' ) ? sd_pagenow_exclude() : array(); |
|
| 438 | + |
|
| 439 | + if ( is_admin() && $pagenow && in_array( $pagenow, $block_widget_init_screens ) ) { |
|
| 440 | + // don't initiate in these conditions. |
|
| 441 | + } else { |
|
| 442 | + // Only load allowed widgets. |
|
| 443 | + $exclude = function_exists( 'sd_widget_exclude' ) ? sd_widget_exclude() : array(); |
|
| 444 | + $widgets = apply_filters( |
|
| 445 | + 'getpaid_widget_classes', |
|
| 446 | + array( |
|
| 447 | + 'WPInv_Checkout_Widget', |
|
| 448 | + 'WPInv_History_Widget', |
|
| 449 | + 'WPInv_Receipt_Widget', |
|
| 450 | + 'WPInv_Subscriptions_Widget', |
|
| 451 | + 'WPInv_Buy_Item_Widget', |
|
| 452 | + 'WPInv_Messages_Widget', |
|
| 453 | + 'WPInv_GetPaid_Widget', |
|
| 454 | + 'WPInv_Invoice_Widget', |
|
| 455 | + ) |
|
| 456 | + ); |
|
| 457 | + |
|
| 458 | + // For each widget... |
|
| 459 | + foreach ( $widgets as $widget ) { |
|
| 460 | + // Abort early if it is excluded for this page. |
|
| 461 | + if ( in_array( $widget, $exclude ) ) { |
|
| 462 | + continue; |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + // SD V1 used to extend the widget class. V2 does not, so we cannot call register widget on it. |
|
| 466 | + if ( is_subclass_of( $widget, 'WP_Widget' ) ) { |
|
| 467 | + register_widget( $widget ); |
|
| 468 | + } else { |
|
| 469 | + new $widget(); |
|
| 470 | + } |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * Upgrades the database. |
|
| 477 | + * |
|
| 478 | + * @since 2.0.2 |
|
| 479 | + */ |
|
| 480 | + public function maybe_upgrade_database() { |
|
| 481 | + // Ensure the database tables are up to date. |
|
| 482 | + GetPaid_Installer::maybe_create_db_tables(); |
|
| 483 | + |
|
| 484 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
| 485 | + |
|
| 486 | + if ( $wpi_version == WPINV_VERSION ) { |
|
| 487 | + return; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + $installer = new GetPaid_Installer(); |
|
| 491 | + |
|
| 492 | + if ( empty( $wpi_version ) ) { |
|
| 493 | + return $installer->upgrade_db( 0 ); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + $upgrades = array( |
|
| 497 | + '0.0.5' => '004', |
|
| 498 | + '1.0.3' => '102', |
|
| 499 | + '2.0.0' => '118', |
|
| 500 | + '2.8.0' => '279', |
|
| 501 | + ); |
|
| 502 | + |
|
| 503 | + foreach ( $upgrades as $key => $method ) { |
|
| 504 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
| 505 | + return $installer->upgrade_db( $method ); |
|
| 506 | + } |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + /** |
|
| 511 | + * Flushes the permalinks if needed. |
|
| 512 | + * |
|
| 513 | + * @since 2.0.8 |
|
| 514 | + */ |
|
| 515 | + public function maybe_flush_permalinks() { |
|
| 516 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
| 517 | + |
|
| 518 | + if ( ! empty( $flush ) ) { |
|
| 519 | + flush_rewrite_rules(); |
|
| 520 | + delete_option( 'wpinv_flush_permalinks' ); |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * Remove our pages from yoast sitemaps. |
|
| 526 | + * |
|
| 527 | + * @since 1.0.19 |
|
| 528 | + * @param int[] $excluded_posts_ids |
|
| 529 | + */ |
|
| 530 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ) { |
|
| 531 | + // Ensure that we have an array. |
|
| 532 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
| 533 | + $excluded_posts_ids = array(); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + // Prepare our pages. |
|
| 537 | + $our_pages = array(); |
|
| 538 | + |
|
| 539 | + // Checkout page. |
|
| 540 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
| 541 | + |
|
| 542 | + // Success page. |
|
| 543 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
| 544 | + |
|
| 545 | + // Failure page. |
|
| 546 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
| 547 | + |
|
| 548 | + // History page. |
|
| 549 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
| 550 | + |
|
| 551 | + // Subscriptions page. |
|
| 552 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
| 553 | + |
|
| 554 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
| 555 | + |
|
| 556 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
| 557 | + |
|
| 558 | + return array_unique( $excluded_posts_ids ); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * Remove our pages from yoast sitemaps. |
|
| 563 | + * |
|
| 564 | + * @since 1.0.19 |
|
| 565 | + * @param string[] $post_types |
|
| 566 | + */ |
|
| 567 | + public function exclude_invoicing_post_types( $post_types ) { |
|
| 568 | + // Ensure that we have an array. |
|
| 569 | + if ( ! is_array( $post_types ) ) { |
|
| 570 | + $post_types = array(); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + // Remove our post types. |
|
| 574 | + return array_diff( $post_types, array_keys( getpaid_get_invoice_post_types() ) ); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * Displays additional footer code. |
|
| 579 | + * |
|
| 580 | + * @since 2.0.0 |
|
| 581 | + */ |
|
| 582 | + public function wp_footer() { |
|
| 583 | + wpinv_get_template( 'frontend-footer.php' ); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + /** |
|
| 587 | + * Displays additional header code. |
|
| 588 | + * |
|
| 589 | + * @since 2.0.0 |
|
| 590 | + */ |
|
| 591 | + public function wp_head() { |
|
| 592 | + wpinv_get_template( 'frontend-head.php' ); |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * Custom query vars. |
|
| 597 | + * |
|
| 598 | + */ |
|
| 599 | + public function custom_query_vars( $vars ) { |
|
| 600 | + $vars[] = 'getpaid-ipn'; |
|
| 601 | + return $vars; |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * Add rewrite tags and rules. |
|
| 606 | + * |
|
| 607 | + */ |
|
| 608 | + public function add_rewrite_rule() { |
|
| 609 | + $tag = 'getpaid-ipn'; |
|
| 610 | + add_rewrite_tag( "%$tag%", '([^&]+)' ); |
|
| 611 | + add_rewrite_rule( "^$tag/([^/]*)/?", "index.php?$tag=\$matches[1]", 'top' ); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + /** |
|
| 615 | + * Processes non-query string ipns. |
|
| 616 | + * |
|
| 617 | + */ |
|
| 618 | + public function maybe_process_new_ipn( $query ) { |
|
| 619 | + if ( is_admin() || ! $query->is_main_query() ) { |
|
| 620 | + return; |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + $gateway = get_query_var( 'getpaid-ipn' ); |
|
| 624 | + |
|
| 625 | + if ( ! empty( $gateway ) ) { |
|
| 626 | + $gateway = sanitize_text_field( $gateway ); |
|
| 627 | + nocache_headers(); |
|
| 628 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
| 629 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
| 630 | + exit; |
|
| 631 | + } |
|
| 632 | + } |
|
| 633 | 633 | } |
@@ -14,143 +14,143 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class WPInv_Subscriptions_Widget extends WP_Super_Duper { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Register the widget with WordPress. |
|
| 19 | - * |
|
| 20 | - */ |
|
| 21 | - public function __construct() { |
|
| 22 | - |
|
| 23 | - $options = array( |
|
| 24 | - 'textdomain' => 'invoicing', |
|
| 25 | - 'block-icon' => 'controls-repeat', |
|
| 26 | - 'block-category' => 'widgets', |
|
| 27 | - 'block-keywords' => "['invoicing','subscriptions', 'getpaid']", |
|
| 28 | - 'class_name' => __CLASS__, |
|
| 29 | - 'base_id' => 'wpinv_subscriptions', |
|
| 30 | - 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
| 31 | - 'widget_ops' => array( |
|
| 32 | - 'classname' => 'getpaid-subscriptions bsui', |
|
| 33 | - 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
| 34 | - ), |
|
| 35 | - 'arguments' => array( |
|
| 36 | - 'title' => array( |
|
| 37 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
| 38 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
| 39 | - 'type' => 'text', |
|
| 40 | - 'desc_tip' => true, |
|
| 41 | - 'default' => '', |
|
| 42 | - 'advanced' => false, |
|
| 43 | - ), |
|
| 44 | - ), |
|
| 45 | - |
|
| 46 | - ); |
|
| 47 | - |
|
| 48 | - parent::__construct( $options ); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Retrieves current user's subscriptions. |
|
| 53 | - * |
|
| 54 | - * @return GetPaid_Subscriptions_Query |
|
| 55 | - */ |
|
| 56 | - public function get_subscriptions() { |
|
| 57 | - |
|
| 58 | - // Prepare license args. |
|
| 59 | - $args = array( |
|
| 60 | - 'customer_in' => get_current_user_id(), |
|
| 61 | - 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
| 62 | - ); |
|
| 63 | - |
|
| 64 | - return new GetPaid_Subscriptions_Query( $args ); |
|
| 65 | - |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * The Super block output function. |
|
| 70 | - * |
|
| 71 | - * @param array $args |
|
| 72 | - * @param array $widget_args |
|
| 73 | - * @param string $content |
|
| 74 | - * |
|
| 75 | - * @return mixed|string|bool |
|
| 76 | - */ |
|
| 77 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 78 | - |
|
| 79 | - // Ensure that the user is logged in. |
|
| 80 | - if ( ! is_user_logged_in() ) { |
|
| 81 | - |
|
| 82 | - return aui()->alert( |
|
| 83 | - array( |
|
| 84 | - 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
| 85 | - 'type' => 'error', |
|
| 86 | - ) |
|
| 87 | - ); |
|
| 88 | - |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // Are we displaying a single subscription? |
|
| 92 | - if ( isset( $_GET['subscription'] ) ) { |
|
| 93 | - return $this->display_single_subscription( intval( $_GET['subscription'] ) ); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - // Retrieve the user's subscriptions. |
|
| 97 | - $subscriptions = $this->get_subscriptions(); |
|
| 98 | - |
|
| 99 | - // Start the output buffer. |
|
| 100 | - ob_start(); |
|
| 101 | - |
|
| 102 | - // Backwards compatibility. |
|
| 103 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
| 104 | - |
|
| 105 | - // Display errors and notices. |
|
| 106 | - wpinv_print_errors(); |
|
| 107 | - |
|
| 108 | - do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
| 109 | - |
|
| 110 | - // Print the table header. |
|
| 111 | - $this->print_table_header(); |
|
| 112 | - |
|
| 113 | - // Print table body. |
|
| 114 | - $this->print_table_body( $subscriptions->get_results() ); |
|
| 115 | - |
|
| 116 | - // Print table footer. |
|
| 117 | - $this->print_table_footer(); |
|
| 118 | - |
|
| 119 | - // Print the navigation. |
|
| 120 | - $this->print_navigation( $subscriptions->get_total() ); |
|
| 121 | - |
|
| 122 | - // Backwards compatibility. |
|
| 123 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
| 124 | - |
|
| 125 | - // Return the output. |
|
| 126 | - return ob_get_clean(); |
|
| 127 | - |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Retrieves the subscription columns. |
|
| 132 | - * |
|
| 133 | - * @return array |
|
| 134 | - */ |
|
| 135 | - public function get_subscriptions_table_columns() { |
|
| 17 | + /** |
|
| 18 | + * Register the widget with WordPress. |
|
| 19 | + * |
|
| 20 | + */ |
|
| 21 | + public function __construct() { |
|
| 22 | + |
|
| 23 | + $options = array( |
|
| 24 | + 'textdomain' => 'invoicing', |
|
| 25 | + 'block-icon' => 'controls-repeat', |
|
| 26 | + 'block-category' => 'widgets', |
|
| 27 | + 'block-keywords' => "['invoicing','subscriptions', 'getpaid']", |
|
| 28 | + 'class_name' => __CLASS__, |
|
| 29 | + 'base_id' => 'wpinv_subscriptions', |
|
| 30 | + 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
| 31 | + 'widget_ops' => array( |
|
| 32 | + 'classname' => 'getpaid-subscriptions bsui', |
|
| 33 | + 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
| 34 | + ), |
|
| 35 | + 'arguments' => array( |
|
| 36 | + 'title' => array( |
|
| 37 | + 'title' => __( 'Widget title', 'invoicing' ), |
|
| 38 | + 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
| 39 | + 'type' => 'text', |
|
| 40 | + 'desc_tip' => true, |
|
| 41 | + 'default' => '', |
|
| 42 | + 'advanced' => false, |
|
| 43 | + ), |
|
| 44 | + ), |
|
| 45 | + |
|
| 46 | + ); |
|
| 47 | + |
|
| 48 | + parent::__construct( $options ); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Retrieves current user's subscriptions. |
|
| 53 | + * |
|
| 54 | + * @return GetPaid_Subscriptions_Query |
|
| 55 | + */ |
|
| 56 | + public function get_subscriptions() { |
|
| 57 | + |
|
| 58 | + // Prepare license args. |
|
| 59 | + $args = array( |
|
| 60 | + 'customer_in' => get_current_user_id(), |
|
| 61 | + 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
| 62 | + ); |
|
| 63 | + |
|
| 64 | + return new GetPaid_Subscriptions_Query( $args ); |
|
| 65 | + |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * The Super block output function. |
|
| 70 | + * |
|
| 71 | + * @param array $args |
|
| 72 | + * @param array $widget_args |
|
| 73 | + * @param string $content |
|
| 74 | + * |
|
| 75 | + * @return mixed|string|bool |
|
| 76 | + */ |
|
| 77 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 78 | + |
|
| 79 | + // Ensure that the user is logged in. |
|
| 80 | + if ( ! is_user_logged_in() ) { |
|
| 81 | + |
|
| 82 | + return aui()->alert( |
|
| 83 | + array( |
|
| 84 | + 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
| 85 | + 'type' => 'error', |
|
| 86 | + ) |
|
| 87 | + ); |
|
| 88 | + |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // Are we displaying a single subscription? |
|
| 92 | + if ( isset( $_GET['subscription'] ) ) { |
|
| 93 | + return $this->display_single_subscription( intval( $_GET['subscription'] ) ); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + // Retrieve the user's subscriptions. |
|
| 97 | + $subscriptions = $this->get_subscriptions(); |
|
| 98 | + |
|
| 99 | + // Start the output buffer. |
|
| 100 | + ob_start(); |
|
| 101 | + |
|
| 102 | + // Backwards compatibility. |
|
| 103 | + do_action( 'wpinv_before_user_subscriptions' ); |
|
| 104 | + |
|
| 105 | + // Display errors and notices. |
|
| 106 | + wpinv_print_errors(); |
|
| 107 | + |
|
| 108 | + do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
| 109 | + |
|
| 110 | + // Print the table header. |
|
| 111 | + $this->print_table_header(); |
|
| 112 | + |
|
| 113 | + // Print table body. |
|
| 114 | + $this->print_table_body( $subscriptions->get_results() ); |
|
| 115 | + |
|
| 116 | + // Print table footer. |
|
| 117 | + $this->print_table_footer(); |
|
| 118 | + |
|
| 119 | + // Print the navigation. |
|
| 120 | + $this->print_navigation( $subscriptions->get_total() ); |
|
| 121 | + |
|
| 122 | + // Backwards compatibility. |
|
| 123 | + do_action( 'wpinv_after_user_subscriptions' ); |
|
| 124 | + |
|
| 125 | + // Return the output. |
|
| 126 | + return ob_get_clean(); |
|
| 127 | + |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Retrieves the subscription columns. |
|
| 132 | + * |
|
| 133 | + * @return array |
|
| 134 | + */ |
|
| 135 | + public function get_subscriptions_table_columns() { |
|
| 136 | 136 | |
| 137 | - $columns = array( |
|
| 138 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 139 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 140 | - 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
| 141 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 142 | - ); |
|
| 137 | + $columns = array( |
|
| 138 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 139 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 140 | + 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
| 141 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 142 | + ); |
|
| 143 | 143 | |
| 144 | - return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
| 145 | - } |
|
| 144 | + return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * Displays the table header. |
|
| 149 | - * |
|
| 150 | - */ |
|
| 151 | - public function print_table_header() { |
|
| 147 | + /** |
|
| 148 | + * Displays the table header. |
|
| 149 | + * |
|
| 150 | + */ |
|
| 151 | + public function print_table_header() { |
|
| 152 | 152 | |
| 153 | - ?> |
|
| 153 | + ?> |
|
| 154 | 154 | |
| 155 | 155 | <table class="table table-bordered table-striped"> |
| 156 | 156 | |
@@ -166,122 +166,122 @@ discard block |
||
| 166 | 166 | |
| 167 | 167 | <?php |
| 168 | 168 | |
| 169 | - } |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /** |
|
| 172 | - * Displays the table body. |
|
| 173 | - * |
|
| 174 | - * @param WPInv_Subscription[] $subscriptions |
|
| 175 | - */ |
|
| 176 | - public function print_table_body( $subscriptions ) { |
|
| 171 | + /** |
|
| 172 | + * Displays the table body. |
|
| 173 | + * |
|
| 174 | + * @param WPInv_Subscription[] $subscriptions |
|
| 175 | + */ |
|
| 176 | + public function print_table_body( $subscriptions ) { |
|
| 177 | 177 | |
| 178 | - if ( empty( $subscriptions ) ) { |
|
| 179 | - $this->print_table_body_no_subscriptions(); |
|
| 180 | - } else { |
|
| 181 | - $this->print_table_body_subscriptions( $subscriptions ); |
|
| 182 | - } |
|
| 178 | + if ( empty( $subscriptions ) ) { |
|
| 179 | + $this->print_table_body_no_subscriptions(); |
|
| 180 | + } else { |
|
| 181 | + $this->print_table_body_subscriptions( $subscriptions ); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - } |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - /** |
|
| 187 | - * Displays the table body if no subscriptions were found. |
|
| 188 | - * |
|
| 189 | - */ |
|
| 190 | - public function print_table_body_no_subscriptions() { |
|
| 186 | + /** |
|
| 187 | + * Displays the table body if no subscriptions were found. |
|
| 188 | + * |
|
| 189 | + */ |
|
| 190 | + public function print_table_body_no_subscriptions() { |
|
| 191 | 191 | |
| 192 | - ?> |
|
| 192 | + ?> |
|
| 193 | 193 | <tbody> |
| 194 | 194 | |
| 195 | 195 | <tr> |
| 196 | 196 | <td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>"> |
| 197 | 197 | |
| 198 | 198 | <?php |
| 199 | - aui()->alert( |
|
| 200 | - array( |
|
| 201 | - 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
| 202 | - 'type' => 'warning', |
|
| 203 | - ), |
|
| 199 | + aui()->alert( |
|
| 200 | + array( |
|
| 201 | + 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
| 202 | + 'type' => 'warning', |
|
| 203 | + ), |
|
| 204 | 204 | true |
| 205 | - ); |
|
| 206 | - ?> |
|
| 205 | + ); |
|
| 206 | + ?> |
|
| 207 | 207 | |
| 208 | 208 | </td> |
| 209 | 209 | </tr> |
| 210 | 210 | |
| 211 | 211 | </tbody> |
| 212 | 212 | <?php |
| 213 | - } |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - /** |
|
| 216 | - * Displays the table body if subscriptions were found. |
|
| 217 | - * |
|
| 218 | - * @param WPInv_Subscription[] $subscriptions |
|
| 219 | - */ |
|
| 220 | - public function print_table_body_subscriptions( $subscriptions ) { |
|
| 215 | + /** |
|
| 216 | + * Displays the table body if subscriptions were found. |
|
| 217 | + * |
|
| 218 | + * @param WPInv_Subscription[] $subscriptions |
|
| 219 | + */ |
|
| 220 | + public function print_table_body_subscriptions( $subscriptions ) { |
|
| 221 | 221 | |
| 222 | - ?> |
|
| 222 | + ?> |
|
| 223 | 223 | <tbody> |
| 224 | 224 | |
| 225 | 225 | <?php foreach ( $subscriptions as $subscription ) : ?> |
| 226 | 226 | <tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>"> |
| 227 | 227 | <?php |
| 228 | - wpinv_get_template( |
|
| 229 | - 'subscriptions/subscriptions-table-row.php', |
|
| 230 | - array( |
|
| 231 | - 'subscription' => $subscription, |
|
| 232 | - 'widget' => $this, |
|
| 233 | - ) |
|
| 234 | - ); |
|
| 235 | - ?> |
|
| 228 | + wpinv_get_template( |
|
| 229 | + 'subscriptions/subscriptions-table-row.php', |
|
| 230 | + array( |
|
| 231 | + 'subscription' => $subscription, |
|
| 232 | + 'widget' => $this, |
|
| 233 | + ) |
|
| 234 | + ); |
|
| 235 | + ?> |
|
| 236 | 236 | </tr> |
| 237 | 237 | <?php endforeach; ?> |
| 238 | 238 | |
| 239 | 239 | </tbody> |
| 240 | 240 | <?php |
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Adds row actions to a column |
|
| 245 | - * |
|
| 246 | - * @param string $content column content |
|
| 247 | - * @param WPInv_Subscription $subscription |
|
| 248 | - * @since 1.0.0 |
|
| 249 | - * @return string |
|
| 250 | - */ |
|
| 251 | - public function add_row_actions( $content, $subscription ) { |
|
| 252 | - |
|
| 253 | - // Prepare row actions. |
|
| 254 | - $actions = array(); |
|
| 255 | - |
|
| 256 | - // View subscription action. |
|
| 257 | - $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 258 | - $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
| 259 | - $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
| 260 | - |
|
| 261 | - // Filter the actions. |
|
| 262 | - $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
| 263 | - |
|
| 264 | - $sanitized = array(); |
|
| 265 | - foreach ( $actions as $key => $action ) { |
|
| 266 | - $key = sanitize_html_class( $key ); |
|
| 267 | - $action = wp_kses_post( $action ); |
|
| 268 | - $sanitized[] = "<span class='$key'>$action</span>"; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
|
| 272 | - $row_actions .= implode( ' | ', $sanitized ); |
|
| 273 | - $row_actions .= '</small>'; |
|
| 274 | - |
|
| 275 | - return $content . $row_actions; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * Displays the table footer. |
|
| 280 | - * |
|
| 281 | - */ |
|
| 282 | - public function print_table_footer() { |
|
| 283 | - |
|
| 284 | - ?> |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Adds row actions to a column |
|
| 245 | + * |
|
| 246 | + * @param string $content column content |
|
| 247 | + * @param WPInv_Subscription $subscription |
|
| 248 | + * @since 1.0.0 |
|
| 249 | + * @return string |
|
| 250 | + */ |
|
| 251 | + public function add_row_actions( $content, $subscription ) { |
|
| 252 | + |
|
| 253 | + // Prepare row actions. |
|
| 254 | + $actions = array(); |
|
| 255 | + |
|
| 256 | + // View subscription action. |
|
| 257 | + $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 258 | + $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
| 259 | + $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
| 260 | + |
|
| 261 | + // Filter the actions. |
|
| 262 | + $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
| 263 | + |
|
| 264 | + $sanitized = array(); |
|
| 265 | + foreach ( $actions as $key => $action ) { |
|
| 266 | + $key = sanitize_html_class( $key ); |
|
| 267 | + $action = wp_kses_post( $action ); |
|
| 268 | + $sanitized[] = "<span class='$key'>$action</span>"; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
|
| 272 | + $row_actions .= implode( ' | ', $sanitized ); |
|
| 273 | + $row_actions .= '</small>'; |
|
| 274 | + |
|
| 275 | + return $content . $row_actions; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * Displays the table footer. |
|
| 280 | + * |
|
| 281 | + */ |
|
| 282 | + public function print_table_footer() { |
|
| 283 | + |
|
| 284 | + ?> |
|
| 285 | 285 | |
| 286 | 286 | <tfoot> |
| 287 | 287 | <tr> |
@@ -296,145 +296,145 @@ discard block |
||
| 296 | 296 | </table> |
| 297 | 297 | <?php |
| 298 | 298 | |
| 299 | - } |
|
| 299 | + } |
|
| 300 | 300 | |
| 301 | - /** |
|
| 302 | - * Displays the navigation. |
|
| 303 | - * |
|
| 304 | - * @param int $total |
|
| 305 | - */ |
|
| 306 | - public function print_navigation( $total ) { |
|
| 301 | + /** |
|
| 302 | + * Displays the navigation. |
|
| 303 | + * |
|
| 304 | + * @param int $total |
|
| 305 | + */ |
|
| 306 | + public function print_navigation( $total ) { |
|
| 307 | 307 | |
| 308 | - if ( $total < 1 ) { |
|
| 308 | + if ( $total < 1 ) { |
|
| 309 | 309 | |
| 310 | - // Out-of-bounds, run the query again without LIMIT for total count. |
|
| 311 | - $args = array( |
|
| 312 | - 'customer_in' => get_current_user_id(), |
|
| 313 | - 'fields' => 'id', |
|
| 314 | - ); |
|
| 310 | + // Out-of-bounds, run the query again without LIMIT for total count. |
|
| 311 | + $args = array( |
|
| 312 | + 'customer_in' => get_current_user_id(), |
|
| 313 | + 'fields' => 'id', |
|
| 314 | + ); |
|
| 315 | 315 | |
| 316 | - $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
| 317 | - $total = $count_query->get_total(); |
|
| 318 | - } |
|
| 316 | + $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
| 317 | + $total = $count_query->get_total(); |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - // Abort if we do not have pages. |
|
| 321 | - if ( 2 > $total ) { |
|
| 322 | - return; |
|
| 323 | - } |
|
| 320 | + // Abort if we do not have pages. |
|
| 321 | + if ( 2 > $total ) { |
|
| 322 | + return; |
|
| 323 | + } |
|
| 324 | 324 | |
| 325 | - ?> |
|
| 325 | + ?> |
|
| 326 | 326 | |
| 327 | 327 | <div class="getpaid-subscriptions-pagination"> |
| 328 | 328 | <?php |
| 329 | - $big = 999999; |
|
| 330 | - |
|
| 331 | - echo wp_kses_post( |
|
| 332 | - getpaid_paginate_links( |
|
| 333 | - array( |
|
| 334 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
| 335 | - 'format' => '?paged=%#%', |
|
| 336 | - 'total' => (int) ceil( $total / 10 ), |
|
| 337 | - ) |
|
| 338 | - ) |
|
| 339 | - ); |
|
| 340 | - ?> |
|
| 329 | + $big = 999999; |
|
| 330 | + |
|
| 331 | + echo wp_kses_post( |
|
| 332 | + getpaid_paginate_links( |
|
| 333 | + array( |
|
| 334 | + 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
| 335 | + 'format' => '?paged=%#%', |
|
| 336 | + 'total' => (int) ceil( $total / 10 ), |
|
| 337 | + ) |
|
| 338 | + ) |
|
| 339 | + ); |
|
| 340 | + ?> |
|
| 341 | 341 | </div> |
| 342 | 342 | |
| 343 | 343 | <?php |
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Returns a single subscription's columns. |
|
| 348 | - * |
|
| 349 | - * @param WPInv_Subscription $subscription |
|
| 350 | - * |
|
| 351 | - * @return array |
|
| 352 | - */ |
|
| 353 | - public function get_single_subscription_columns( $subscription ) { |
|
| 354 | - |
|
| 355 | - // Prepare subscription detail columns. |
|
| 356 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
| 357 | - $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
| 358 | - $fields = apply_filters( |
|
| 359 | - 'getpaid_single_subscription_details_fields', |
|
| 360 | - array( |
|
| 361 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 362 | - 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
| 363 | - 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
| 364 | - 'start_date' => __( 'Start date', 'invoicing' ), |
|
| 365 | - 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
| 366 | - 'payments' => __( 'Payments', 'invoicing' ), |
|
| 367 | - 'item' => $items_count > 1 ? __( 'Items', $items_count, 'invoicing' ) : __( 'Item', 'invoicing' ) |
|
| 368 | - ), |
|
| 369 | - $subscription, |
|
| 370 | - $items_count |
|
| 371 | - ); |
|
| 372 | - |
|
| 373 | - if ( isset( $fields['expiry_date'] ) ) { |
|
| 374 | - |
|
| 375 | - if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
| 376 | - $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - if ( 'pending' === $subscription->get_status() ) { |
|
| 380 | - unset( $fields['expiry_date'] ); |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - if ( isset( $fields['start_date'] ) && 'pending' === $subscription->get_status() ) { |
|
| 385 | - unset( $fields['start_date'] ); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - if ( $subscription->get_initial_amount() === $subscription->get_recurring_amount() ) { |
|
| 389 | - unset( $fields['initial_amount'] ); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - return $fields; |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * Displays a single subscription. |
|
| 397 | - * |
|
| 398 | - * @param string $subscription |
|
| 399 | - * |
|
| 400 | - * @return string |
|
| 401 | - */ |
|
| 402 | - public function display_single_subscription( $subscription ) { |
|
| 403 | - |
|
| 404 | - // Fetch the subscription. |
|
| 405 | - $subscription = new WPInv_Subscription( (int) $subscription ); |
|
| 406 | - |
|
| 407 | - if ( ! $subscription->exists() ) { |
|
| 408 | - |
|
| 409 | - return aui()->alert( |
|
| 410 | - array( |
|
| 411 | - 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
| 412 | - 'type' => 'error', |
|
| 413 | - ) |
|
| 414 | - ); |
|
| 415 | - |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - // Ensure that the user owns this subscription key. |
|
| 419 | - if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 420 | - |
|
| 421 | - return aui()->alert( |
|
| 422 | - array( |
|
| 423 | - 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
| 424 | - 'type' => 'error', |
|
| 425 | - ) |
|
| 426 | - ); |
|
| 427 | - |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - return wpinv_get_template_html( |
|
| 431 | - 'subscriptions/subscription-details.php', |
|
| 432 | - array( |
|
| 433 | - 'subscription' => $subscription, |
|
| 434 | - 'widget' => $this, |
|
| 435 | - ) |
|
| 436 | - ); |
|
| 437 | - |
|
| 438 | - } |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Returns a single subscription's columns. |
|
| 348 | + * |
|
| 349 | + * @param WPInv_Subscription $subscription |
|
| 350 | + * |
|
| 351 | + * @return array |
|
| 352 | + */ |
|
| 353 | + public function get_single_subscription_columns( $subscription ) { |
|
| 354 | + |
|
| 355 | + // Prepare subscription detail columns. |
|
| 356 | + $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
| 357 | + $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
| 358 | + $fields = apply_filters( |
|
| 359 | + 'getpaid_single_subscription_details_fields', |
|
| 360 | + array( |
|
| 361 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 362 | + 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
| 363 | + 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
| 364 | + 'start_date' => __( 'Start date', 'invoicing' ), |
|
| 365 | + 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
| 366 | + 'payments' => __( 'Payments', 'invoicing' ), |
|
| 367 | + 'item' => $items_count > 1 ? __( 'Items', $items_count, 'invoicing' ) : __( 'Item', 'invoicing' ) |
|
| 368 | + ), |
|
| 369 | + $subscription, |
|
| 370 | + $items_count |
|
| 371 | + ); |
|
| 372 | + |
|
| 373 | + if ( isset( $fields['expiry_date'] ) ) { |
|
| 374 | + |
|
| 375 | + if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
| 376 | + $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + if ( 'pending' === $subscription->get_status() ) { |
|
| 380 | + unset( $fields['expiry_date'] ); |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + if ( isset( $fields['start_date'] ) && 'pending' === $subscription->get_status() ) { |
|
| 385 | + unset( $fields['start_date'] ); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + if ( $subscription->get_initial_amount() === $subscription->get_recurring_amount() ) { |
|
| 389 | + unset( $fields['initial_amount'] ); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + return $fields; |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * Displays a single subscription. |
|
| 397 | + * |
|
| 398 | + * @param string $subscription |
|
| 399 | + * |
|
| 400 | + * @return string |
|
| 401 | + */ |
|
| 402 | + public function display_single_subscription( $subscription ) { |
|
| 403 | + |
|
| 404 | + // Fetch the subscription. |
|
| 405 | + $subscription = new WPInv_Subscription( (int) $subscription ); |
|
| 406 | + |
|
| 407 | + if ( ! $subscription->exists() ) { |
|
| 408 | + |
|
| 409 | + return aui()->alert( |
|
| 410 | + array( |
|
| 411 | + 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
| 412 | + 'type' => 'error', |
|
| 413 | + ) |
|
| 414 | + ); |
|
| 415 | + |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + // Ensure that the user owns this subscription key. |
|
| 419 | + if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 420 | + |
|
| 421 | + return aui()->alert( |
|
| 422 | + array( |
|
| 423 | + 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
| 424 | + 'type' => 'error', |
|
| 425 | + ) |
|
| 426 | + ); |
|
| 427 | + |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + return wpinv_get_template_html( |
|
| 431 | + 'subscriptions/subscription-details.php', |
|
| 432 | + array( |
|
| 433 | + 'subscription' => $subscription, |
|
| 434 | + 'widget' => $this, |
|
| 435 | + ) |
|
| 436 | + ); |
|
| 437 | + |
|
| 438 | + } |
|
| 439 | 439 | |
| 440 | 440 | } |
@@ -21,20 +21,20 @@ |
||
| 21 | 21 | |
| 22 | 22 | foreach ( $file_types as $file_type ) { |
| 23 | 23 | |
| 24 | - if ( isset( $all_types[ $file_type ] ) ) { |
|
| 25 | - $types[] = $all_types[ $file_type ]; |
|
| 26 | - $file_type = explode( '|', $file_type ); |
|
| 24 | + if ( isset( $all_types[ $file_type ] ) ) { |
|
| 25 | + $types[] = $all_types[ $file_type ]; |
|
| 26 | + $file_type = explode( '|', $file_type ); |
|
| 27 | 27 | |
| 28 | - foreach ( $file_type as $type ) { |
|
| 29 | - $type = trim( $type ); |
|
| 30 | - $types[] = ".$type"; |
|
| 31 | - $_types[] = $type; |
|
| 32 | - } |
|
| 28 | + foreach ( $file_type as $type ) { |
|
| 29 | + $type = trim( $type ); |
|
| 30 | + $types[] = ".$type"; |
|
| 31 | + $_types[] = $type; |
|
| 32 | + } |
|
| 33 | 33 | } |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | if ( ! empty( $required ) ) { |
| 37 | - $label .= "<span class='text-danger'> *</span>"; |
|
| 37 | + $label .= "<span class='text-danger'> *</span>"; |
|
| 38 | 38 | } |
| 39 | 39 | ?> |
| 40 | 40 | <label><span v-html="form_element.label"></span></label> |