This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
copycraft.php
119 lines (103 loc) · 2.93 KB
/
copycraft.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
/**
* Plugin Name: CopyCraft
* Plugin URI: https://copycraft.ai
* Description: AI-powered compelling product descriptions for your WooCommerce products using OpenAI GPT-3.
* Author: Tectalic
* Author URI: https://tectalic.com/
* Text Domain: copycraft
* Domain Path: /languages
* Version: 0.2.1
* WC requires at least: 7.0
* WC tested up to: 7.3
*/
namespace OM4\CopyCraft;
use OM4\CopyCraft\Modal\Register as ModalRegister;
use OM4\CopyCraft\Settings\Data;
use OM4\CopyCraft\Settings\Register as SettingsRegister;
use OM4\CopyCraft\Vendor\Art4\Requests\Psr\HttpClient;
use OM4\CopyCraft\Vendor\League\Container\Container;
use OM4\CopyCraft\Vendor\League\Container\ReflectionContainer;
use OM4\CopyCraft\Vendor\Tectalic\OpenAi\Authentication;
use OM4\CopyCraft\Vendor\Tectalic\OpenAi\Client;
use OM4\CopyCraft\Vendor\Tectalic\OpenAi\Manager;
defined( 'ABSPATH' ) || exit;
require_once 'includes/autoload.php';
/**
* The main plugin class.
*/
class Plugin {
/**
* Dependency Injection Container instance.
*
* @var Container
*/
private Container $container;
/**
* Plugin constructor.
*/
public function __construct() {
$this->container = new Container();
$this->container->add(
Client::class,
function () {
if ( Manager::isGlobal() ) {
return Manager::access();
}
/**
* Settings instance.
*
* @var Data $settings
*/
$settings = $this->container->get( Data::class );
$settings = $settings->get_settings();
return Manager::build(
new HttpClient(),
new Authentication( isset( $settings['openai_api_key'] ) ? $settings['openai_api_key'] : '' )
);
}
);
$this->container->delegate( new ReflectionContainer( true ) );
add_action( 'init', array( $this, 'admin_init' ) );
/**
* Declare compatibility with WooCommerce High-Performance Order Storage (HPOS).
*
* @link https://github.com/woocommerce/woocommerce/wiki/High-Performance-Order-Storage-Upgrade-Recipe-Book
*/
add_action(
'before_woocommerce_init',
function() {
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
}
}
);
}
/**
* Initialise the plugin, including all WordPress hooks/filters/actions.
* Executed during the `init` hook.
*
* @return void
*/
public function admin_init() {
if ( ! is_admin() ) {
// Non wp-admin page.
return;
}
/**
* Register instance for settings screen.
*
* @var SettingsRegister $settings
*/
$settings = $this->container->get( SettingsRegister::class );
add_action( 'admin_menu', array( $settings, 'register_settings' ) );
/**
* Register instance for modal screen.
*
* @var ModalRegister $modal
*/
$modal = $this->container->get( ModalRegister::class );
$modal->register_modal();
}
}
$copycraft = new Plugin();