PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.0.1
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.0.1
3.3.0 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.1 trunk 1.0.4 1.1.0 1.1.0.1 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 All 162 releases
cartflows / libraries / class-cartflows-nps-survey.php

class-cartflows-nps-survey.php in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 3.0.1, at libraries/class-cartflows-nps-survey.php

126 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * CartFlows Loader.
4 *
5 * @package CartFlows
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 if ( ! class_exists( 'Cartflows_Nps_Survey' ) ) :
13
14 /**
15 * Cartflows Nps Survey Loader
16 *
17 * @since 2.1.3
18 */
19 class Cartflows_Nps_Survey {
20 /**
21 * Instance
22 *
23 * @since 2.1.3
24 * @var (Object) Cartflows_Nps_Survey
25 */
26 private static $instance = null;
27
28 /**
29 * Get Instance
30 *
31 * @since 2.1.3
32 *
33 * @return object Class object.
34 */
35 public static function get_instance() {
36 if ( ! isset( self::$instance ) ) {
37 self::$instance = new self();
38 }
39
40 return self::$instance;
41 }
42
43 /**
44 * Constructor.
45 *
46 * @since 2.1.3
47 */
48 private function __construct() {
49 $this->version_check();
50 add_action( 'init', array( $this, 'load' ), 999 );
51 add_filter( 'nps_survey_api_endpoint', array( $this, 'update_webhook_url' ), 10, 2 );
52 }
53
54 /**
55 * Version Check
56 *
57 * @since 2.1.3
58 * @return void
59 */
60 public function version_check() {
61
62 $file = realpath( dirname( __FILE__ ) . '/nps-survey/version.json' );
63
64 // Is file exist?
65 if ( is_file( $file ) ) {
66
67 $file_data = json_decode( file_get_contents( $file ), true );
68
69 global $nps_survey_version, $nps_survey_init;
70
71 $path = realpath( dirname( __FILE__ ) . '/nps-survey/nps-survey.php' );
72
73 $version = isset( $file_data['nps-survey'] ) ? $file_data['nps-survey'] : 0;
74
75 if ( null === $nps_survey_version ) {
76 $nps_survey_version = '1.0.0';
77 }
78
79 // Compare versions.
80 if ( version_compare( $version, $nps_survey_version, '>=' ) ) {
81 $nps_survey_version = $version;
82 $nps_survey_init = $path;
83 }
84 }
85 }
86
87 /**
88 * Load latest plugin
89 *
90 * @since 2.1.3
91 * @return void
92 */
93 public function load() {
94
95 global $nps_survey_version, $nps_survey_init;
96 if ( is_file( realpath( $nps_survey_init ) ) ) {
97 include_once realpath( $nps_survey_init );
98 }
99 }
100
101 /**
102 * Update the NPS survey webhook URL.
103 *
104 * @param string $url Webhook URL.
105 * @param array<mixed> $post_data NPS survey post data.
106 *
107 * @return string
108 */
109 public function update_webhook_url( $url, $post_data ) {
110 if ( isset( $post_data['plugin_slug'] ) && 'cartflows' === $post_data['plugin_slug'] ) {
111 // Return the NPS webhook URL if the plugin slug is CartFlows.
112 return CARTFLOWS_NPS_WEBHOOK_URL;
113 }
114
115 return $url;
116 }
117
118 }
119
120 /**
121 * Kicking this off by calling 'get_instance()' method
122 */
123 Cartflows_Nps_Survey::get_instance();
124
125 endif;
126