PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / trunk
LatePoint – Calendar Booking Plugin for Appointments and Events vtrunk
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 / kit / bsf-analytics / classes / class-bsf-analytics-helper.php
latepoint / lib / kit / bsf-analytics / classes Last commit date
class-bsf-analytics-helper.php 4 months ago
class-bsf-analytics-helper.php
98 lines
1 <?php
2 /**
3 * BSF analytics Helper Class File.
4 *
5 * @package bsf-analytics
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 if ( ! class_exists( 'BSF_Analytics_Helper' ) ) {
13 /**
14 * BSF analytics stat class.
15 */
16 class BSF_Analytics_Helper {
17
18 /**
19 * Check is error in the received response.
20 *
21 * @param object $response Received API Response.
22 * @return array $result Error result.
23 */
24 public static function is_api_error( $response ) {
25
26 $result = array(
27 'error' => false,
28 'error_message' => __( 'Oops! Something went wrong. Please refresh the page and try again.' ),
29 'error_code' => 0,
30 );
31
32 if ( is_wp_error( $response ) ) {
33 $result['error'] = true;
34 $result['error_message'] = $response->get_error_message();
35 $result['error_code'] = $response->get_error_code();
36 } elseif ( ! empty( wp_remote_retrieve_response_code( $response ) ) && ! in_array( wp_remote_retrieve_response_code( $response ), array( 200, 201, 204 ), true ) ) {
37 $result['error'] = true;
38 $result['error_message'] = wp_remote_retrieve_response_message( $response );
39 $result['error_code'] = wp_remote_retrieve_response_code( $response );
40 }
41
42 return $result;
43 }
44
45 /**
46 * Get API headers
47 *
48 * @since 1.1.6
49 * @return array<string, string>
50 */
51 public static function get_api_headers() {
52 return array(
53 'Content-Type' => 'application/json',
54 'Accept' => 'application/json',
55 );
56 }
57
58 /**
59 * Get API URL for sending analytics.
60 *
61 * @return string API URL.
62 * @since 1.0.0
63 */
64 public static function get_api_url() {
65 return defined( 'BSF_ANALYTICS_API_BASE_URL' ) ? BSF_ANALYTICS_API_BASE_URL : 'https://analytics.brainstormforce.com/';
66 }
67
68 /**
69 * Check if the current screen is allowed for the survey.
70 *
71 * This function checks if the current screen is one of the allowed screens for displaying the survey.
72 * It uses the `get_current_screen` function to get the current screen information and compares it with the list of allowed screens.
73 *
74 * @since 1.1.6
75 * @return bool True if the current screen is allowed, false otherwise.
76 */
77 public static function is_allowed_screen() {
78
79 // This filter allows to dynamically modify the list of allowed screens for the survey.
80 $allowed_screens = apply_filters( 'uds_survey_allowed_screens', array( 'plugins' ) );
81
82 $current_screen = get_current_screen();
83
84 // Check if $current_screen is a valid object before accessing its properties.
85 if ( ! is_object( $current_screen ) ) {
86 return false; // Return false if current screen is not valid.
87 }
88
89 $screen_id = $current_screen->id;
90
91 if ( ! empty( $screen_id ) && in_array( $screen_id, $allowed_screens, true ) ) {
92 return true;
93 }
94
95 return false;
96 }
97 }
98 }