-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathetsy-plugin.php
More file actions
104 lines (93 loc) · 2.67 KB
/
Copy pathetsy-plugin.php
File metadata and controls
104 lines (93 loc) · 2.67 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
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
<?php
/**
* Plugin Name: Etsy
* Plugin URI: https://plugindevsite.local
* Description: Websites for Etsy sellers
* Version: 1.0.0
* Author: Your Name
* Text Domain: etsy-shop-inventory
* License: GPL v2 or later
*/
// Exit if accessed directly
if (!defined('ABSPATH')) {
exit;
}
// Define plugin constants
define('ETSY_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('ETSY_PLUGIN_URL', plugin_dir_url(__FILE__));
/**
* Initialize the plugin
*/
function etsy_plugin_init() {
// Include post types
require_once ETSY_PLUGIN_DIR . 'includes/post-types.php';
// Include shortcodes
require_once ETSY_PLUGIN_DIR . 'includes/shortcodes.php';
// Include admin files if in admin area
if (is_admin()) {
require_once ETSY_PLUGIN_DIR . 'admin/main.php';
}
}
add_action('init', 'etsy_plugin_init');
/**
* Register styles and scripts
*/
function etsy_enqueue_scripts() {
// Enqueue frontend styles
wp_enqueue_style(
'etsywp-frontend-styles',
ETSY_PLUGIN_URL . 'assets/css/frontend-styles.css',
array(),
filemtime(ETSY_PLUGIN_DIR . 'assets/css/frontend-styles.css')
);
}
add_action('wp_enqueue_scripts', 'etsy_enqueue_scripts');
/**
* Register admin menu
*/
function etsy_register_admin_menu() {
// Add a single Etsy menu item
add_menu_page(
'Etsy',
'Etsy',
'manage_options',
'etsy-shop',
'etsy_admin_page',
'dashicons-store',
30
);
}
add_action('admin_menu', 'etsy_register_admin_menu');
/**
* Create 'Best Sellers' page on plugin activation
*/
function etsy_create_best_sellers_page() {
$page_title = 'Best Sellers';
$page_content = '[etsywp_best_sellers]'; // Placeholder for shortcode or content
$page_check = get_page_by_title($page_title);
if (!isset($page_check->ID)) {
$new_page = array(
'post_title' => $page_title,
'post_content' => $page_content,
'post_status' => 'publish',
'post_type' => 'page',
);
wp_insert_post($new_page);
}
}
function etsy_create_shop_all_page() {
$page_title = 'Shop All';
$page_content = '[etsywp_shop_all]'; // Placeholder for shortcode or content
$page_check = get_page_by_title($page_title);
if (!isset($page_check->ID)) {
$new_page = array(
'post_title' => $page_title,
'post_content' => $page_content,
'post_status' => 'publish',
'post_type' => 'page',
);
wp_insert_post($new_page);
}
}
register_activation_hook(__FILE__, 'etsy_create_best_sellers_page');
register_activation_hook(__FILE__, 'etsy_create_shop_all_page');