| 1 |
<?php |
| 2 |
/** |
| 3 |
* wp-init.php |
| 4 |
* |
| 5 |
* Copyright (c) "kento" Karim Rahimpur www.itthinx.com |
| 6 |
* |
| 7 |
* This code is released under the GNU General Public License. |
| 8 |
* See COPYRIGHT.txt and LICENSE.txt. |
| 9 |
* |
| 10 |
* This code is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* This header and all notices must be kept intact. |
| 16 |
* |
| 17 |
* @author Karim Rahimpur |
| 18 |
* @package groups |
| 19 |
* @since groups 1.0.0 |
| 20 |
*/ |
| 21 |
|
| 22 |
if ( !defined( 'ABSPATH' ) ) { |
| 23 |
exit; |
| 24 |
} |
| 25 |
|
| 26 |
// startup |
| 27 |
global $groups_version, $groups_admin_messages; |
| 28 |
|
| 29 |
if ( !isset( $groups_admin_messages ) ) { |
| 30 |
$groups_admin_messages = array(); |
| 31 |
} |
| 32 |
|
| 33 |
if ( !isset( $groups_version ) ) { |
| 34 |
$groups_version = GROUPS_CORE_VERSION; |
| 35 |
} |
| 36 |
|
| 37 |
// <= 3.2.1 |
| 38 |
if ( !function_exists( 'is_user_member_of_blog' ) ) { |
| 39 |
function is_user_member_of_blog( $user_id, $blog_id = 0 ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 40 |
return false !== get_user_by( 'id', $user_id ); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Load core : |
| 46 |
*/ |
| 47 |
|
| 48 |
require_once GROUPS_VIEWS_LIB . '/class-groups-log.php'; |
| 49 |
|
| 50 |
require_once GROUPS_CORE_LIB . '/class-groups-lock.php'; |
| 51 |
require_once GROUPS_CORE_LIB . '/class-groups-lock-exception.php'; |
| 52 |
|
| 53 |
require_once GROUPS_CORE_LIB . '/class-groups-cache.php'; |
| 54 |
require_once GROUPS_CORE_LIB . '/class-groups-cache-object.php'; |
| 55 |
|
| 56 |
require_once GROUPS_CORE_LIB . '/class-groups-utility.php'; |
| 57 |
|
| 58 |
// options |
| 59 |
require_once GROUPS_CORE_LIB . '/class-groups-options.php'; |
| 60 |
|
| 61 |
// plugin control: activation, deactivation, ... |
| 62 |
require_once GROUPS_CORE_LIB . '/class-groups-controller.php'; |
| 63 |
|
| 64 |
// legacy enabled? |
| 65 |
$groups_legacy_enable = Groups_Options::get_option( GROUPS_LEGACY_ENABLE, GROUPS_LEGACY_ENABLE_DEFAULT ); |
| 66 |
|
| 67 |
// admin |
| 68 |
if ( is_admin() ) { |
| 69 |
require_once GROUPS_ADMIN_LIB . '/class-groups-admin.php'; |
| 70 |
require_once GROUPS_ADMIN_LIB . '/class-groups-admin-welcome.php'; |
| 71 |
if ( Groups_Options::get_option( GROUPS_SHOW_IN_USER_PROFILE, GROUPS_SHOW_IN_USER_PROFILE_DEFAULT ) ) { |
| 72 |
require_once GROUPS_ADMIN_LIB . '/class-groups-admin-user-profile.php'; |
| 73 |
} |
| 74 |
require_once GROUPS_ADMIN_LIB . '/class-groups-admin-users.php'; |
| 75 |
require_once GROUPS_ADMIN_LIB . '/class-groups-admin-posts.php'; |
| 76 |
require_once GROUPS_ADMIN_LIB . '/class-groups-admin-post-columns.php'; |
| 77 |
if ( $groups_legacy_enable ) { |
| 78 |
require_once GROUPS_ADMIN_LIB . '/class-groups-admin-deprecation-notice.php'; // @since 4.2.0 |
| 79 |
require_once GROUPS_LEGACY_LIB . '/admin/class-groups-admin-posts-legacy.php'; |
| 80 |
require_once GROUPS_LEGACY_LIB . '/admin/class-groups-admin-post-columns-legacy.php'; |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
// help |
| 85 |
if ( is_admin() ) { |
| 86 |
require_once GROUPS_CORE_LIB . '/class-groups-help.php'; |
| 87 |
} |
| 88 |
|
| 89 |
require_once GROUPS_CORE_LIB . '/class-groups-capability.php'; |
| 90 |
require_once GROUPS_CORE_LIB . '/class-groups-group.php'; |
| 91 |
require_once GROUPS_CORE_LIB . '/class-groups-group-capability.php'; |
| 92 |
require_once GROUPS_CORE_LIB . '/class-groups-user.php'; |
| 93 |
require_once GROUPS_CORE_LIB . '/class-groups-user-capability.php'; |
| 94 |
require_once GROUPS_CORE_LIB . '/class-groups-user-group.php'; |
| 95 |
|
| 96 |
/** |
| 97 |
* Load auto : |
| 98 |
*/ |
| 99 |
|
| 100 |
require_once GROUPS_AUTO_LIB . '/class-groups-registered.php'; |
| 101 |
|
| 102 |
/** |
| 103 |
* Load access : |
| 104 |
*/ |
| 105 |
|
| 106 |
require_once GROUPS_ACCESS_LIB . '/class-groups-post-access.php'; |
| 107 |
if ( $groups_legacy_enable ) { |
| 108 |
require_once GROUPS_LEGACY_LIB . '/access/class-groups-post-access-legacy.php'; |
| 109 |
} |
| 110 |
require_once GROUPS_ACCESS_LIB . '/class-groups-comment-access.php'; |
| 111 |
|
| 112 |
if ( is_admin() ) { |
| 113 |
require_once GROUPS_ACCESS_LIB . '/class-groups-access-meta-boxes.php'; |
| 114 |
if ( $groups_legacy_enable ) { |
| 115 |
require_once GROUPS_LEGACY_LIB . '/access/class-groups-access-meta-boxes-legacy.php'; |
| 116 |
} |
| 117 |
} |
| 118 |
require_once GROUPS_ACCESS_LIB . '/class-groups-access-shortcodes.php'; |
| 119 |
require_once GROUPS_VIEWS_LIB . '/class-groups-shortcodes.php'; |
| 120 |
|
| 121 |
/** |
| 122 |
* Load wp : |
| 123 |
*/ |
| 124 |
require_once GROUPS_WP_LIB . '/class-groups-wordpress.php'; |
| 125 |
|
| 126 |
/** |
| 127 |
* Load blocks : |
| 128 |
*/ |
| 129 |
require_once GROUPS_BLOCKS_LIB . '/src/class-groups-blocks.php'; |
| 130 |
|
| 131 |
/** |
| 132 |
* Extras ... |
| 133 |
*/ |
| 134 |
require_once GROUPS_EXTRA_LIB . '/class-groups-extra.php'; |
| 135 |
|
| 136 |
// @since 4.0.0 |
| 137 |
require_once GROUPS_CORE_LIB . '/class-groups-cache-robot.php'; |
| 138 |
|
| 139 |
// widgets |
| 140 |
// include_once GROUPS_CORE_LIB . '/class-groups-widgets.php'; |
| 141 |
// add_action( 'widgets_init', 'groups_widgets_init' ); |
| 142 |
|
| 143 |
/** |
| 144 |
* Register widgets |
| 145 |
*/ |
| 146 |
// function groups_widgets_init() { |
| 147 |
// register_widget( 'Groups_Widget' ); |
| 148 |
// } |
| 149 |
|
| 150 |
/** |
| 151 |
* Returns the prefixed DB table name. |
| 152 |
* |
| 153 |
* @param string $name the name of the DB table |
| 154 |
* |
| 155 |
* @return string prefixed DB table name |
| 156 |
*/ |
| 157 |
function _groups_get_tablename( $name ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 158 |
global $wpdb; |
| 159 |
|
| 160 |
/** |
| 161 |
* Filters the prefix of the database table to query. |
| 162 |
* |
| 163 |
* @since 2.11.0 |
| 164 |
* |
| 165 |
* @param str $wpdb->prefix The current WordPress table prefix. Allowed characters are a-z, A-Z, 0-9, the dash - and the underscore _. |
| 166 |
* |
| 167 |
* @return str The possibly-modified table prefix. |
| 168 |
*/ |
| 169 |
$prefix = apply_filters( 'groups_get_table_prefix', $wpdb->prefix ); |
| 170 |
|
| 171 |
if ( is_string( $prefix ) ) { |
| 172 |
$prefix = preg_replace( '/[^a-zA-Z0-9-_]+/', '', $prefix ); |
| 173 |
} |
| 174 |
|
| 175 |
// use the default if the filter returned nonsense or null due to error |
| 176 |
if ( !is_string( $prefix ) ) { |
| 177 |
$prefix = $wpdb->prefix; |
| 178 |
} |
| 179 |
|
| 180 |
// Return the constructed table name. |
| 181 |
return $prefix . GROUPS_TP . $name; |
| 182 |
} |
| 183 |
|
| 184 |
/** |
| 185 |
* This returns true if admin override is enabled and the current user |
| 186 |
* is an administrator, otherwise false. |
| 187 |
* To enable admin override (AKA god mode for admins), add this to |
| 188 |
* your wp-config.php : |
| 189 |
* |
| 190 |
* define( 'GROUPS_ADMINISTRATOR_OVERRIDE', true ); |
| 191 |
* |
| 192 |
* Enabling this is NOT recommended for production sites. |
| 193 |
* |
| 194 |
* @param int $user_id indicate the user ID or omit to check for the current user |
| 195 |
* |
| 196 |
* @return boolean |
| 197 |
*/ |
| 198 |
function _groups_admin_override( $user_id = null ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound |
| 199 |
$result = false; |
| 200 |
if ( ( $user_id === null ) && function_exists( 'get_current_user_id' ) ) { |
| 201 |
$user_id = get_current_user_id(); |
| 202 |
} |
| 203 |
if ( $user_id ) { |
| 204 |
if ( defined( 'GROUPS_ADMINISTRATOR_OVERRIDE' ) && ( GROUPS_ADMINISTRATOR_OVERRIDE === true ) ) { |
| 205 |
// @since 3.1.0 user_can() relies on get_userdata() which is defined in wp-includes/pluggable.php |
| 206 |
if ( function_exists( 'user_can' ) && function_exists( 'get_userdata' ) ) { |
| 207 |
if ( user_can( $user_id, 'administrator' ) ) { |
| 208 |
$result = true; |
| 209 |
} |
| 210 |
} |
| 211 |
} |
| 212 |
} |
| 213 |
return $result; |
| 214 |
} |
| 215 |
|