Plugin Directory

Changeset 3038994


Ignore:
Timestamp:
02/21/2024 08:34:04 AM (2 years ago)
Author:
gleap
Message:

v13.0.2

Location:
gleap/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • gleap/trunk/README.txt

    r3008850 r3038994  
    3838
    3939== Changelog ==
     40
     41= 13.0.2 =
     42* Added action to track events
     43e.g. do_action('gleap_send_custom_event', $event_data);
    4044
    4145= 13.0.1 =
  • gleap/trunk/admin/class-gleap-admin.php

    r3008603 r3038994  
    130130        $gleap_fields = array(
    131131            Field::make('text', 'gleap_token', 'API key')->set_required(true)->set_help_text("Get your free API key within the <a href=\"https://app.gleap.io/\">Gleap Dashboard.</a>"),
    132             Field::make('text', 'gleap_identity_token', 'Identity verification secret')->set_help_text("If you'd like to verify the identity of your users, copy the code from Project -> Settings -> Security to the field above."),
     132            Field::make('text', 'gleap_identity_token', 'Identity verification secret')->set_attribute('type', 'password')->set_help_text("If you'd like to verify the identity of your users, copy the code from Project -> Settings -> Security to the field above."),
     133            Field::make('text', 'gleap_secret_api_token', 'Secret API token')->set_attribute('type', 'password')->set_help_text("If you'd like to use the Gleap Rest API to send events, copy the code from Project -> Settings -> Security to the field above."),
    133134            Field::make('checkbox', 'gleap_selected_roles_only', 'Enable Gleap only for the selected WP roles')
    134135                ->set_default_value(false)
  • gleap/trunk/gleap.php

    r3008850 r3038994  
    1717 * Plugin Name:       Gleap
    1818 * Description:       Gleap helps developers build the best software faster. It is your affordable in-app bug reporting tool for apps, websites and industrial applications.
    19  * Version:           13.0.1
     19 * Version:           13.0.2
    2020 * Author:            Gleap
    2121 * Author URI:        https://www.gleap.io
  • gleap/trunk/public/class-gleap-public.php

    r3008850 r3038994  
    5454        $this->plugin_name = $plugin_name;
    5555        $this->version = $version;
    56     }
     56
     57        add_action('gleap_send_custom_event', array($this, 'send_custom_event'));
     58    }
    5759
    5860    /**
     
    106108    }
    107109
     110    /**
     111     * Send a custom event to Gleap.
     112     *
     113     * @since    1.0.0
     114     * @param    array    $event_data    The data of the event to send.
     115     */
     116    public function send_custom_event($event_data) {
     117        $secret_api_token = carbon_get_theme_option('gleap_secret_api_token');
     118
     119        // Check if the secret API token is set.
     120        if (empty($secret_api_token)) {
     121            // You can either throw an exception or handle the error appropriately.
     122            // For example:
     123            // throw new Exception('Gleap secret API token is not set.');
     124            // Or handle it another way, such as logging the error:
     125            error_log('Gleap: Cannot send event because secret API token is not set.');
     126            return;
     127        }
     128
     129        $response = wp_remote_post('https://api.gleap.io/admin/track', array(
     130            'headers' => array(
     131                'Content-Type' => 'application/json',
     132                'Api-Token' => $secret_api_token,
     133            ),
     134            'body' => json_encode(array('events' => array($event_data))),
     135        ));
     136
     137        // Error handling.
     138        if (is_wp_error($response)) {
     139            // Handle error - log it, notify admin, etc.
     140            error_log('Error sending custom event to Gleap: ' . $response->get_error_message());
     141        }
     142    }
     143
     144
    108145    /**
    109146     * Register the JavaScript for the public-facing side of the site.
     
    122159
    123160        $gleap_token = carbon_get_theme_option('gleap_token');
    124         if ($gleap_token) {
    125             $gleap_selected_roles_only = carbon_get_theme_option('gleap_selected_roles_only');
     161
     162
     163        // Apply filter to allow modification of the gleap_token
     164        $gleap_token = apply_filters('gleap_modify_token', $gleap_token);
     165
     166        if ($gleap_token) {
     167            $gleap_selected_roles_only = carbon_get_theme_option('gleap_selected_roles_only');
    126168            if ($gleap_selected_roles_only == true) {
    127169                $user_roles = wp_get_current_user()->roles;
     
    137179            if (is_user_logged_in()) {
    138180                $gleap_identity_token = carbon_get_theme_option('gleap_identity_token');
     181
     182                // Apply filter to allow modification of the gleap_identity_token
     183                $gleap_identity_token = apply_filters('gleap_modify_identity_token', $gleap_identity_token);
     184
    139185                $user_data = get_userdata(get_current_user_id());
    140186                $login = $user_data->user_login;
Note: See TracChangeset for help on using the changeset viewer.