-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathb2b-content-generator.php
More file actions
75 lines (66 loc) · 2.61 KB
/
b2b-content-generator.php
File metadata and controls
75 lines (66 loc) · 2.61 KB
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
<?php
/**
* Plugin Name: B2B AI Content Generator for WooCommerce
* Plugin URI: https://github.com/anjana-kanzariya/b2b-content-generator
* Description: Generate B2B-optimised product descriptions, excerpts, and SEO meta using AI — powered by OpenAI, Claude, Gemini, or OpenRouter. Works directly from your existing WooCommerce product data.
* Version: 1.0.0
* Author: Anjana Kanzariya
* Author URI: https://github.com/anjana-kanzariya
* License: GPL-2.0+
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: b2b-content-gen
* Domain Path: /languages
* Requires at least: 6.0
* Requires PHP: 7.4
* WC requires at least: 7.0
* WC tested up to: 9.0
*/
defined( 'ABSPATH' ) || exit;
define( 'B2BCG_VERSION', '1.0.0' );
define( 'B2BCG_PLUGIN_FILE', __FILE__ );
define( 'B2BCG_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'B2BCG_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
/**
* Check WooCommerce is active before doing anything.
*/
function b2bcg_check_dependencies(): void {
if ( ! class_exists( 'WooCommerce' ) ) {
add_action( 'admin_notices', 'b2bcg_missing_wc_notice' );
return;
}
b2bcg_init();
}
add_action( 'plugins_loaded', 'b2bcg_check_dependencies' );
function b2bcg_missing_wc_notice(): void {
echo '<div class="notice notice-error"><p>'
. esc_html__( 'B2B AI Content Generator requires WooCommerce to be installed and active.', 'b2b-content-gen' )
. '</p></div>';
}
function b2bcg_init(): void {
// Woocommere compatibility
add_action( 'before_woocommerce_init', function() {
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility(
'custom_order_tables',
B2BCG_PLUGIN_FILE,
true
);
}
} );
require_once B2BCG_PLUGIN_DIR . 'includes/class-b2bcg-settings.php';
require_once B2BCG_PLUGIN_DIR . 'includes/class-b2bcg-api-handler.php';
require_once B2BCG_PLUGIN_DIR . 'includes/class-b2bcg-prompt-builder.php';
require_once B2BCG_PLUGIN_DIR . 'includes/class-b2bcg-product-data.php';
require_once B2BCG_PLUGIN_DIR . 'admin/class-b2bcg-admin.php';
require_once B2BCG_PLUGIN_DIR . 'admin/class-b2bcg-ajax.php';
B2BCG_Settings::init();
B2BCG_Admin::init();
B2BCG_Ajax::init();
}
register_activation_hook( __FILE__, 'b2bcg_activate' );
function b2bcg_activate(): void {
if ( ! class_exists( 'WooCommerce' ) ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
wp_die( esc_html__( 'B2B AI Content Generator requires WooCommerce. Please install WooCommerce first.', 'b2b-content-gen' ) );
}
}