Plugin Directory

Changeset 3306623


Ignore:
Timestamp:
06/04/2025 04:49:27 PM (10 months ago)
Author:
logtivity
Message:

Register site with Logtivity using Team API

Location:
logtivity
Files:
4 added
18 edited
1 copied

Legend:

Unmodified
Added
Removed
  • logtivity/tags/3.1.12/Admin/Logtivity_Admin.php

    r3290027 r3306623  
    4646        add_action('wp_ajax_nopriv_logtivity_update_settings', [$this, 'update']);
    4747
     48        add_action('wp_ajax_logtivity_register_site', [$this, 'registerSite']);
     49
    4850        add_filter('logtivity_hide_from_menu', [$this, 'shouldHidePluginFromUI']);
    4951        add_filter('all_plugins', [$this, 'maybeHideFromMenu']);
     
    98100
    99101    /**
    100      * Register the settings page
    101      */
    102     public function registerOptionsPage()
     102     * Create the admin menus
     103     *
     104     * @return void
     105     */
     106    public function registerOptionsPage(): void
    103107    {
    104108        if (!apply_filters('logtivity_hide_from_menu', false)) {
     
    116120        if (!apply_filters('logtivity_hide_settings_page', false)) {
    117121            add_submenu_page(
    118                 ($this->options->isWhiteLabelMode() ? 'lgtvy-logs' : 'logtivity'),
     122                $this->options->isWhiteLabelMode() ? 'lgtvy-logs' : 'logtivity',
    119123                'Logtivity Settings',
    120124                'Settings',
    121125                Logtivity::ACCESS_SETTINGS,
    122                 'logtivity' . '-settings',
    123                 [$this, 'showLogtivitySettingsPage']
     126                'logtivity-settings',
     127                [$this, 'showSettingsPage']
    124128            );
    125129        }
     130
     131        if ($this->options->getApiKey() == false) {
     132            add_submenu_page(
     133                $this->options->isWhiteLabelMode() ? 'lgtvy-logs' : 'logtivity',
     134                'Register Site',
     135                'Register Site',
     136                Logtivity::ACCESS_SETTINGS,
     137                'logtivity-register-site',
     138                [$this, 'showRegisterSitePage']
     139            );
     140        }
    126141    }
    127142
     
    131146     * @return void
    132147     */
    133     public function showLogIndexPage()
     148    public function showLogIndexPage(): void
    134149    {
    135150        if (!current_user_can(Logtivity::ACCESS_LOGS)) {
     
    147162     * @return void
    148163     */
    149     public function showLogtivitySettingsPage()
     164    public function showSettingsPage(): void
    150165    {
    151166        if (!current_user_can(Logtivity::ACCESS_SETTINGS)) {
     
    159174
    160175    /**
     176     * Show the register by team API page
     177     *
     178     * @return void
     179     */
     180    public function showRegisterSitePage(): void
     181    {
     182        if (!current_user_can(Logtivity::ACCESS_SETTINGS)) {
     183            wp_die(__('You do not have sufficient permissions to access this page.'));
     184        }
     185
     186        $options = $this->options->getOptions();
     187
     188        echo logtivity_view('register', compact('options'));
     189    }
     190
     191    /**
    161192     * @return void
    162193     */
     
    165196        if (!wp_verify_nonce($_POST['logtivity_update_settings'] ?? null, 'logtivity_update_settings')) {
    166197            wp_safe_redirect($this->settingsPageUrl());
    167             exit;
     198            exit();
    168199        }
    169200
     
    172203        if (!$user->hasRole('administrator')) {
    173204            wp_safe_redirect($this->settingsPageUrl());
    174             exit;
     205            exit();
    175206        }
    176207
     
    189220
    190221        wp_safe_redirect($this->settingsPageUrl());
    191         exit;
     222        exit();
     223    }
     224
     225    /**
     226     * ajax endpoint for registering with a team API Key
     227     *
     228     * @return void
     229     */
     230    public function registerSite(): void
     231    {
     232        try {
     233            if (wp_verify_nonce($_POST['logtivity_register_site'] ?? null, 'logtivity_register_site')) {
     234                $teamApi  = sanitize_text_field($_POST['logtivity_team_api_key'] ?? null);
     235
     236                $response = Logtivity::registerSite($teamApi);
     237
     238
     239                if ($response instanceof WP_Error) {
     240                    wp_send_json_error($response);
     241                } else {
     242                    wp_send_json_success($response);
     243                }
     244
     245            } else {
     246                wp_send_json_error('Invalid Request');
     247            }
     248
     249        } catch (Throwable $error) {
     250            wp_send_json_error($error->getMessage(), $error->getCode());
     251        }
     252
     253        wp_die();
    192254    }
    193255
  • logtivity/tags/3.1.12/Admin/Logtivity_Options.php

    r3290027 r3306623  
    9494
    9595    /**
    96      * Get the API key for the site
     96     * Get the API Key for the site
    9797     *
    9898     * @return string
  • logtivity/tags/3.1.12/Services/Logtivity_Api.php

    r3290027 r3306623  
    4848
    4949    /**
    50      * The API key for either the site or team
     50     * The API Key for either the site or team
    5151     *
    5252     * @var ?string
     
    175175            ];
    176176
     177            // @TODO: Switch to Logtivity_Response class to get standardized responses
    177178            $response = wp_remote_request($this->getEndpoint($url), $request);
    178179            if ($this->notUpdatingWidgetInCustomizer()) {
     
    190191                    $responseMessage = wp_remote_retrieve_response_message($response);
    191192                    $responseBody    = json_decode(wp_remote_retrieve_body($response), true);
    192                     $responseError   = $responseCode < 400
    193                         ? ($responseBody['error'] ?? null)
    194                         : ($responseMessage ?: 'Unknown error');
    195 
     193
     194                    if ($responseCode < 400) {
     195                        $responseError = $responseBody['error'] ?? null;
     196                    } else {
     197                        $responseError   = $responseMessage;
     198                        $responseMessage = (($responseBody['message'] ?? $responseMessage) ?: 'Unknown error');
     199
     200                    }
    196201                    $responseData = [
    197202                        'code'    => $responseCode,
     
    310315                    $message = sprintf('Disconnected (%s - %s)', $code, $message);
    311316                } else {
    312                     $message = 'Not connected. Please check API key';
     317                    $message = 'Not connected. Please check API Key';
    313318                }
    314319
  • logtivity/tags/3.1.12/assets/admin.css

    r3294349 r3306623  
    8989body[class*="_page_logtivity"] .button-primary:hover,
    9090body[class*="_page_lgtvy-logs"] .button-primary:hover {
    91   background-color: #28679b;
     91  background-color: #307bb9;
    9292  border-color: #256091;
    9393  color: #fff;
     
    135135.logtivity-button-primary:focus,
    136136.logtivity-button-primary:active {
    137   background-color: #fcc948 !important;
    138   border-color: #fcc948 !important;
     137  background-color: #f6993f !important;
     138  border-color: #f6993f !important;
    139139  color: #13314a !important;
    140140}
     
    143143.logtivity-button:focus,
    144144.logtivity-button:active {
    145   box-shadow: 0 15px 25px -7px rgba(0,0,0,0.1) !important;
     145  box-shadow: 0 15px 25px -7px rgba(0, 0, 0, 0.1) !important;
    146146}
    147147
     
    166166  font-size: 14px;
    167167  line-height: 1.2 !important;
     168}
     169
     170.logtivity-notice-info *,
     171.logtivity-notice-warning *,
     172.logtivity-notice-danger * {
     173  background-color: #e1effbff;
     174}
     175
     176.logtivity-notice-warning {
     177  border-left: 4px solid #f6993f;
     178}
     179
     180.logtivity-notice-danger {
     181  border-left: 4px solid #e3342f;
    168182}
    169183
     
    190204.logtivity-settings input[type="search"]:focus {
    191205  background-color: #fff;
    192   border-color: #88b8e0;
     206  border-color: #6cb2eb;
    193207  box-shadow: 0 0 0 .2rem rgba(48, 123, 185, .25);
    194208  color: #495057;
     
    302316
    303317.logtivity-modal-strip {
    304   background: #0073AA;
     318  background: #307bb9;
    305319  padding-top: 20px;
    306320  padding-bottom: 20px;
     
    308322
    309323.logtivity-modal-strip.light {
    310   background: #00A0D2;
     324  background: #6cb2eb;
    311325}
    312326
  • logtivity/tags/3.1.12/assets/app.js

    r2717247 r3306623  
    1 var LogtivityLogIndex = {
    2    
    3     init: function() {
    4         this.container = jQuery('#logtivity-log-index');
    5 
    6         if (!this.container.length) {
    7             return;
    8         }
    9        
    10         this.form = jQuery('#logtivity-log-index-search-form');
    11 
    12         this.listenForPagination();
    13 
    14         this.listenForChange();
    15 
    16         this.filter();
    17 
    18         this.listenForViewLog()
    19 
    20         this.listenForCloseModal();
    21     },
    22 
    23     listenForCloseModal: function() {
    24 
    25         var $this = this;
    26 
    27         jQuery("body").on( "click", ".js-logtivity-notice-dismiss", function(e) {
    28             e.preventDefault();
    29 
    30             $this.hideModal();
    31 
    32         });
    33 
    34         jQuery(document).on('keyup', function(e) {
    35 
    36             if (e.key == "Escape") {
    37                 $this.hideModal();
    38             }
    39 
    40         });
    41 
    42         jQuery(document).mouseup(function(e) {
    43 
    44             if (!$this.modalOpen) {
    45                 return;
    46             }
    47 
    48             var container = jQuery('.logtivity-modal-dialog');
    49 
    50             // if the target of the click isn't the container nor a descendant of the container
    51             if (!container.is(e.target) && container.has(e.target).length === 0) {
    52                 $this.hideModal();
    53             }
    54 
    55         });
    56 
    57     },
    58 
    59     listenForViewLog: function() {
    60 
    61         var $this = this;
    62 
    63         jQuery("body").on( "click", ".js-logtivity-view-log", function(e) {
    64             e.preventDefault();
    65 
    66             $this.showLogModal(jQuery(this).next().html());
    67         });
    68 
    69     },
    70 
    71     showLogModal: function(modalContent) {
    72 
    73         jQuery('.logtivity-modal').addClass('active');
    74 
    75         this.modalOpen = true;
    76 
    77         jQuery('.logtivity-modal-content').html(modalContent);
    78 
    79     },
    80 
    81     hideModal: function() {
    82 
    83         jQuery('.logtivity-modal').removeClass('active');
    84 
    85         this.modalOpen = false;
    86 
    87     },
    88 
    89     listenForChange: function() {
    90 
    91         var $this = this;
    92 
    93         var timeout = null;
    94 
    95         jQuery("body").on( "input", "#logtivity-log-index-search-form input", function(e) {
    96             e.preventDefault();
    97 
    98             jQuery('#logtivity_page').val('');
    99 
    100             // Clear the timeout if it has already been set.
    101             // This will prevent the previous task from executing
    102             // if it has been less than <MILLISECONDS>
    103             clearTimeout(timeout);
    104 
    105             // Make a new timeout set to go off in 1000ms
    106             timeout = setTimeout(function () {
    107                
    108                 $this.filter();
    109 
    110             }, 1000);
    111 
    112         });
    113 
    114     },
    115 
    116     loading: function() {
    117 
    118         this.container.html(
    119             '<div style="text-align: center; padding-bottom: 20px"><div class="spinner is-active" style="float:none;width:auto;height:auto;padding:10px 0 10px 50px;background-position:20px 0;"></div></div>'
    120             );
    121    
    122     },
    123 
    124     listenForPagination: function() {
    125 
    126         var $this = this;
    127 
    128         jQuery("body").on( "click", ".js-logtivity-pagination", function(e) {
    129             e.preventDefault();
    130 
    131             jQuery('#logtivity_page').val(jQuery(this).attr('data-page'));
    132 
    133             $this.filter();
    134         });
    135 
    136     },
    137 
    138     filter: function() {
    139 
    140         this.loading();
    141 
    142         var $this = this;
    143 
    144         jQuery.ajax({
    145             url: $this.form.attr('action'),
    146             type: 'GET',
    147             data: $this.form.serialize(),
    148             success: function(result) {
    149                 $this.container.html(result.view);
    150             },
    151             error: function(error) {
    152                 console.log(error);
    153             }
    154         });
    155 
    156     }
    157 
    158 };
    159 
    160 var DismissUrlHasChanged = {
    161 
    162     init: function() {
    163 
    164         jQuery( document ).on( 'click', '.notice-dismiss', function () {
    165             var type = jQuery(this).closest('.is-dismissible').attr('notice');
    166             var dismissUntil = jQuery(this).closest('.is-dismissible').attr('dismiss-until');
    167 
    168             if (type) {
    169                 jQuery.ajax( ajaxurl, {
    170                     type: 'POST',
    171                     data: {
    172                         action: 'logtivity_dismiss_notice',
    173                         type: type,
    174                         dismiss_until: dismissUntil,
    175                     }
    176                 });
    177             }
    178 
    179         });
    180 
    181     }
    182 
    183 };
    184 
    185 jQuery(function() {
    186     LogtivityLogIndex.init();
    187     DismissUrlHasChanged.init();
     1jQuery(function($) {
     2    let LogtivityLogIndex = {
     3        init: function() {
     4            this.container = $('#logtivity-log-index');
     5
     6            if (!this.container.length) {
     7                return;
     8            }
     9
     10            this.form = $('#logtivity-log-index-search-form');
     11            this.listenForPagination();
     12            this.listenForChange();
     13            this.filter();
     14            this.listenForViewLog()
     15            this.listenForCloseModal();
     16        },
     17
     18        listenForCloseModal: function() {
     19            let listenForCloseModal = this;
     20
     21            $("body").on("click", ".js-logtivity-notice-dismiss", function(e) {
     22                e.preventDefault();
     23
     24                listenForCloseModal.hideModal();
     25            });
     26
     27            $(document).on('keyup', function(e) {
     28                if (e.key === "Escape") {
     29                    listenForCloseModal.hideModal();
     30                }
     31
     32            });
     33
     34            $(document).mouseup(function(e) {
     35                if (!listenForCloseModal.modalOpen) {
     36                    return;
     37                }
     38
     39                let $container = $('.logtivity-modal-dialog');
     40
     41                // if the target of the click isn't the container nor a descendant of the container
     42                if (!$container.is(e.target) && $container.has(e.target).length === 0) {
     43                    listenForCloseModal.hideModal();
     44                }
     45            });
     46        },
     47
     48        listenForViewLog: function() {
     49            let listenForViewLog = this;
     50
     51            $("body").on("click", ".js-logtivity-view-log", function(e) {
     52                e.preventDefault();
     53
     54                listenForViewLog.showLogModal($(this).next().html());
     55            });
     56        },
     57
     58        showLogModal: function(modalContent) {
     59            $('.logtivity-modal').addClass('active');
     60
     61            this.modalOpen = true;
     62
     63            $('.logtivity-modal-content').html(modalContent);
     64        },
     65
     66        hideModal: function() {
     67            $('.logtivity-modal').removeClass('active');
     68
     69            this.modalOpen = false;
     70        },
     71
     72        listenForChange: function() {
     73            let listenForChange = this,
     74                timeout         = null;
     75
     76            $("body").on("input", "#logtivity-log-index-search-form input", function(e) {
     77                e.preventDefault();
     78
     79                $('#logtivity_page').val('');
     80
     81                // Clear the timeout if it has already been set.
     82                // This will prevent the previous task from executing
     83                // if it has been less than <MILLISECONDS>
     84                clearTimeout(timeout);
     85
     86                // Make a new timeout set to go off in 1000ms
     87                timeout = setTimeout(function() {
     88                    listenForChange.filter();
     89                }, 1000);
     90            });
     91        },
     92
     93        loading: function() {
     94            this.container.html(
     95                '<div style="text-align: center; padding-bottom: 20px"><div class="spinner is-active" style="float:none;width:auto;height:auto;padding:10px 0 10px 50px;background-position:20px 0;"></div></div>'
     96            );
     97        },
     98
     99        listenForPagination: function() {
     100            let listenForPagination = this;
     101
     102            $("body").on("click", ".js-logtivity-pagination", function(e) {
     103                e.preventDefault();
     104
     105                $('#logtivity_page').val($(this).attr('data-page'));
     106
     107                listenForPagination.filter();
     108            });
     109        },
     110
     111        filter: function() {
     112            let filter = this;
     113
     114            this.loading();
     115
     116            $.ajax({
     117                url    : filter.form.attr('action'),
     118                type   : 'GET',
     119                data   : filter.form.serialize(),
     120                success: function(result) {
     121                    filter.container.html(result.view);
     122                },
     123                error  : function(error) {
     124                    console.log(error);
     125                }
     126            });
     127        }
     128    };
     129
     130    let DismissUrlHasChanged = {
     131        init: function() {
     132            $(document).on('click', '.notice-dismiss', function() {
     133                let type         = $(this).closest('.is-dismissible').attr('notice'),
     134                    dismissUntil = $(this).closest('.is-dismissible').attr('dismiss-until');
     135
     136                if (type) {
     137                    $.ajax(ajaxurl, {
     138                        type: 'POST',
     139                        data: {
     140                            action       : 'logtivity_dismiss_notice',
     141                            type         : type,
     142                            dismiss_until: dismissUntil,
     143                        }
     144                    });
     145                }
     146            });
     147        }
     148    };
     149
     150    LogtivityLogIndex.init();
     151    DismissUrlHasChanged.init();
     152
     153    let registerMessage = function(message, type) {
     154        type = type || 'info';
     155
     156        let $messaging = $('#logtivity-register-response')
     157            .removeClass()
     158            .addClass('logtivity-notice logtivity-notice-' + type)
     159            .css('width', 'fit-content');
     160
     161        if (message) {
     162            $messaging
     163                .css('display', 'block')
     164                .html('<div>' + message + '</div>');
     165        } else {
     166            $messaging
     167                .css('display', 'none')
     168                .html();
     169        }
     170    };
     171
     172    $('#logtivity-register-site').on('submit', function(evt) {
     173        evt.preventDefault();
     174
     175        registerMessage();
     176
     177        $.post(this.getAttribute('action'), $(this).serialize())
     178            .success(function(response) {
     179                let success      = response.success || false,
     180                    responseData = response.data || [],
     181                    code         = responseData.code || 200;
     182
     183                console.log(responseData);
     184                console.log(response);
     185
     186                if (success && code === 200) {
     187                    registerMessage(responseData.message);
     188
     189                } else if (success) {
     190                    let message = '<h2>' + code + ': ' + responseData.error + '<h2>';
     191                    if (responseData.error !== responseData.message) {
     192                        message += responseData.message;
     193                    }
     194
     195                    registerMessage(message, 'danger');
     196
     197                } else if (typeof responseData == 'string') {
     198                    registerMessage(responseData, 'danger');
     199
     200                } else if (typeof responseData.forEach !== 'undefined') {
     201                    let message = '';
     202                    responseData.forEach(function(error) {
     203                        message += '<p>' + error.message + '</p>';
     204                    });
     205                    registerMessage(message, 'danger');
     206
     207                } else {
     208                    console.log(response);
     209                    registerMessage('Unknown Response', 'danger')
     210                }
     211
     212            })
     213            .error(function($xhr) {
     214                let message = 'Unknown Error'
     215                if ($xhr.responseJSON) {
     216                    message = $xhr.responseJSON.data || message;
     217                } else if ($xhr.responseText) {
     218                    message = $xhr.responseText;
     219                }
     220
     221                registerMessage(message, 'danger');
     222            });
     223    });
    188224});
  • logtivity/tags/3.1.12/logtivity.php

    r3294349 r3306623  
    66 * Description:       Record activity logs and errors logs across all your WordPress sites.
    77 * Author:            Logtivity
    8  * Version:           3.1.11
     8 * Version:           3.1.12
    99 * Text Domain:       logtivity
    1010 * Requires at least: 4.7
     
    4545     * @var string
    4646     */
    47     protected string $version = '3.1.11';
     47    protected string $version = '3.1.12';
    4848
    4949    /**
    5050     * List all classes here with their file paths. Keep class names the same as filenames.
     51     * Ordering of this list matters!
     52     * @TODO: Implement pst-0 autoloading
    5153     *
    5254     * @var string[]
     
    5961        'Admin/Logtivity_Dismiss_Notice_Controller',
    6062        'Admin/Logtivity_Options',
     63        'Admin/Logtivity_Response',
    6164        'Admin/Logtivity_Admin',
    6265        'Services/Logtivity_User_Logger_Trait',
     
    208211            }
    209212        }
     213    }
     214
     215    /**
     216     * Main entry for registering a site using the team API Key
     217     *
     218     * @param ?string $teamApi
     219     * @param ?string $teamName
     220     * @param ?string $siteName
     221     * @param ?string $url
     222     *
     223     * @return null|Logtivity_Response|WP_Error
     224     */
     225    public static function registerSite(
     226        ?string $teamApi,
     227        ?string $teamName = null,
     228        ?string $siteName = null,
     229        ?string $url = null
     230    ) {
     231        $logtivityOptions = new Logtivity_Options();
     232
     233        if ($logtivityOptions->getApiKey()) {
     234            $response = new WP_Error(
     235                'logtivity_register_site_error',
     236                __('You have already entered an API Key for this site.', 'logtivity')
     237            );
     238
     239        } elseif ($teamApi) {
     240            $request = [
     241                'method'   => 'POST',
     242                'timeout'  => 6,
     243                'blocking' => true,
     244                'body'     => [
     245                    'team_name' => $teamName,
     246                    'name'      => $siteName ?: get_bloginfo('name'),
     247                    'url'       => $url ?: home_url(),
     248                ],
     249                'cookies'  => [],
     250            ];
     251
     252            $response = new Logtivity_Response($teamApi, '/sites', $request);
     253            if ($response->code == 200 && $response->error == false) {
     254                $apikey   = $response->body['api_key'] ?? null;
     255                $teamName = $response->body['team_name'] ?? '*unknown*';
     256                $created  = $response->body['created_at'] ?? null;
     257                $isNew    = $response->body['is_new'] ?? null;
     258
     259                if ($apikey) {
     260                    $logtivityOptions->update(['logtivity_site_api_key' => $apikey]);
     261
     262                    if ($isNew) {
     263                        $response->message = sprintf(
     264                            'This site has been created on <a href="%s" target="_blank">Logtivity</a> for team \'%s\'. Logging is now enabled.',
     265                            logtivity_get_app_url(),
     266                            $teamName
     267                        );
     268
     269                    } else {
     270                        if ($created) {
     271                            $createdTimestamp = strtotime($created);
     272                            $creationText = sprintf(
     273                                'It was created on %s at %s ',
     274                                wp_date(get_option('date_format'), $createdTimestamp),
     275                                wp_date(get_option('time_format'), $createdTimestamp)
     276                            );
     277                        }
     278                        $response->message = sprintf(
     279                            'This site was found on <a href="%s" target="_blank">Logtivity</a>. %sfor the team \'%s\'. Logging is now enabled.',
     280                            logtivity_get_app_url(),
     281                            $creationText ?? '',
     282                            $teamName
     283                        );
     284                    }
     285                }
     286            }
     287
     288        } else {
     289            $response = new WP_Error('logtivity_missing_data', 'Team API Key is required.');
     290        }
     291
     292        return $response ?? null;
    210293    }
    211294
  • logtivity/tags/3.1.12/readme.txt

    r3294349 r3306623  
    55Requires at least: 6.6
    66Tested up to: 6.8
    7 Stable tag: 3.1.11
     7Stable tag: 3.1.12
    88Requires PHP: 7.4
    99License: GPLv2 or later
     
    122122#### Once Activated
    123123Visit 'Tools > Logtivity' to view the settings page.
    124 Enter your Logtivity API key, configure your options and your event monitoring will start!
     124Enter your Logtivity API Key, configure your options and your event monitoring will start!
    125125
    126126== Frequently Asked Questions ==
     
    262262
    263263== Changelog ==
     264
     265= 3.1.12 =
     266
     267* New: Register Site with Team API
     268* Update: Adjust screen styles and messaging
     269
     270_Release Date - Wednesday, June 4, 2025_
    264271
    265272= 3.1.11 =
     
    604611= 1.4.0 =
    605612* Removed deprecated async method from Logtivity_Logger class.
    606 * Added API key verification when updating Logtivity settings.
     613* Added API Key verification when updating Logtivity settings.
    607614
    608615= 1.3.1 =
  • logtivity/tags/3.1.12/views/activation.php

    r3294349 r3306623  
    2929                    <?php
    3030                    echo sprintf(
    31                         esc_html__('%sClick the "Add Site" button%s  and get your API key.', 'logtivity'),
     31                        esc_html__('%sClick the "Add Site" button%s  and get your API Key.', 'logtivity'),
    3232                        '<a target="_blank" href="https://logtivity.io/docs/connect-your-site-to-logtivity/">',
    3333                        '</a>'
     
    3838                    <?php
    3939                    echo sprintf(
    40                         esc_html__('Add your API key into %sthe "Settings" area%s on this site.', 'logtivity'),
     40                        esc_html__('Add your API Key into %sthe "Settings" area%s on this site.', 'logtivity'),
    4141                        '<a target="_blank" href="' . admin_url('admin.php?page=logtivity-settings') . '">',
    4242                        '</a>'
  • logtivity/tags/3.1.12/views/settings.php

    r3290027 r3306623  
    4040
    4141<div class="postbox logtivity-settings">
    42     <?php if (logtivity_has_site_url_changed()): ?>
    43         <div style="background: #DC3232;color: #fff;padding: 1em">
    44             <h2 style="color: white; padding-left: 0" class="title">We've detected a change in your site URL.</h2>
    45             <p>Is this a dev or staging environment? As a precaution, we've stopped logging. To start recording
    46                 logs, again click the 'Update Settings' button below.</p>
    47         </div>
    48     <?php endif ?>
    49 
    5042    <div class="inside">
    5143        <h1 style="padding-top: 20px;">Settings</h1>
     44
     45        <?php if (logtivity_has_site_url_changed()): ?>
     46            <div class="logtivity-notice logtivity-notice-danger">
     47                <h2>We've detected a change in your site URL.</h2>
     48                <div>
     49                    Is this a dev or staging environment? As a precaution, we've stopped logging. To start recording
     50                    logs, again click the 'Update Settings' button below.
     51                </div>
     52            </div>
     53        <?php endif ?>
    5254
    5355        <form action="<?php echo admin_url('admin-ajax.php'); ?>?action=logtivity_update_settings" method="post">
     
    104106                        <span class="description">
    105107                            You can find this value by logging into your account
    106                             and navigating to/creating this site settings page.
     108                            and navigating to this site's settings page.
    107109                        </span>
    108110                    </td>
     
    261263                        <span class="description">
    262264                            When messages are sent to Logtivity, the site URL will be checked
    263                             against the URL Logtivity has on file for this API key. If they do
     265                            against the URL Logtivity has on file for this API Key. If they do
    264266                            not match, logging will be paused.
    265267                        </span>
     
    338340                                    If you have multiple sites on Logtivity and would rather control disabled
    339341                                    logs globally you can go to the
    340                                     <a href="<?php echo logtivity_get_app_url() . '/team-settings/activity-log-settings'; ?>"
    341                                        target="_blank"
    342                                        rel="nofollow"
    343                                     >Activity Log Settings page</a>
     342                                    <?php
     343                                    echo sprintf(
     344                                        '<a href="%s" target="_blank" rel="nofollow">%s</a>',
     345                                        logtivity_get_app_url() . '/team-settings/activity-log-settings',
     346                                        'Activity Log Settings page'
     347                                    );
     348                                    ?>
    344349                                    in your Logtivity dashboard.
    345350                                <?php endif; ?>
  • logtivity/trunk/Admin/Logtivity_Admin.php

    r3290027 r3306623  
    4646        add_action('wp_ajax_nopriv_logtivity_update_settings', [$this, 'update']);
    4747
     48        add_action('wp_ajax_logtivity_register_site', [$this, 'registerSite']);
     49
    4850        add_filter('logtivity_hide_from_menu', [$this, 'shouldHidePluginFromUI']);
    4951        add_filter('all_plugins', [$this, 'maybeHideFromMenu']);
     
    98100
    99101    /**
    100      * Register the settings page
    101      */
    102     public function registerOptionsPage()
     102     * Create the admin menus
     103     *
     104     * @return void
     105     */
     106    public function registerOptionsPage(): void
    103107    {
    104108        if (!apply_filters('logtivity_hide_from_menu', false)) {
     
    116120        if (!apply_filters('logtivity_hide_settings_page', false)) {
    117121            add_submenu_page(
    118                 ($this->options->isWhiteLabelMode() ? 'lgtvy-logs' : 'logtivity'),
     122                $this->options->isWhiteLabelMode() ? 'lgtvy-logs' : 'logtivity',
    119123                'Logtivity Settings',
    120124                'Settings',
    121125                Logtivity::ACCESS_SETTINGS,
    122                 'logtivity' . '-settings',
    123                 [$this, 'showLogtivitySettingsPage']
     126                'logtivity-settings',
     127                [$this, 'showSettingsPage']
    124128            );
    125129        }
     130
     131        if ($this->options->getApiKey() == false) {
     132            add_submenu_page(
     133                $this->options->isWhiteLabelMode() ? 'lgtvy-logs' : 'logtivity',
     134                'Register Site',
     135                'Register Site',
     136                Logtivity::ACCESS_SETTINGS,
     137                'logtivity-register-site',
     138                [$this, 'showRegisterSitePage']
     139            );
     140        }
    126141    }
    127142
     
    131146     * @return void
    132147     */
    133     public function showLogIndexPage()
     148    public function showLogIndexPage(): void
    134149    {
    135150        if (!current_user_can(Logtivity::ACCESS_LOGS)) {
     
    147162     * @return void
    148163     */
    149     public function showLogtivitySettingsPage()
     164    public function showSettingsPage(): void
    150165    {
    151166        if (!current_user_can(Logtivity::ACCESS_SETTINGS)) {
     
    159174
    160175    /**
     176     * Show the register by team API page
     177     *
     178     * @return void
     179     */
     180    public function showRegisterSitePage(): void
     181    {
     182        if (!current_user_can(Logtivity::ACCESS_SETTINGS)) {
     183            wp_die(__('You do not have sufficient permissions to access this page.'));
     184        }
     185
     186        $options = $this->options->getOptions();
     187
     188        echo logtivity_view('register', compact('options'));
     189    }
     190
     191    /**
    161192     * @return void
    162193     */
     
    165196        if (!wp_verify_nonce($_POST['logtivity_update_settings'] ?? null, 'logtivity_update_settings')) {
    166197            wp_safe_redirect($this->settingsPageUrl());
    167             exit;
     198            exit();
    168199        }
    169200
     
    172203        if (!$user->hasRole('administrator')) {
    173204            wp_safe_redirect($this->settingsPageUrl());
    174             exit;
     205            exit();
    175206        }
    176207
     
    189220
    190221        wp_safe_redirect($this->settingsPageUrl());
    191         exit;
     222        exit();
     223    }
     224
     225    /**
     226     * ajax endpoint for registering with a team API Key
     227     *
     228     * @return void
     229     */
     230    public function registerSite(): void
     231    {
     232        try {
     233            if (wp_verify_nonce($_POST['logtivity_register_site'] ?? null, 'logtivity_register_site')) {
     234                $teamApi  = sanitize_text_field($_POST['logtivity_team_api_key'] ?? null);
     235
     236                $response = Logtivity::registerSite($teamApi);
     237
     238
     239                if ($response instanceof WP_Error) {
     240                    wp_send_json_error($response);
     241                } else {
     242                    wp_send_json_success($response);
     243                }
     244
     245            } else {
     246                wp_send_json_error('Invalid Request');
     247            }
     248
     249        } catch (Throwable $error) {
     250            wp_send_json_error($error->getMessage(), $error->getCode());
     251        }
     252
     253        wp_die();
    192254    }
    193255
  • logtivity/trunk/Admin/Logtivity_Options.php

    r3290027 r3306623  
    9494
    9595    /**
    96      * Get the API key for the site
     96     * Get the API Key for the site
    9797     *
    9898     * @return string
  • logtivity/trunk/Services/Logtivity_Api.php

    r3290027 r3306623  
    4848
    4949    /**
    50      * The API key for either the site or team
     50     * The API Key for either the site or team
    5151     *
    5252     * @var ?string
     
    175175            ];
    176176
     177            // @TODO: Switch to Logtivity_Response class to get standardized responses
    177178            $response = wp_remote_request($this->getEndpoint($url), $request);
    178179            if ($this->notUpdatingWidgetInCustomizer()) {
     
    190191                    $responseMessage = wp_remote_retrieve_response_message($response);
    191192                    $responseBody    = json_decode(wp_remote_retrieve_body($response), true);
    192                     $responseError   = $responseCode < 400
    193                         ? ($responseBody['error'] ?? null)
    194                         : ($responseMessage ?: 'Unknown error');
    195 
     193
     194                    if ($responseCode < 400) {
     195                        $responseError = $responseBody['error'] ?? null;
     196                    } else {
     197                        $responseError   = $responseMessage;
     198                        $responseMessage = (($responseBody['message'] ?? $responseMessage) ?: 'Unknown error');
     199
     200                    }
    196201                    $responseData = [
    197202                        'code'    => $responseCode,
     
    310315                    $message = sprintf('Disconnected (%s - %s)', $code, $message);
    311316                } else {
    312                     $message = 'Not connected. Please check API key';
     317                    $message = 'Not connected. Please check API Key';
    313318                }
    314319
  • logtivity/trunk/assets/admin.css

    r3294349 r3306623  
    8989body[class*="_page_logtivity"] .button-primary:hover,
    9090body[class*="_page_lgtvy-logs"] .button-primary:hover {
    91   background-color: #28679b;
     91  background-color: #307bb9;
    9292  border-color: #256091;
    9393  color: #fff;
     
    135135.logtivity-button-primary:focus,
    136136.logtivity-button-primary:active {
    137   background-color: #fcc948 !important;
    138   border-color: #fcc948 !important;
     137  background-color: #f6993f !important;
     138  border-color: #f6993f !important;
    139139  color: #13314a !important;
    140140}
     
    143143.logtivity-button:focus,
    144144.logtivity-button:active {
    145   box-shadow: 0 15px 25px -7px rgba(0,0,0,0.1) !important;
     145  box-shadow: 0 15px 25px -7px rgba(0, 0, 0, 0.1) !important;
    146146}
    147147
     
    166166  font-size: 14px;
    167167  line-height: 1.2 !important;
     168}
     169
     170.logtivity-notice-info *,
     171.logtivity-notice-warning *,
     172.logtivity-notice-danger * {
     173  background-color: #e1effbff;
     174}
     175
     176.logtivity-notice-warning {
     177  border-left: 4px solid #f6993f;
     178}
     179
     180.logtivity-notice-danger {
     181  border-left: 4px solid #e3342f;
    168182}
    169183
     
    190204.logtivity-settings input[type="search"]:focus {
    191205  background-color: #fff;
    192   border-color: #88b8e0;
     206  border-color: #6cb2eb;
    193207  box-shadow: 0 0 0 .2rem rgba(48, 123, 185, .25);
    194208  color: #495057;
     
    302316
    303317.logtivity-modal-strip {
    304   background: #0073AA;
     318  background: #307bb9;
    305319  padding-top: 20px;
    306320  padding-bottom: 20px;
     
    308322
    309323.logtivity-modal-strip.light {
    310   background: #00A0D2;
     324  background: #6cb2eb;
    311325}
    312326
  • logtivity/trunk/assets/app.js

    r2717247 r3306623  
    1 var LogtivityLogIndex = {
    2    
    3     init: function() {
    4         this.container = jQuery('#logtivity-log-index');
    5 
    6         if (!this.container.length) {
    7             return;
    8         }
    9        
    10         this.form = jQuery('#logtivity-log-index-search-form');
    11 
    12         this.listenForPagination();
    13 
    14         this.listenForChange();
    15 
    16         this.filter();
    17 
    18         this.listenForViewLog()
    19 
    20         this.listenForCloseModal();
    21     },
    22 
    23     listenForCloseModal: function() {
    24 
    25         var $this = this;
    26 
    27         jQuery("body").on( "click", ".js-logtivity-notice-dismiss", function(e) {
    28             e.preventDefault();
    29 
    30             $this.hideModal();
    31 
    32         });
    33 
    34         jQuery(document).on('keyup', function(e) {
    35 
    36             if (e.key == "Escape") {
    37                 $this.hideModal();
    38             }
    39 
    40         });
    41 
    42         jQuery(document).mouseup(function(e) {
    43 
    44             if (!$this.modalOpen) {
    45                 return;
    46             }
    47 
    48             var container = jQuery('.logtivity-modal-dialog');
    49 
    50             // if the target of the click isn't the container nor a descendant of the container
    51             if (!container.is(e.target) && container.has(e.target).length === 0) {
    52                 $this.hideModal();
    53             }
    54 
    55         });
    56 
    57     },
    58 
    59     listenForViewLog: function() {
    60 
    61         var $this = this;
    62 
    63         jQuery("body").on( "click", ".js-logtivity-view-log", function(e) {
    64             e.preventDefault();
    65 
    66             $this.showLogModal(jQuery(this).next().html());
    67         });
    68 
    69     },
    70 
    71     showLogModal: function(modalContent) {
    72 
    73         jQuery('.logtivity-modal').addClass('active');
    74 
    75         this.modalOpen = true;
    76 
    77         jQuery('.logtivity-modal-content').html(modalContent);
    78 
    79     },
    80 
    81     hideModal: function() {
    82 
    83         jQuery('.logtivity-modal').removeClass('active');
    84 
    85         this.modalOpen = false;
    86 
    87     },
    88 
    89     listenForChange: function() {
    90 
    91         var $this = this;
    92 
    93         var timeout = null;
    94 
    95         jQuery("body").on( "input", "#logtivity-log-index-search-form input", function(e) {
    96             e.preventDefault();
    97 
    98             jQuery('#logtivity_page').val('');
    99 
    100             // Clear the timeout if it has already been set.
    101             // This will prevent the previous task from executing
    102             // if it has been less than <MILLISECONDS>
    103             clearTimeout(timeout);
    104 
    105             // Make a new timeout set to go off in 1000ms
    106             timeout = setTimeout(function () {
    107                
    108                 $this.filter();
    109 
    110             }, 1000);
    111 
    112         });
    113 
    114     },
    115 
    116     loading: function() {
    117 
    118         this.container.html(
    119             '<div style="text-align: center; padding-bottom: 20px"><div class="spinner is-active" style="float:none;width:auto;height:auto;padding:10px 0 10px 50px;background-position:20px 0;"></div></div>'
    120             );
    121    
    122     },
    123 
    124     listenForPagination: function() {
    125 
    126         var $this = this;
    127 
    128         jQuery("body").on( "click", ".js-logtivity-pagination", function(e) {
    129             e.preventDefault();
    130 
    131             jQuery('#logtivity_page').val(jQuery(this).attr('data-page'));
    132 
    133             $this.filter();
    134         });
    135 
    136     },
    137 
    138     filter: function() {
    139 
    140         this.loading();
    141 
    142         var $this = this;
    143 
    144         jQuery.ajax({
    145             url: $this.form.attr('action'),
    146             type: 'GET',
    147             data: $this.form.serialize(),
    148             success: function(result) {
    149                 $this.container.html(result.view);
    150             },
    151             error: function(error) {
    152                 console.log(error);
    153             }
    154         });
    155 
    156     }
    157 
    158 };
    159 
    160 var DismissUrlHasChanged = {
    161 
    162     init: function() {
    163 
    164         jQuery( document ).on( 'click', '.notice-dismiss', function () {
    165             var type = jQuery(this).closest('.is-dismissible').attr('notice');
    166             var dismissUntil = jQuery(this).closest('.is-dismissible').attr('dismiss-until');
    167 
    168             if (type) {
    169                 jQuery.ajax( ajaxurl, {
    170                     type: 'POST',
    171                     data: {
    172                         action: 'logtivity_dismiss_notice',
    173                         type: type,
    174                         dismiss_until: dismissUntil,
    175                     }
    176                 });
    177             }
    178 
    179         });
    180 
    181     }
    182 
    183 };
    184 
    185 jQuery(function() {
    186     LogtivityLogIndex.init();
    187     DismissUrlHasChanged.init();
     1jQuery(function($) {
     2    let LogtivityLogIndex = {
     3        init: function() {
     4            this.container = $('#logtivity-log-index');
     5
     6            if (!this.container.length) {
     7                return;
     8            }
     9
     10            this.form = $('#logtivity-log-index-search-form');
     11            this.listenForPagination();
     12            this.listenForChange();
     13            this.filter();
     14            this.listenForViewLog()
     15            this.listenForCloseModal();
     16        },
     17
     18        listenForCloseModal: function() {
     19            let listenForCloseModal = this;
     20
     21            $("body").on("click", ".js-logtivity-notice-dismiss", function(e) {
     22                e.preventDefault();
     23
     24                listenForCloseModal.hideModal();
     25            });
     26
     27            $(document).on('keyup', function(e) {
     28                if (e.key === "Escape") {
     29                    listenForCloseModal.hideModal();
     30                }
     31
     32            });
     33
     34            $(document).mouseup(function(e) {
     35                if (!listenForCloseModal.modalOpen) {
     36                    return;
     37                }
     38
     39                let $container = $('.logtivity-modal-dialog');
     40
     41                // if the target of the click isn't the container nor a descendant of the container
     42                if (!$container.is(e.target) && $container.has(e.target).length === 0) {
     43                    listenForCloseModal.hideModal();
     44                }
     45            });
     46        },
     47
     48        listenForViewLog: function() {
     49            let listenForViewLog = this;
     50
     51            $("body").on("click", ".js-logtivity-view-log", function(e) {
     52                e.preventDefault();
     53
     54                listenForViewLog.showLogModal($(this).next().html());
     55            });
     56        },
     57
     58        showLogModal: function(modalContent) {
     59            $('.logtivity-modal').addClass('active');
     60
     61            this.modalOpen = true;
     62
     63            $('.logtivity-modal-content').html(modalContent);
     64        },
     65
     66        hideModal: function() {
     67            $('.logtivity-modal').removeClass('active');
     68
     69            this.modalOpen = false;
     70        },
     71
     72        listenForChange: function() {
     73            let listenForChange = this,
     74                timeout         = null;
     75
     76            $("body").on("input", "#logtivity-log-index-search-form input", function(e) {
     77                e.preventDefault();
     78
     79                $('#logtivity_page').val('');
     80
     81                // Clear the timeout if it has already been set.
     82                // This will prevent the previous task from executing
     83                // if it has been less than <MILLISECONDS>
     84                clearTimeout(timeout);
     85
     86                // Make a new timeout set to go off in 1000ms
     87                timeout = setTimeout(function() {
     88                    listenForChange.filter();
     89                }, 1000);
     90            });
     91        },
     92
     93        loading: function() {
     94            this.container.html(
     95                '<div style="text-align: center; padding-bottom: 20px"><div class="spinner is-active" style="float:none;width:auto;height:auto;padding:10px 0 10px 50px;background-position:20px 0;"></div></div>'
     96            );
     97        },
     98
     99        listenForPagination: function() {
     100            let listenForPagination = this;
     101
     102            $("body").on("click", ".js-logtivity-pagination", function(e) {
     103                e.preventDefault();
     104
     105                $('#logtivity_page').val($(this).attr('data-page'));
     106
     107                listenForPagination.filter();
     108            });
     109        },
     110
     111        filter: function() {
     112            let filter = this;
     113
     114            this.loading();
     115
     116            $.ajax({
     117                url    : filter.form.attr('action'),
     118                type   : 'GET',
     119                data   : filter.form.serialize(),
     120                success: function(result) {
     121                    filter.container.html(result.view);
     122                },
     123                error  : function(error) {
     124                    console.log(error);
     125                }
     126            });
     127        }
     128    };
     129
     130    let DismissUrlHasChanged = {
     131        init: function() {
     132            $(document).on('click', '.notice-dismiss', function() {
     133                let type         = $(this).closest('.is-dismissible').attr('notice'),
     134                    dismissUntil = $(this).closest('.is-dismissible').attr('dismiss-until');
     135
     136                if (type) {
     137                    $.ajax(ajaxurl, {
     138                        type: 'POST',
     139                        data: {
     140                            action       : 'logtivity_dismiss_notice',
     141                            type         : type,
     142                            dismiss_until: dismissUntil,
     143                        }
     144                    });
     145                }
     146            });
     147        }
     148    };
     149
     150    LogtivityLogIndex.init();
     151    DismissUrlHasChanged.init();
     152
     153    let registerMessage = function(message, type) {
     154        type = type || 'info';
     155
     156        let $messaging = $('#logtivity-register-response')
     157            .removeClass()
     158            .addClass('logtivity-notice logtivity-notice-' + type)
     159            .css('width', 'fit-content');
     160
     161        if (message) {
     162            $messaging
     163                .css('display', 'block')
     164                .html('<div>' + message + '</div>');
     165        } else {
     166            $messaging
     167                .css('display', 'none')
     168                .html();
     169        }
     170    };
     171
     172    $('#logtivity-register-site').on('submit', function(evt) {
     173        evt.preventDefault();
     174
     175        registerMessage();
     176
     177        $.post(this.getAttribute('action'), $(this).serialize())
     178            .success(function(response) {
     179                let success      = response.success || false,
     180                    responseData = response.data || [],
     181                    code         = responseData.code || 200;
     182
     183                console.log(responseData);
     184                console.log(response);
     185
     186                if (success && code === 200) {
     187                    registerMessage(responseData.message);
     188
     189                } else if (success) {
     190                    let message = '<h2>' + code + ': ' + responseData.error + '<h2>';
     191                    if (responseData.error !== responseData.message) {
     192                        message += responseData.message;
     193                    }
     194
     195                    registerMessage(message, 'danger');
     196
     197                } else if (typeof responseData == 'string') {
     198                    registerMessage(responseData, 'danger');
     199
     200                } else if (typeof responseData.forEach !== 'undefined') {
     201                    let message = '';
     202                    responseData.forEach(function(error) {
     203                        message += '<p>' + error.message + '</p>';
     204                    });
     205                    registerMessage(message, 'danger');
     206
     207                } else {
     208                    console.log(response);
     209                    registerMessage('Unknown Response', 'danger')
     210                }
     211
     212            })
     213            .error(function($xhr) {
     214                let message = 'Unknown Error'
     215                if ($xhr.responseJSON) {
     216                    message = $xhr.responseJSON.data || message;
     217                } else if ($xhr.responseText) {
     218                    message = $xhr.responseText;
     219                }
     220
     221                registerMessage(message, 'danger');
     222            });
     223    });
    188224});
  • logtivity/trunk/logtivity.php

    r3294349 r3306623  
    66 * Description:       Record activity logs and errors logs across all your WordPress sites.
    77 * Author:            Logtivity
    8  * Version:           3.1.11
     8 * Version:           3.1.12
    99 * Text Domain:       logtivity
    1010 * Requires at least: 4.7
     
    4545     * @var string
    4646     */
    47     protected string $version = '3.1.11';
     47    protected string $version = '3.1.12';
    4848
    4949    /**
    5050     * List all classes here with their file paths. Keep class names the same as filenames.
     51     * Ordering of this list matters!
     52     * @TODO: Implement pst-0 autoloading
    5153     *
    5254     * @var string[]
     
    5961        'Admin/Logtivity_Dismiss_Notice_Controller',
    6062        'Admin/Logtivity_Options',
     63        'Admin/Logtivity_Response',
    6164        'Admin/Logtivity_Admin',
    6265        'Services/Logtivity_User_Logger_Trait',
     
    208211            }
    209212        }
     213    }
     214
     215    /**
     216     * Main entry for registering a site using the team API Key
     217     *
     218     * @param ?string $teamApi
     219     * @param ?string $teamName
     220     * @param ?string $siteName
     221     * @param ?string $url
     222     *
     223     * @return null|Logtivity_Response|WP_Error
     224     */
     225    public static function registerSite(
     226        ?string $teamApi,
     227        ?string $teamName = null,
     228        ?string $siteName = null,
     229        ?string $url = null
     230    ) {
     231        $logtivityOptions = new Logtivity_Options();
     232
     233        if ($logtivityOptions->getApiKey()) {
     234            $response = new WP_Error(
     235                'logtivity_register_site_error',
     236                __('You have already entered an API Key for this site.', 'logtivity')
     237            );
     238
     239        } elseif ($teamApi) {
     240            $request = [
     241                'method'   => 'POST',
     242                'timeout'  => 6,
     243                'blocking' => true,
     244                'body'     => [
     245                    'team_name' => $teamName,
     246                    'name'      => $siteName ?: get_bloginfo('name'),
     247                    'url'       => $url ?: home_url(),
     248                ],
     249                'cookies'  => [],
     250            ];
     251
     252            $response = new Logtivity_Response($teamApi, '/sites', $request);
     253            if ($response->code == 200 && $response->error == false) {
     254                $apikey   = $response->body['api_key'] ?? null;
     255                $teamName = $response->body['team_name'] ?? '*unknown*';
     256                $created  = $response->body['created_at'] ?? null;
     257                $isNew    = $response->body['is_new'] ?? null;
     258
     259                if ($apikey) {
     260                    $logtivityOptions->update(['logtivity_site_api_key' => $apikey]);
     261
     262                    if ($isNew) {
     263                        $response->message = sprintf(
     264                            'This site has been created on <a href="%s" target="_blank">Logtivity</a> for team \'%s\'. Logging is now enabled.',
     265                            logtivity_get_app_url(),
     266                            $teamName
     267                        );
     268
     269                    } else {
     270                        if ($created) {
     271                            $createdTimestamp = strtotime($created);
     272                            $creationText = sprintf(
     273                                'It was created on %s at %s ',
     274                                wp_date(get_option('date_format'), $createdTimestamp),
     275                                wp_date(get_option('time_format'), $createdTimestamp)
     276                            );
     277                        }
     278                        $response->message = sprintf(
     279                            'This site was found on <a href="%s" target="_blank">Logtivity</a>. %sfor the team \'%s\'. Logging is now enabled.',
     280                            logtivity_get_app_url(),
     281                            $creationText ?? '',
     282                            $teamName
     283                        );
     284                    }
     285                }
     286            }
     287
     288        } else {
     289            $response = new WP_Error('logtivity_missing_data', 'Team API Key is required.');
     290        }
     291
     292        return $response ?? null;
    210293    }
    211294
  • logtivity/trunk/readme.txt

    r3294349 r3306623  
    55Requires at least: 6.6
    66Tested up to: 6.8
    7 Stable tag: 3.1.11
     7Stable tag: 3.1.12
    88Requires PHP: 7.4
    99License: GPLv2 or later
     
    122122#### Once Activated
    123123Visit 'Tools > Logtivity' to view the settings page.
    124 Enter your Logtivity API key, configure your options and your event monitoring will start!
     124Enter your Logtivity API Key, configure your options and your event monitoring will start!
    125125
    126126== Frequently Asked Questions ==
     
    262262
    263263== Changelog ==
     264
     265= 3.1.12 =
     266
     267* New: Register Site with Team API
     268* Update: Adjust screen styles and messaging
     269
     270_Release Date - Wednesday, June 4, 2025_
    264271
    265272= 3.1.11 =
     
    604611= 1.4.0 =
    605612* Removed deprecated async method from Logtivity_Logger class.
    606 * Added API key verification when updating Logtivity settings.
     613* Added API Key verification when updating Logtivity settings.
    607614
    608615= 1.3.1 =
  • logtivity/trunk/views/activation.php

    r3294349 r3306623  
    2929                    <?php
    3030                    echo sprintf(
    31                         esc_html__('%sClick the "Add Site" button%s  and get your API key.', 'logtivity'),
     31                        esc_html__('%sClick the "Add Site" button%s  and get your API Key.', 'logtivity'),
    3232                        '<a target="_blank" href="https://logtivity.io/docs/connect-your-site-to-logtivity/">',
    3333                        '</a>'
     
    3838                    <?php
    3939                    echo sprintf(
    40                         esc_html__('Add your API key into %sthe "Settings" area%s on this site.', 'logtivity'),
     40                        esc_html__('Add your API Key into %sthe "Settings" area%s on this site.', 'logtivity'),
    4141                        '<a target="_blank" href="' . admin_url('admin.php?page=logtivity-settings') . '">',
    4242                        '</a>'
  • logtivity/trunk/views/settings.php

    r3290027 r3306623  
    4040
    4141<div class="postbox logtivity-settings">
    42     <?php if (logtivity_has_site_url_changed()): ?>
    43         <div style="background: #DC3232;color: #fff;padding: 1em">
    44             <h2 style="color: white; padding-left: 0" class="title">We've detected a change in your site URL.</h2>
    45             <p>Is this a dev or staging environment? As a precaution, we've stopped logging. To start recording
    46                 logs, again click the 'Update Settings' button below.</p>
    47         </div>
    48     <?php endif ?>
    49 
    5042    <div class="inside">
    5143        <h1 style="padding-top: 20px;">Settings</h1>
     44
     45        <?php if (logtivity_has_site_url_changed()): ?>
     46            <div class="logtivity-notice logtivity-notice-danger">
     47                <h2>We've detected a change in your site URL.</h2>
     48                <div>
     49                    Is this a dev or staging environment? As a precaution, we've stopped logging. To start recording
     50                    logs, again click the 'Update Settings' button below.
     51                </div>
     52            </div>
     53        <?php endif ?>
    5254
    5355        <form action="<?php echo admin_url('admin-ajax.php'); ?>?action=logtivity_update_settings" method="post">
     
    104106                        <span class="description">
    105107                            You can find this value by logging into your account
    106                             and navigating to/creating this site settings page.
     108                            and navigating to this site's settings page.
    107109                        </span>
    108110                    </td>
     
    261263                        <span class="description">
    262264                            When messages are sent to Logtivity, the site URL will be checked
    263                             against the URL Logtivity has on file for this API key. If they do
     265                            against the URL Logtivity has on file for this API Key. If they do
    264266                            not match, logging will be paused.
    265267                        </span>
     
    338340                                    If you have multiple sites on Logtivity and would rather control disabled
    339341                                    logs globally you can go to the
    340                                     <a href="<?php echo logtivity_get_app_url() . '/team-settings/activity-log-settings'; ?>"
    341                                        target="_blank"
    342                                        rel="nofollow"
    343                                     >Activity Log Settings page</a>
     342                                    <?php
     343                                    echo sprintf(
     344                                        '<a href="%s" target="_blank" rel="nofollow">%s</a>',
     345                                        logtivity_get_app_url() . '/team-settings/activity-log-settings',
     346                                        'Activity Log Settings page'
     347                                    );
     348                                    ?>
    344349                                    in your Logtivity dashboard.
    345350                                <?php endif; ?>
Note: See TracChangeset for help on using the changeset viewer.