| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPAdminify\Inc\Admin; |
| 4 |
|
| 5 |
use WPAdminify\Inc\Utils; |
| 6 |
use WPAdminify\Inc\Admin\AdminSettingsModel; |
| 7 |
use WPAdminify\Inc\Admin\Options\Customize; |
| 8 |
use WPAdminify\Inc\Admin\Options\Productivity; |
| 9 |
use WPAdminify\Inc\Admin\Options\CustomCSSJS; |
| 10 |
use WPAdminify\Inc\Admin\Options\Performance; |
| 11 |
use WPAdminify\Inc\Admin\Options\MenuLayout; |
| 12 |
use WPAdminify\Inc\Admin\Options\Security; |
| 13 |
use WPAdminify\Inc\Admin\Options\White_Label; |
| 14 |
if ( !defined( 'ABSPATH' ) ) { |
| 15 |
die; |
| 16 |
} |
| 17 |
// Cannot access directly. |
| 18 |
if ( !class_exists( 'AdminSettings' ) ) { |
| 19 |
class AdminSettings extends AdminSettingsModel { |
| 20 |
// AdminSettings cannot be extended by creating instances |
| 21 |
public static $instance = null; |
| 22 |
|
| 23 |
public $defaults = []; |
| 24 |
|
| 25 |
private $message = []; |
| 26 |
|
| 27 |
public function __construct() { |
| 28 |
// this should be first so the default values get stored |
| 29 |
$this->jltwp_adminify_options(); |
| 30 |
parent::__construct( (array) get_option( $this->prefix ) ); |
| 31 |
add_action( 'network_admin_menu', [$this, 'network_panel'] ); |
| 32 |
} |
| 33 |
|
| 34 |
public function network_panel() { |
| 35 |
add_menu_page( |
| 36 |
$this->get_plugin_menu_label(), |
| 37 |
$this->get_plugin_menu_label(), |
| 38 |
'manage_options', |
| 39 |
'wp-adminify-settings', |
| 40 |
[$this, 'network_panel_display'], |
| 41 |
WP_ADMINIFY_ASSETS_IMAGE . 'logos/menu-icon.svg', |
| 42 |
30 |
| 43 |
); |
| 44 |
} |
| 45 |
|
| 46 |
public function get_bloginfo( $blog_id, $fields = [] ) { |
| 47 |
switch_to_blog( $blog_id ); |
| 48 |
$_fields = []; |
| 49 |
foreach ( $fields as $field ) { |
| 50 |
$_fields[$field] = get_bloginfo( $field ); |
| 51 |
} |
| 52 |
restore_current_blog(); |
| 53 |
return $_fields; |
| 54 |
} |
| 55 |
|
| 56 |
public function get_sites() { |
| 57 |
$sites = get_sites(); |
| 58 |
foreach ( $sites as $site ) { |
| 59 |
$info = $this->get_bloginfo( $site->blog_id, ['name'] ); |
| 60 |
$site->name = $info['name']; |
| 61 |
} |
| 62 |
return $sites; |
| 63 |
} |
| 64 |
|
| 65 |
public function get_sites_option_empty() { |
| 66 |
return sprintf( __( '<option value="%1$s">%2$s</option>', 'adminify' ), 0, __( 'Select', 'adminify' ) ); |
| 67 |
} |
| 68 |
|
| 69 |
public function get_sites_option( $sites = [], $add_empty_slot = false ) { |
| 70 |
if ( empty( $sites ) ) { |
| 71 |
$sites = $this->get_sites(); |
| 72 |
} |
| 73 |
$_sites = []; |
| 74 |
if ( $add_empty_slot ) { |
| 75 |
$_sites[] = $this->get_sites_option_empty(); |
| 76 |
} |
| 77 |
foreach ( $sites as $site ) { |
| 78 |
$_sites[] = sprintf( __( '<option value="%1$s">%2$s</option>', 'adminify' ), $site->blog_id, $site->name ); |
| 79 |
} |
| 80 |
return implode( '', $_sites ); |
| 81 |
} |
| 82 |
|
| 83 |
public function maybe_display_message() { |
| 84 |
if ( empty( $this->message ) ) { |
| 85 |
return; |
| 86 |
} |
| 87 |
$classes = 'adminify-status adminify-status--' . esc_attr( $this->message['type'] ); |
| 88 |
echo '<div class="' . esc_attr( $classes ) . '"><p>' . esc_html__( wp_kses_post( $this->message['message'] ), 'adminify' ); |
| 89 |
} |
| 90 |
|
| 91 |
public function network_panel_display() { |
| 92 |
$multisite_settings = sprintf( |
| 93 |
wp_kses_post( '<div class="%1$s"><h2>%2$s</h2> <a href="%3$s" target="_blank">%4$s</a></div>', 'adminify' ), |
| 94 |
Utils::upgrade_pro_class(), |
| 95 |
esc_html__( 'Network Settings', 'adminify' ), |
| 96 |
esc_url( 'https://wpadminify.com/pricing' ), |
| 97 |
Utils::adminify_upgrade_pro( 'Please Upgrade or Activate License' ) |
| 98 |
); |
| 99 |
// Initialize the multisite_settings variable |
| 100 |
$multisite_settings = apply_filters( 'adminify/admin_settings/network', $multisite_settings ); |
| 101 |
// Apply the filter |
| 102 |
echo $multisite_settings; |
| 103 |
} |
| 104 |
|
| 105 |
public function option_modules() { |
| 106 |
$extra_data_merge = []; |
| 107 |
$clonable_data = [ |
| 108 |
'_wpadminify' => __( 'WP Adminify Options', 'adminify' ), |
| 109 |
'_adminify_admin_columns_adminify_admin_page' => __( 'Admin Page Columns Data', 'adminify' ), |
| 110 |
]; |
| 111 |
// Activity Logs Active |
| 112 |
if ( Utils::is_plugin_active( 'adminify-activity-logs/adminify-activity-logs.php' ) ) { |
| 113 |
$extra_data_merge['adminify_activity_logs'] = __( 'Activity Logs Data', 'adminify' ); |
| 114 |
$clonable_data = array_merge( $clonable_data, $extra_data_merge ); |
| 115 |
} |
| 116 |
// Quick Circle Menu Active |
| 117 |
if ( Utils::is_plugin_active( 'adminify-quick-circle-menu/adminify-quick-circle-menu.php' ) ) { |
| 118 |
$extra_data_merge['_wpadminify_quick_circle_menu'] = __( 'Quick Circle Menu', 'adminify' ); |
| 119 |
$clonable_data = array_merge( $clonable_data, $extra_data_merge ); |
| 120 |
} |
| 121 |
// Google Pagespeed Active |
| 122 |
if ( Utils::is_plugin_active( 'adminify-google-pagespeed/adminify-google-pagespeed.php' ) ) { |
| 123 |
$extra_data_merge['adminify_page_speed'] = __( 'Google Pagespeed', 'adminify' ); |
| 124 |
$clonable_data = array_merge( $clonable_data, $extra_data_merge ); |
| 125 |
} |
| 126 |
// Login Customizer Active |
| 127 |
if ( Utils::is_plugin_active( 'loginfy/loginfy.php' ) ) { |
| 128 |
$extra_data_merge['jltwp_adminify_login'] = __( 'Loginify Data', 'adminify' ); |
| 129 |
$clonable_data = array_merge( $clonable_data, $extra_data_merge ); |
| 130 |
} |
| 131 |
// Header Footer Scripts Active |
| 132 |
if ( Utils::is_plugin_active( 'adminify-sidebar-generator/adminify-sidebar-generator.php' ) ) { |
| 133 |
$extra_data_merge['_wp_adminify_sidebar_settings'] = __( 'Sidebar Generator', 'adminify' ); |
| 134 |
$clonable_data = array_merge( $clonable_data, $extra_data_merge ); |
| 135 |
} |
| 136 |
// Sidebar Generator Active |
| 137 |
if ( Utils::is_plugin_active( 'adminify-header-footer-scripts/adminify-header-footer-scripts.php' ) ) { |
| 138 |
$extra_data_merge['_wpadminify_custom_js_css'] = __( 'Custom JS/CSS', 'adminify' ); |
| 139 |
$clonable_data = array_merge( $clonable_data, $extra_data_merge ); |
| 140 |
} |
| 141 |
// Admin Columns Active |
| 142 |
if ( Utils::is_plugin_active( 'adminify-admin-columns/adminify-admin-columns.php' ) ) { |
| 143 |
$extra_data_merge['_adminify_admin_columns_page'] = __( 'Admin Columns Page Data', 'adminify' ); |
| 144 |
$extra_data_merge['_adminify_admin_columns_post'] = __( 'Admin Columns Post Data', 'adminify' ); |
| 145 |
$clonable_data = array_merge( $clonable_data, $extra_data_merge ); |
| 146 |
} |
| 147 |
return (array) apply_filters( 'adminify_clone_blog_option_modules', $clonable_data ); |
| 148 |
} |
| 149 |
|
| 150 |
public function get_pagespeed_data( $copy_from ) { |
| 151 |
switch_to_blog( $copy_from ); |
| 152 |
global $wpdb; |
| 153 |
$table_name = $wpdb->prefix . 'adminify_page_speed'; |
| 154 |
$histories = $wpdb->get_results( "SELECT * FROM {$table_name}", ARRAY_A ); |
| 155 |
restore_current_blog(); |
| 156 |
return $histories; |
| 157 |
} |
| 158 |
|
| 159 |
public function clone_pagespeed_data( $histories, $copy_to ) { |
| 160 |
switch_to_blog( $copy_to ); |
| 161 |
global $wpdb; |
| 162 |
$table_name = $wpdb->prefix . 'adminify_page_speed'; |
| 163 |
foreach ( $histories as $history ) { |
| 164 |
unset($history['id']); |
| 165 |
$wpdb->insert( "{$table_name}", $history, [ |
| 166 |
'url' => '%s', |
| 167 |
'score_desktop' => '%d', |
| 168 |
'score_mobile' => '%d', |
| 169 |
'data_desktop' => '%s', |
| 170 |
'data_mobile' => '%s', |
| 171 |
'screenshot' => '%s', |
| 172 |
'time' => '%s', |
| 173 |
] ); |
| 174 |
} |
| 175 |
restore_current_blog(); |
| 176 |
} |
| 177 |
|
| 178 |
public function get_admin_columns_options( $copy_from ) { |
| 179 |
$options = []; |
| 180 |
switch_to_blog( $copy_from ); |
| 181 |
$args = [ |
| 182 |
'public' => true, |
| 183 |
]; |
| 184 |
$types = get_post_types( $args ); |
| 185 |
unset($types['attachment']); |
| 186 |
restore_current_blog(); |
| 187 |
foreach ( $types as $type ) { |
| 188 |
$options[] = '_adminify_admin_columns_meta_' . esc_attr( $type ); |
| 189 |
} |
| 190 |
return $options; |
| 191 |
} |
| 192 |
|
| 193 |
public static function get_instance() { |
| 194 |
if ( !is_null( self::$instance ) ) { |
| 195 |
return self::$instance; |
| 196 |
} |
| 197 |
self::$instance = new self(); |
| 198 |
return self::$instance; |
| 199 |
} |
| 200 |
|
| 201 |
protected function get_defaults() { |
| 202 |
return $this->defaults; |
| 203 |
} |
| 204 |
|
| 205 |
public static function get_pro_label() { |
| 206 |
$is_pro = ""; |
| 207 |
$is_pro = WP_ADMINIFY; |
| 208 |
return $is_pro; |
| 209 |
} |
| 210 |
|
| 211 |
public function get_plugin_menu_icon() { |
| 212 |
$menu_icon = WP_ADMINIFY_ASSETS_IMAGE . 'logos/menu-icon-light.svg'; |
| 213 |
$saved_data = get_option( $this->prefix ); |
| 214 |
if ( isset( $saved_data['white_label']['adminify']['menu_icon'] ) && !empty( $saved_data['white_label']['adminify']['menu_icon']['url'] ) ) { |
| 215 |
$menu_icon = $saved_data['white_label']['adminify']['menu_icon']['url']; |
| 216 |
} |
| 217 |
return $menu_icon; |
| 218 |
} |
| 219 |
|
| 220 |
public function get_plugin_menu_label() { |
| 221 |
$plugin_menu_label = self::get_pro_label(); |
| 222 |
$saved_data = get_option( $this->prefix ); |
| 223 |
if ( isset( $saved_data['white_label']['adminify']['menu_label'] ) && !empty( $saved_data['white_label']['adminify']['menu_label'] ) ) { |
| 224 |
$plugin_menu_label = $saved_data['white_label']['adminify']['menu_label']; |
| 225 |
} |
| 226 |
return $plugin_menu_label; |
| 227 |
} |
| 228 |
|
| 229 |
public static function support_url() { |
| 230 |
$support_url = ''; |
| 231 |
$support_url = 'https://wordpress.org/support/plugin/adminify/#new-topic-0'; |
| 232 |
return $support_url; |
| 233 |
} |
| 234 |
|
| 235 |
public function jltwp_adminify_options() { |
| 236 |
if ( !class_exists( 'ADMINIFY' ) ) { |
| 237 |
return; |
| 238 |
} |
| 239 |
$submenu_position = apply_filters( 'jltwp_adminify_submenu_position', 30 ); |
| 240 |
$saved_data = get_option( $this->prefix ); |
| 241 |
$global_admin_ui_mode = ( empty( $saved_data['light_dark_mode']['admin_ui_mode'] ) ? 'light' : sanitize_text_field( $saved_data['light_dark_mode']['admin_ui_mode'] ) ); |
| 242 |
$admin_ui_mode = ( empty( get_user_meta( get_current_user_id(), 'color_mode', true ) ) ? $global_admin_ui_mode : get_user_meta( get_current_user_id(), 'color_mode', true ) ); |
| 243 |
$light_logo_image_url = WP_ADMINIFY_ASSETS_IMAGE . 'logos/logo-text-light.svg'; |
| 244 |
$dark_logo_image_url = WP_ADMINIFY_ASSETS_IMAGE . 'logos/logo-text-dark.svg'; |
| 245 |
$plugin_author_name = WP_ADMINIFY_AUTHOR; |
| 246 |
// WP Adminify Options |
| 247 |
\ADMINIFY::createOptions( $this->prefix, [ |
| 248 |
'framework_title' => '<img class="wp-adminify-settings-logo adminify-settings-light-logo" src=' . esc_url( $light_logo_image_url ) . '><img class="wp-adminify-settings-logo adminify-settings-dark-logo" src=' . esc_url( $dark_logo_image_url ) . '>' . ' <small>by ' . esc_html( $plugin_author_name ) . '</small>', |
| 249 |
'framework_class' => '', |
| 250 |
'menu_title' => $this->get_plugin_menu_label(), |
| 251 |
'menu_slug' => 'wp-adminify-settings', |
| 252 |
'menu_capability' => 'manage_options', |
| 253 |
'menu_icon' => $this->get_plugin_menu_icon(), |
| 254 |
'menu_position' => 30, |
| 255 |
'menu_hidden' => false, |
| 256 |
'menu_parent' => 'admin.php?page=wp-adminify-settings', |
| 257 |
'show_bar_menu' => true, |
| 258 |
'show_sub_menu' => false, |
| 259 |
'show_in_network' => false, |
| 260 |
'show_in_customizer' => false, |
| 261 |
'show_search' => false, |
| 262 |
'show_reset_all' => true, |
| 263 |
'show_reset_section' => true, |
| 264 |
'show_footer' => true, |
| 265 |
'show_all_options' => false, |
| 266 |
'show_form_warning' => true, |
| 267 |
'sticky_header' => false, |
| 268 |
'save_defaults' => false, |
| 269 |
'ajax_save' => true, |
| 270 |
'admin_bar_menu_icon' => '', |
| 271 |
'admin_bar_menu_priority' => 80, |
| 272 |
'footer_text' => ' ', |
| 273 |
'footer_after' => ' ', |
| 274 |
'footer_credit' => ' ', |
| 275 |
'database' => 'options', |
| 276 |
'transient_time' => 0, |
| 277 |
'contextual_help' => [], |
| 278 |
'contextual_help_sidebar' => '', |
| 279 |
'enqueue_webfont' => true, |
| 280 |
'async_webfont' => false, |
| 281 |
'output_css' => true, |
| 282 |
'nav' => 'normal', |
| 283 |
'has_nav' => false, |
| 284 |
'theme' => 'dark', |
| 285 |
'class' => 'wp-adminify-settings', |
| 286 |
'defaults' => [], |
| 287 |
] ); |
| 288 |
$this->defaults = array_merge( $this->defaults, ( new Customize() )->get_defaults() ); |
| 289 |
$this->defaults = array_merge( $this->defaults, ( new MenuLayout() )->get_defaults() ); |
| 290 |
$this->defaults = array_merge( $this->defaults, ( new Productivity() )->get_defaults() ); |
| 291 |
$this->defaults = array_merge( $this->defaults, ( new Security() )->get_defaults() ); |
| 292 |
$this->defaults = array_merge( $this->defaults, ( new Performance() )->get_defaults() ); |
| 293 |
$this->defaults = array_merge( $this->defaults, ( new CustomCSSJS() )->get_defaults() ); |
| 294 |
$this->defaults = array_merge( $this->defaults, ( new White_Label() )->get_defaults() ); |
| 295 |
// Fix Missing keys on save |
| 296 |
add_filter( "adminify_{$this->prefix}_save", function ( $data ) { |
| 297 |
$data = $this->fix_missing_keys( $this->defaults, $data ); |
| 298 |
return $data; |
| 299 |
} ); |
| 300 |
// Backup Settings |
| 301 |
\ADMINIFY::createSection( $this->prefix, [ |
| 302 |
'title' => __( 'Backup', 'adminify' ), |
| 303 |
'icon' => 'fas fa-database', |
| 304 |
'fields' => [[ |
| 305 |
'type' => 'subheading', |
| 306 |
'content' => Utils::adminfiy_help_urls( |
| 307 |
__( 'Backup Config Settings', 'adminify' ), |
| 308 |
'https://wpadminify.com/docs/adminify/export-import/backup', |
| 309 |
'https://www.youtube.com/playlist?list=PLqpMw0NsHXV-EKj9Xm1DMGa6FGniHHly8', |
| 310 |
'https://www.facebook.com/groups/jeweltheme', |
| 311 |
self::support_url() |
| 312 |
), |
| 313 |
], [ |
| 314 |
'type' => 'backup', |
| 315 |
'class' => 'adminify-block', |
| 316 |
]], |
| 317 |
] ); |
| 318 |
} |
| 319 |
|
| 320 |
function fix_missing_keys( $defaults, $data ) { |
| 321 |
if ( is_array( $defaults ) ) { |
| 322 |
foreach ( $defaults as $key => $value ) { |
| 323 |
if ( is_array( $value ) ) { |
| 324 |
if ( !isset( $data[$key] ) || gettype( $data[$key] ) !== 'array' ) { |
| 325 |
$data[$key] = []; |
| 326 |
} |
| 327 |
$data[$key] = $this->fix_missing_keys( $value, $data[$key] ); |
| 328 |
} |
| 329 |
} |
| 330 |
} |
| 331 |
return $data; |
| 332 |
} |
| 333 |
|
| 334 |
public function get_prefix() { |
| 335 |
return $this->prefix; |
| 336 |
} |
| 337 |
|
| 338 |
} |
| 339 |
|
| 340 |
} |