| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Plugin Name: Writesonic |
| 5 |
* Description: Publish content from Writesonic to your site and measure how AI crawlers read it. |
| 6 |
* Version: 2.0.0 |
| 7 |
* Author: Writesonic |
| 8 |
* Author URI: https://writesonic.com/ |
| 9 |
* Text Domain: writesonic |
| 10 |
* Domain Path: /languages |
| 11 |
* Requires at least: 6.0 |
| 12 |
* Requires PHP: 7.4 |
| 13 |
* License: GPLv2 or later |
| 14 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 15 |
*/ |
| 16 |
|
| 17 |
if (!defined('ABSPATH')) { |
| 18 |
exit; |
| 19 |
} |
| 20 |
|
| 21 |
if (version_compare(PHP_VERSION, '7.4', '<')) { |
| 22 |
add_action('admin_notices', function () { |
| 23 |
printf( |
| 24 |
'<div class="notice notice-error"><p>%s</p></div>', |
| 25 |
esc_html__('Writesonic requires PHP 7.4 or newer. The plugin is inactive.', 'writesonic') |
| 26 |
); |
| 27 |
}); |
| 28 |
|
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
if (!defined('WRITESONIC_VERSION')) { |
| 33 |
define('WRITESONIC_VERSION', '2.0.0'); |
| 34 |
} |
| 35 |
if (!defined('WRITESONIC_FILE')) { |
| 36 |
define('WRITESONIC_FILE', __FILE__); |
| 37 |
} |
| 38 |
if (!defined('WRITESONIC_DIR')) { |
| 39 |
define('WRITESONIC_DIR', plugin_dir_path(__FILE__)); |
| 40 |
} |
| 41 |
if (!defined('WRITESONIC_URL')) { |
| 42 |
define('WRITESONIC_URL', plugin_dir_url(__FILE__)); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Publishing token store. Shape is frozen: an array of `user_email => token`. |
| 47 |
* knowledge-and-integration-hub authenticates every `/writesonic/v2/*` call |
| 48 |
* against these values, so existing tokens must keep validating forever. |
| 49 |
*/ |
| 50 |
if (!defined('WRITESONIC_API_KEY_OPTION')) { |
| 51 |
define('WRITESONIC_API_KEY_OPTION', 'writesonic_api_key'); |
| 52 |
} |
| 53 |
|
| 54 |
if (!defined('WRITESONIC_CONNECT_URL')) { |
| 55 |
define('WRITESONIC_CONNECT_URL', 'https://app.writesonic.com/wordpress-authentication/'); |
| 56 |
} |
| 57 |
|
| 58 |
if (!defined('WRITESONIC_STATE_URL')) { |
| 59 |
define('WRITESONIC_STATE_URL', 'https://api.writesonic.com/v1/thirdparty/wordpress-connection-state'); |
| 60 |
} |
| 61 |
|
| 62 |
if (!defined('WRITESONIC_CLAIM_URL')) { |
| 63 |
define('WRITESONIC_CLAIM_URL', 'https://api.writesonic.com/v1/thirdparty/wordpress-analytics-claim'); |
| 64 |
} |
| 65 |
|
| 66 |
if (!defined('WRITESONIC_DEFAULT_INGESTION_DOMAIN')) { |
| 67 |
define('WRITESONIC_DEFAULT_INGESTION_DOMAIN', 'https://ingestion.writesonic.com'); |
| 68 |
} |
| 69 |
|
| 70 |
require_once WRITESONIC_DIR . 'includes/class-writesonic-rest.php'; |
| 71 |
require_once WRITESONIC_DIR . 'includes/class-writesonic-connection.php'; |
| 72 |
require_once WRITESONIC_DIR . 'includes/class-writesonic-analytics.php'; |
| 73 |
require_once WRITESONIC_DIR . 'includes/class-writesonic-migration.php'; |
| 74 |
require_once WRITESONIC_DIR . 'includes/class-writesonic-admin.php'; |
| 75 |
|
| 76 |
add_action('plugins_loaded', function () { |
| 77 |
load_plugin_textdomain('writesonic', false, dirname(plugin_basename(WRITESONIC_FILE)) . '/languages'); |
| 78 |
}); |
| 79 |
|
| 80 |
/** |
| 81 |
* Analytics is decided at `init` rather than at load time: the legacy plugin |
| 82 |
* registers its own interceptor on `init` too, so by this point every plugin |
| 83 |
* file is loaded and the conflict probe is authoritative regardless of the |
| 84 |
* order WordPress activated them in. |
| 85 |
*/ |
| 86 |
add_action('init', array('Writesonic_Migration', 'boot'), 0); |
| 87 |
add_action('init', array('Writesonic_Analytics', 'boot'), 1); |
| 88 |
|
| 89 |
WPM_Writesonic_Integration::init(); |
| 90 |
Writesonic_Connection::init(); |
| 91 |
Writesonic_Admin::init(); |
| 92 |
|
| 93 |
register_activation_hook(__FILE__, array('Writesonic_Migration', 'on_activate')); |
| 94 |
register_deactivation_hook(__FILE__, array('WPM_Writesonic_Integration', 'deactivation')); |
| 95 |
|