# logtivity/1.10.0/Services/Logtivity_Register_Site.php

Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity, version 1.10.0. 37 lines.

- Page: https://pluginprobe.com/plugins/logtivity/1.10.0/code/Services/Logtivity_Register_Site.php
- Raw: https://pluginprobe.com/plugins/logtivity/1.10.0/raw/Services/Logtivity_Register_Site.php
- Modified: 2022-02-14T14:00:10+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/logtivity/1.10.0/code/Services/Logtivity_Register_Site.php#L10-L20`.

```php
<?php

class Logtivity_Register_Site
{
	public static function execute($data = [])
	{
		$logtivity_options = new Logtivity_Options;

		if ($logtivity_options->getApiKey()) {
		    return new WP_Error(
		    	'logtivity_register_site_error', 
		    	__('You cannot register a site that already has an API Key.', 'logtivity')
		    );
		}

		$response = json_decode(
			(new Logtivity_Api)->setApiKey($data['team_api_key'])
				->post('/sites', [
					'name' => $data['name'] ?? home_url(),
					'url' => $data['url'] ?? home_url(),
				])
		);

		if ($response && property_exists($response, 'message')) {
			return wp_send_json(['response' => $response->message]);
		}

		$logtivity_options->update(
			array_merge(
				$data,
				[
					'logtivity_site_api_key' => $response->api_key
				]
			),
		);
	}
}
```
