PluginProbe ʕ •ᴥ•ʔ
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.6.8
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.6.8
5.6.8 5.6.7 5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / helpers / nps_survey_helper.php
latepoint / lib / helpers Last commit date
activities_helper.php 4 months ago agent_helper.php 4 months ago analytics_helper.php 2 weeks ago auth_helper.php 1 week ago blocks_helper.php 3 weeks ago booking_helper.php 1 week ago bricks_helper.php 4 months ago bundles_helper.php 1 week ago calendar_helper.php 1 week ago carts_helper.php 4 months ago connector_helper.php 4 months ago csv_helper.php 4 months ago customer_helper.php 1 month ago customer_import_helper.php 1 month ago database_helper.php 1 day ago debug_helper.php 4 months ago defaults_helper.php 4 months ago elementor_helper.php 4 months ago email_helper.php 4 months ago encrypt_helper.php 4 months ago events_helper.php 3 months ago form_helper.php 4 months ago icalendar_helper.php 4 months ago image_helper.php 4 months ago invoices_helper.php 1 day ago license_helper.php 4 months ago location_helper.php 4 months ago marketing_systems_helper.php 4 months ago meeting_systems_helper.php 4 months ago menu_helper.php 3 weeks ago meta_helper.php 4 months ago migrations_helper.php 4 months ago money_helper.php 3 months ago notifications_helper.php 4 months ago nps_survey_helper.php 4 months ago order_intent_helper.php 2 months ago orders_helper.php 4 days ago otp_helper.php 3 months ago pages_helper.php 4 months ago params_helper.php 4 months ago payments_helper.php 4 days ago plugin_version_update_helper.php 2 months ago price_breakdown_helper.php 4 months ago process_jobs_helper.php 4 months ago processes_helper.php 4 months ago razorpay_connect_helper.php 1 day ago replacer_helper.php 4 months ago resource_helper.php 1 week ago roles_helper.php 3 weeks ago router_helper.php 4 months ago service_helper.php 4 months ago sessions_helper.php 4 months ago settings_helper.php 2 weeks ago short_links_systems_helper.php 4 months ago shortcodes_helper.php 3 weeks ago sms_helper.php 4 months ago steps_helper.php 1 day ago stripe_connect_helper.php 2 weeks ago styles_helper.php 4 months ago support_topics_helper.php 4 months ago time_helper.php 2 months ago timeline_helper.php 2 months ago transaction_helper.php 1 month ago transaction_intent_helper.php 4 months ago util_helper.php 1 month ago version_specific_updates_helper.php 1 day ago whatsapp_helper.php 1 month ago work_periods_helper.php 3 months ago wp_datetime.php 4 months ago wp_user_helper.php 4 months ago
nps_survey_helper.php
194 lines
1 <?php
2 /**
3 * LatePoint NPS Survey Helper.
4 *
5 * @since 5.2.8
6 * @package LatePoint
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 if ( ! class_exists( 'OsNpsSurveyHelper' ) ) {
14 /**
15 * OsNpsSurveyHelper - NPS Survey Version Checker and Loader
16 */
17 class OsNpsSurveyHelper {
18
19 /**
20 * Instance of this class.
21 *
22 * @var OsNpsSurveyHelper
23 */
24 private static $instance = null;
25
26 /**
27 * Array of allowed screens where the NPS survey should be displayed.
28 * This ensures that the NPS survey is only displayed on LatePoint pages.
29 *
30 * @var array
31 */
32 private static $allowed_screens = [
33 'toplevel_page_latepoint',
34 ];
35
36 /**
37 * Get instance.
38 *
39 * @return OsNpsSurveyHelper
40 */
41 public static function get_instance() {
42 if ( null === self::$instance ) {
43 self::$instance = new self();
44 }
45 return self::$instance;
46 }
47
48 /**
49 * Constructor.
50 */
51 private function __construct() {
52 $this->version_check();
53 add_action( 'init', [ $this, 'load' ], 999 );
54
55 add_action( 'admin_footer', [ $this, 'show_nps_notice' ], 999 );
56 add_filter( 'nps_survey_post_data', [ $this, 'update_nps_survey_post_data' ] );
57 }
58
59 /**
60 * Version Check
61 *
62 * @return void
63 */
64 public function version_check() {
65 $file = realpath( LATEPOINT_ABSPATH . '/lib/kit/nps-survey/version.json' );
66
67 // Is file exist?
68 if ( is_file( $file ) ) {
69 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
70 $file_data = json_decode( file_get_contents( $file ), true );
71 global $nps_survey_version, $nps_survey_init;
72 $path = realpath( LATEPOINT_ABSPATH . '/lib/kit/nps-survey/nps-survey.php' );
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 * @return void
91 */
92 public function load() {
93 global $nps_survey_version, $nps_survey_init;
94
95 if ( is_file( realpath( $nps_survey_init ) ) ) {
96 include_once realpath( $nps_survey_init );
97 }
98 }
99
100 /**
101 * Count the number of bookings and determine if NPS survey should be shown.
102 *
103 * @return bool
104 */
105 public function maybe_display_nps_survey() {
106 // Check if user has manage_options capability.
107 if ( ! current_user_can( 'manage_options' ) ) {
108 return false;
109 }
110
111 // Get total bookings count.
112 $bookings_model = new OsBookingModel();
113 $bookings_count = $bookings_model->count();
114
115 // Get total customers count.
116 $customers_model = new OsCustomerModel();
117 $customers_count = $customers_model->count();
118
119 // Show the NPS survey if there are at least 5 bookings or 3 customers.
120 if ( $bookings_count >= 3 || $customers_count >= 3 ) {
121 return true;
122 }
123
124 return false;
125 }
126
127 /**
128 * Render NPS Survey
129 *
130 * @return void
131 */
132 public function show_nps_notice() {
133 // Ensure the Nps_Survey class exists before proceeding.
134 if ( ! class_exists( 'Nps_Survey' ) ) {
135 return;
136 }
137
138 // Get current screen.
139 $screen = get_current_screen();
140 if ( ! $screen || ! in_array( $screen->id, self::$allowed_screens, true ) ) {
141 return;
142 }
143
144 // Check if the constant WEEK_IN_SECONDS is already defined.
145 if ( ! defined( 'WEEK_IN_SECONDS' ) ) {
146 define( 'WEEK_IN_SECONDS', 604800 );
147 }
148
149 // Display the NPS survey.
150 Nps_Survey::show_nps_notice(
151 'nps-survey-latepoint',
152 [
153 'show_if' => $this->maybe_display_nps_survey(),
154 'dismiss_timespan' => 2 * WEEK_IN_SECONDS,
155 'display_after' => 0,
156 'plugin_slug' => 'latepoint',
157 'show_on_screens' => self::$allowed_screens,
158 'message' => [
159 'logo' => esc_url( LATEPOINT_IMAGES_URL . 'logo.png' ),
160 'plugin_name' => __( 'Quick Question!', 'latepoint' ),
161 'nps_rating_message' => __( 'How would you rate LatePoint? Love it, hate it, or somewhere in between? Your honest answer helps us understand how we\'re doing.', 'latepoint' ),
162 'feedback_title' => __( 'Thanks a lot for your feedback!', 'latepoint' ),
163 'feedback_content' => __( 'Thanks for being part of the LatePoint community! Got feedback or suggestions? We\'d love to hear it.', 'latepoint' ),
164 'plugin_rating_link' => esc_url( 'https://wordpress.org/support/plugin/latepoint/reviews/#new-post' ),
165 'plugin_rating_title' => __( 'Thank you for your feedback', 'latepoint' ),
166 'plugin_rating_content' => __( 'We value your input. How can we improve your experience?', 'latepoint' ),
167 'plugin_rating_button_string' => __( 'Rate LatePoint', 'latepoint' ),
168 'rating_min_label' => __( 'Hate it!', 'latepoint' ),
169 'rating_max_label' => __( 'Love it!', 'latepoint' ),
170 ],
171 'privacy_policy' => [
172 'url' => 'https://latepoint.com/privacy-policy',
173 ],
174 ]
175 );
176 }
177
178 /**
179 * Update the NPS survey post data.
180 * Add LatePoint plugin version to the NPS survey post data.
181 *
182 * @param array $post_data NPS survey post data.
183 * @return array
184 */
185 public function update_nps_survey_post_data( $post_data ) {
186 if ( isset( $post_data['plugin_slug'] ) && 'latepoint' === $post_data['plugin_slug'] ) {
187 $post_data['plugin_version'] = LATEPOINT_VERSION;
188 }
189
190 return $post_data;
191 }
192 }
193 }
194