-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstarter-pack.php
More file actions
123 lines (100 loc) · 3.12 KB
/
Copy pathstarter-pack.php
File metadata and controls
123 lines (100 loc) · 3.12 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
/*
Plugin Name: Starter Pack
Plugin URI:
Description: A WordPress plugin to jumpstart devving on any WordPress site
Author: Chad O'Brien
Author URI: https://github.com/csobrien90
Version: 1.0
Text Domain: plugin-starter-pack
License: GPL v3
Requires PHP: 7.2
License URI: http://www.gnu.org/licenses/gpl-3.0.html
Copyright(C) 2022, Chad O'Brien - obrien.music@gmail.com
*/
require_once 'functions.php';
function starter_pack_activate() {
if ( !current_user_can('activate_plugins') ) return;
// Create testing page
global $wpdb;
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
if ( null === $wpdb->get_row( "SELECT post_name FROM {$wpdb->prefix}posts WHERE post_name = 'dev-testing-ground'", 'ARRAY_A' ) ) {
$current_user = wp_get_current_user();
// create post object
$page = array(
'post_title' => 'Dev Testing Ground',
'post_status' => 'publish',
'post_author' => $current_user->ID,
'post_type' => 'page',
'post_content' => ''
);
// insert the post into the database
$dev_testing_ground_post_id = wp_insert_post( $page );
}
if ( null === $wpdb->get_row( "SELECT post_name FROM {$wpdb->prefix}posts WHERE post_name = 'login-sub'", 'ARRAY_A' ) ) {
$current_user = wp_get_current_user();
// create post object
$page = array(
'post_title' => 'SP Login',
'post_name' => 'login-sub',
'post_status' => 'publish',
'post_author' => $current_user->ID,
'post_type' => 'page',
'post_content' => ''
);
// insert the post into the database
$login_sub_post_id = wp_insert_post( $page );
}
// Set default options
update_option( 'sp_dev_testing_ground_page_id', $dev_testing_ground_post_id );
update_option( 'sp_login_page_id', $login_sub_post_id );
update_option( 'sp_login_slug', 'login-sub' );
}
register_activation_hook(__FILE__, 'starter_pack_activate');
function starter_pack_deactivate() {
// Remove plugin pages
wp_delete_post( get_option( 'sp_dev_testing_ground_page_id' ), 1 );
wp_delete_post( get_option( 'sp_login_page_id' ), 1 );
// Remove settings options
$settings_options = [
'sp_dev_testing_ground_page_id',
'sp_login_page_id',
'sp_login_slug',
'sp_login_redirect',
'sp_custom_redirect',
'sp_allowed_mime_types',
'sp_security_settings',
'sp_enqueue_settings',
];
foreach ( $settings_options as $option ) {
delete_option( $option );
}
}
register_deactivation_hook(__FILE__, 'starter_pack_deactivate');
function starter_pack_admin() {
require_once 'content/page-admin.php';
}
function add_starter_pack_dashboard_menu_item() {
add_menu_page(
'Starter Pack',
'Starter Pack',
'manage_options',
'starter-pack-admin',
'starter_pack_admin',
'dashicons-laptop',
6
);
}
add_action( 'admin_menu', 'add_starter_pack_dashboard_menu_item', 999 );
function load_sp_first()
{
$path = str_replace( WP_PLUGIN_DIR . '/', '', __FILE__ );
if ( $plugins = get_option( 'active_plugins' ) ) {
if ( $key = array_search( $path, $plugins ) ) {
array_splice( $plugins, $key, 1 );
array_unshift( $plugins, $path );
update_option( 'active_plugins', $plugins );
}
}
}
add_action( 'activated_plugin', 'load_sp_first' );