-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontrol-listings.php
More file actions
117 lines (98 loc) · 3.03 KB
/
Copy pathcontrol-listings.php
File metadata and controls
117 lines (98 loc) · 3.03 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
<?php
/*
Plugin Name: Control Listings - Classifieds Ads Directory Portal Manager
Plugin URI: https://controllistings.com
Description: Classifieds ads directory portal manager
Author: Themeperch
Version: 1.0.7
Author URI: https://themeperch.net/
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
Text Domain: control-listings
*/
// Exit if accessed directly.
defined( 'ABSPATH' ) || die;
if( defined('CTRL_LISTINGS_VER') ) return;
class Control_Listings_Init{
public function __construct() {
$this->constants();
// Activate
register_activation_hook( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ), [ $this, 'activate' ] );
add_action('wpmu_new_blog', [$this, 'install_for_new_blog'], 10, 1 );
// Set up startup actions
add_action( 'init', [$this, 'init'], 1 );
}
private function constants(){
define( 'CTRL_LISTINGS_URI', trailingslashit(plugin_dir_url( __FILE__ )) );
define( 'CTRL_LISTINGS_VER', '1.0.7' );
define( 'CTRL_LISTINGS_ASSETS', trailingslashit(CTRL_LISTINGS_URI.'assets') );
define( 'CTRL_LISTINGS_DIR', trailingslashit(plugin_dir_path( __FILE__ )) );
define( 'CTRL_LISTINGS_TEMPLATEPATH', trailingslashit(plugin_dir_path( __FILE__ ).'views') );
}
public function init() {
if ( ! defined( 'RWMB_VER' ) ) {
require __DIR__ . '/vendor/wpmetabox/meta-box/meta-box.php';
}
require __DIR__ . '/vendor/autoload.php';
new ControlListings\Loader;
}
/**
* Install when a new site is added to a network
*
* @param $blog_id
*/
public function install_for_new_blog( $blog_id ) {
if( is_plugin_active_for_network( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ) ) ) {
switch_to_blog( $blog_id );
$this->install();
restore_current_blog();
}
}
/**
* Install plugin for all sites in a multi-site environment when network activated
*
* @param $network_wide
*/
public function activate( $network_wide ) {
if( is_multisite() && $network_wide ) {
global $wpdb;
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
foreach( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ) as $blog_id ) {
switch_to_blog( $blog_id );
$this->install();
restore_current_blog();
}
} else {
$this->install();
}
}
/**
* Install
*/
public function install() {
global $wpdb;
$wpdb->hide_errors();
$collate = '';
if ( $wpdb->has_cap( 'collation' ) ) {
if( ! empty( $wpdb->charset ) ) {
$collate .= "DEFAULT CHARACTER SET $wpdb->charset";
}
if( ! empty( $wpdb->collate ) ) {
$collate .= " COLLATE $wpdb->collate";
}
}
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
$sql = "
CREATE TABLE {$wpdb->prefix}control_listings_bookmarks (
id bigint(20) NOT NULL auto_increment,
user_id bigint(20) NOT NULL,
post_id bigint(20) NOT NULL,
bookmark_note longtext NULL,
date_created datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (id)
) $collate;
";
dbDelta( $sql );
}
}
new Control_Listings_Init();