| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPAdminify\Inc\Classes; |
| 4 |
|
| 5 |
use WPAdminify\Inc\Utils; |
| 6 |
use WPAdminify\Inc\Admin\AdminSettings; |
| 7 |
use WPAdminify\Inc\Modules\MenuEditor\MenuEditorOptions; |
| 8 |
// no direct access allowed |
| 9 |
if ( !defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
/** |
| 13 |
* WPAdminify |
| 14 |
* Third Party Plugins Compatibility |
| 15 |
* |
| 16 |
* @author Jewel Theme <support@jeweltheme.com> |
| 17 |
*/ |
| 18 |
class ThirdPartyCompatibility { |
| 19 |
public $menu_settings; |
| 20 |
|
| 21 |
public function __construct() { |
| 22 |
$this->menu_settings = ( new MenuEditorOptions() )->get(); |
| 23 |
add_action( 'init', [$this, 'register_actions_on_init'], 0 ); |
| 24 |
add_action( 'admin_init', [$this, 'register_actions_on_admin_init'], 0 ); |
| 25 |
// 24-3-24 |
| 26 |
add_action( 'admin_enqueue_scripts', [$this, 'jltwp_adminify_reset_theme_conflicts'], 999999 ); |
| 27 |
// 28-6-24 |
| 28 |
add_action( 'admin_head', [$this, 'jltwp_adminify_plugin_conflicts'], 999999 ); |
| 29 |
} |
| 30 |
|
| 31 |
public function jltwp_adminify_plugin_conflicts() { |
| 32 |
$adminify_ui = AdminSettings::get_instance()->get( 'admin_ui' ); |
| 33 |
if ( !empty( $adminify_ui ) ) { |
| 34 |
// Motopress Hotel Booking Lite |
| 35 |
if ( Utils::is_plugin_active( 'motopress-hotel-booking-lite/motopress-hotel-booking.php' ) ) { |
| 36 |
echo '<style> |
| 37 |
.wp-adminify.bookings_page_mphb_calendar .widefat thead th, |
| 38 |
.wp-adminify.bookings_page_mphb_calendar .widefat tfoot th, |
| 39 |
.wp-adminify.bookings_page_mphb_calendar .widefat tbody td { |
| 40 |
padding: 0 !important; |
| 41 |
} |
| 42 |
.adminify-ui .widefat tbody tr td:first-child { |
| 43 |
border-left-color: inherit !important; |
| 44 |
} |
| 45 |
</style>'; |
| 46 |
} |
| 47 |
} |
| 48 |
if ( Utils::is_plugin_active( 'squirrly-seo/squirrly.php' ) ) { |
| 49 |
echo '<style> |
| 50 |
.wp-adminify.adminify-ui.block-editor-page .interface-interface-skeleton { |
| 51 |
top: 0 !important; |
| 52 |
} |
| 53 |
</style>'; |
| 54 |
} |
| 55 |
if ( Utils::is_plugin_active( 'advanced-database-cleaner-pro/advanced-db-cleaner.php' ) ) { |
| 56 |
echo '<style> |
| 57 |
.wp-adminify.toplevel_page_advanced_db_cleaner #wpbody-content .wp-list-table.widefat td{ |
| 58 |
padding: 10px 10px; |
| 59 |
} |
| 60 |
.wp-adminify.toplevel_page_advanced_db_cleaner #wpbody-content input#aDBc_keep_button_revision { |
| 61 |
padding: 0px 3px !important; |
| 62 |
line-height: inherit !important; |
| 63 |
} |
| 64 |
</style>'; |
| 65 |
} |
| 66 |
if ( Utils::is_plugin_active( 'advanced-access-manager/aam.php' ) ) { |
| 67 |
add_filter( |
| 68 |
'jltwp_adminify_menu_option_compatibility_filter', |
| 69 |
array($this, 'apply_menu_restrictions_via_filter'), |
| 70 |
10, |
| 71 |
2 |
| 72 |
); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
public function apply_menu_restrictions_via_filter( $menu_options, $menu ) { |
| 77 |
$aam_options = get_option( 'aam_access_settings', [] ); |
| 78 |
if ( is_array( $aam_options ) ) { |
| 79 |
$simplified_aam_option = $this->simplify_aam_menu_restriction( $aam_options ); |
| 80 |
$menu_options = $this->update_aam_menu_option( $menu_options, $simplified_aam_option ); |
| 81 |
} |
| 82 |
return $menu_options; |
| 83 |
} |
| 84 |
|
| 85 |
public function simplify_aam_menu_restriction( $aam_option ) { |
| 86 |
$simplified_aam_option = []; |
| 87 |
foreach ( $aam_option['role'] as $role => $aam_role ) { |
| 88 |
if ( !empty( $aam_role['menu'] ) ) { |
| 89 |
foreach ( $aam_role['menu'] as $menu_item => $value ) { |
| 90 |
if ( !$value ) { |
| 91 |
continue; |
| 92 |
} |
| 93 |
$menu_item = str_replace( 'menu-', '', $menu_item ); |
| 94 |
if ( !isset( $simplified_aam_option[$menu_item] ) ) { |
| 95 |
$simplified_aam_option[$menu_item] = []; |
| 96 |
} |
| 97 |
$simplified_aam_option[$menu_item][] = $role; |
| 98 |
} |
| 99 |
} |
| 100 |
} |
| 101 |
return $simplified_aam_option; |
| 102 |
} |
| 103 |
|
| 104 |
public function update_aam_menu_option( $menu_options, $simplified_aam_option ) { |
| 105 |
foreach ( $menu_options as $key => $item ) { |
| 106 |
// If this menu item is in restricted list, update hidden_for |
| 107 |
if ( isset( $simplified_aam_option[$key] ) ) { |
| 108 |
if ( !isset( $item['hidden_for'] ) ) { |
| 109 |
$item['hidden_for'] = []; |
| 110 |
} |
| 111 |
$item['hidden_for'] = array_merge( $item['hidden_for'], $simplified_aam_option[$key] ); |
| 112 |
$item['hidden_for'] = array_unique( $item['hidden_for'] ); |
| 113 |
} |
| 114 |
// If submenu exists, apply the function recursively |
| 115 |
// if (isset($item['submenu']) && is_array($item['submenu'])) { |
| 116 |
// $item['submenu'] = update_aam_menu_option($item['submenu'], $simplified_aam_option); |
| 117 |
// } |
| 118 |
$menu_options[$key] = $item; |
| 119 |
} |
| 120 |
return $menu_options; |
| 121 |
} |
| 122 |
|
| 123 |
public function jltwp_adminify_reset_theme_conflicts() { |
| 124 |
global $pagenow; |
| 125 |
if ( $pagenow == 'wp-login.php' || $pagenow == 'wp-register.php' || $pagenow == 'customize.php' ) { |
| 126 |
return; |
| 127 |
} |
| 128 |
$theme = wp_get_theme(); |
| 129 |
// Neve WordPress Theme |
| 130 |
if ( 'Neve' == $theme->name || 'Neve' == $theme->parent_theme ) { |
| 131 |
wp_enqueue_style( |
| 132 |
'wp-adminify_neve-theme', |
| 133 |
WP_ADMINIFY_ASSETS . 'css/themes/neve.min.css', |
| 134 |
false, |
| 135 |
WP_ADMINIFY_VER |
| 136 |
); |
| 137 |
} |
| 138 |
// Phlox WordPress Theme |
| 139 |
if ( 'Phlox' == $theme->name || 'Phlox' == $theme->parent_theme ) { |
| 140 |
echo '<style> |
| 141 |
.wp-adminify.adminify-ui #wpcontent .wp-adminify.adminify-top_bar { |
| 142 |
opacity: 1 !important; |
| 143 |
} |
| 144 |
</style>'; |
| 145 |
} |
| 146 |
// Enfold WordPress Theme |
| 147 |
if ( 'Enfold' == $theme->name || 'Enfold' == $theme->parent_theme ) { |
| 148 |
echo '<style> |
| 149 |
.wp-adminify.avia-advanced-editor-enabled #wpadminbar{ |
| 150 |
display: none !important; |
| 151 |
} |
| 152 |
</style>'; |
| 153 |
} |
| 154 |
// Third Party Plugin CSS Conflict |
| 155 |
// $jltwp_adminify_plugin_conflict_css = ''; |
| 156 |
// if (Utils::is_plugin_active('quillforms/quillforms.php')) { |
| 157 |
// $jltwp_adminify_plugin_conflict_css = '//css code here'; |
| 158 |
// $jltwp_adminify_plugin_conflict_css = preg_replace('#/\*.*?\*/#s', '', $jltwp_adminify_plugin_conflict_css); |
| 159 |
// $jltwp_adminify_plugin_conflict_css = preg_replace('/\s*([{}|:;,])\s+/', '$1', $jltwp_adminify_plugin_conflict_css); |
| 160 |
// $jltwp_adminify_plugin_conflict_css = preg_replace('/\s\s+(.*)/', '$1', $jltwp_adminify_plugin_conflict_css); |
| 161 |
// } |
| 162 |
// $adminify_ui = AdminSettings::get_instance()->get('admin_ui'); |
| 163 |
// if (!empty($adminify_ui)) { |
| 164 |
// wp_add_inline_style('wp-adminify-admin', wp_strip_all_tags($jltwp_adminify_plugin_conflict_css)); |
| 165 |
// } else { |
| 166 |
// wp_add_inline_style('wp-adminify-default-ui', wp_strip_all_tags($jltwp_adminify_plugin_conflict_css)); |
| 167 |
// } |
| 168 |
if ( Utils::is_plugin_active( 'stackable-ultimate-gutenberg-blocks-premium/plugin.php' ) ) { |
| 169 |
echo '<style> |
| 170 |
.wp-adminify.adminify-ui #wpcontent .wp-adminify.adminify-top_bar { |
| 171 |
opacity: 1 !important; |
| 172 |
} |
| 173 |
</style>'; |
| 174 |
} |
| 175 |
if ( Utils::is_plugin_active( 'woocommerce/woocommerce.php' ) ) { |
| 176 |
echo '<style> |
| 177 |
.adminify-ui #woocommerce-embedded-root .woocommerce-layout__header { |
| 178 |
width: 100%; |
| 179 |
top: 0; |
| 180 |
} |
| 181 |
.adminify-ui #woocommerce-embedded-root .woocommerce-layout__header .woocommerce-layout__header-wrapper { |
| 182 |
margin-right: 1rem; |
| 183 |
} |
| 184 |
body.woocommerce-page #wpwrap #wpcontent, |
| 185 |
body.woocommerce-page.woocommerce_page_wc-admin #wpwrap #wpbody-content { |
| 186 |
overflow-x: unset !important; |
| 187 |
position: unset !important; |
| 188 |
} |
| 189 |
</style>'; |
| 190 |
} |
| 191 |
if ( Utils::is_plugin_active( 'tinymce-templates/tinymce-templates.php' ) ) { |
| 192 |
echo '<style>#tinymce-templates-wrap #tinymce-templates-preview { height: 500px !important; }</style>'; |
| 193 |
} |
| 194 |
if ( Utils::is_plugin_active( 'elementor/elementor.php' ) ) { |
| 195 |
echo '<style> |
| 196 |
body.wp-adminify-admin-bar.admin-bar .dialog-lightbox-widget { |
| 197 |
height: calc(100vh - 0px) !important; |
| 198 |
} |
| 199 |
body.wp-adminify-admin-bar.admin-bar #e-admin-top-bar-root{ |
| 200 |
padding-top: 70px !important; |
| 201 |
width: calc(100% + 20px) !important; |
| 202 |
margin-left: -20px; |
| 203 |
} |
| 204 |
body.wp-adminify-admin-bar.admin-bar #e-admin-top-bar-root .e-admin-top-bar{ |
| 205 |
padding-left: 20px; |
| 206 |
} |
| 207 |
</style>'; |
| 208 |
} |
| 209 |
if ( Utils::is_plugin_active( 'one-click-demo-import/one-click-demo-import.php' ) ) { |
| 210 |
echo '<style> |
| 211 |
.wp-adminify.appearance_page_one-click-demo-import .button-hero { |
| 212 |
min-height: auto !important; |
| 213 |
} |
| 214 |
</style>'; |
| 215 |
} |
| 216 |
if ( Utils::is_plugin_active( 'wpforms-lite/wpforms.php' ) ) { |
| 217 |
if ( Utils::jltwp_adminify_currentpage_id( 'dashboard' ) ) { |
| 218 |
wp_enqueue_style( |
| 219 |
'wpforms-full', |
| 220 |
WPFORMS_PLUGIN_URL . 'assets/css/frontend/classic/wpforms-full.css', |
| 221 |
[], |
| 222 |
WPFORMS_VERSION |
| 223 |
); |
| 224 |
} |
| 225 |
} |
| 226 |
if ( Utils::is_plugin_active( 'classic-editor/classic-editor.php' ) ) { |
| 227 |
echo '<style> |
| 228 |
#ed_toolbar{ |
| 229 |
width: 100% !important; |
| 230 |
} |
| 231 |
#ed_toolbar #qt_content_dfw{ |
| 232 |
line-height: inherit; |
| 233 |
padding: 0; |
| 234 |
} |
| 235 |
</style>'; |
| 236 |
} |
| 237 |
if ( Utils::is_plugin_active( 'updraftplus/updraftplus.php' ) ) { |
| 238 |
echo '<style> |
| 239 |
.wp-adminify.settings_page_updraftplus input{ |
| 240 |
border-radius: 4px !important; |
| 241 |
border: 1px solid #CCC !important; |
| 242 |
} |
| 243 |
.wp-adminify.adminify-dark-mode .updraft_feat_table, |
| 244 |
.wp-adminify.adminify-dark-mode .updraft_feat_table td, |
| 245 |
.wp-adminify.adminify-dark-mode .updraft_next_scheduled_backups_wrapper > div, |
| 246 |
.wp-adminify.adminify-dark-mode .updraft_migrate_widget_module_content{ |
| 247 |
background: inherit; |
| 248 |
} |
| 249 |
.wp-adminify.adminify-dark-mode .updraft_premium_cta, |
| 250 |
.wp-adminify.adminify-dark-mode .updraft_premium_cta__bottom, |
| 251 |
.wp-adminify.adminify-dark-mode .udp-box, |
| 252 |
.wp-adminify.adminify-dark-mode .updraftcentral_cloud_connect, |
| 253 |
.wp-adminify.adminify-dark-mode .updraft_advert_bottom, |
| 254 |
.wp-adminify.adminify-dark-mode #remote-storage-container label{ |
| 255 |
background: #020407; |
| 256 |
} |
| 257 |
.wp-adminify.adminify-dark-mode .expertmode .advanced_settings_container .advanced_settings_menu .advanced_tools_button{ |
| 258 |
color: inherit; |
| 259 |
} |
| 260 |
</style>'; |
| 261 |
} |
| 262 |
if ( Utils::is_plugin_active( 'tinymce-advanced/tinymce-advanced.php' ) ) { |
| 263 |
echo '<style> |
| 264 |
.wp-editor-container .mce-container-body .mce-menubar.mce-toolbar{ |
| 265 |
position: initial !important; |
| 266 |
} |
| 267 |
.wp-editor-container .mce-container-body .mce-toolbar-grp .mce-container-body{ |
| 268 |
position: relative !important; |
| 269 |
} |
| 270 |
.wp-editor-container .mce-container-body .mce-toolbar-grp .mce-toolbar.mce-first { |
| 271 |
padding-right: 0 !important; |
| 272 |
} |
| 273 |
#ed_toolbar{ |
| 274 |
width: 100% !important; |
| 275 |
} |
| 276 |
#ed_toolbar #qt_content_dfw{ |
| 277 |
line-height: inherit; |
| 278 |
padding: 0; |
| 279 |
} |
| 280 |
</style>'; |
| 281 |
} |
| 282 |
// Third Party localize script |
| 283 |
wp_localize_script( 'wp-adminify-admin', 'WPAdminify_ThirdParty', $this->thirdparty_create_js_object() ); |
| 284 |
} |
| 285 |
|
| 286 |
public function thirdparty_create_js_object() { |
| 287 |
// betterlinks menu settings |
| 288 |
$betterlinks = [ |
| 289 |
'active' => false, |
| 290 |
]; |
| 291 |
if ( Utils::is_plugin_active( 'betterlinks/betterlinks.php' ) ) { |
| 292 |
if ( is_array( $this->menu_settings ) && array_key_exists( 'betterlinks', $this->menu_settings ) ) { |
| 293 |
$menu_name = ( !empty( $this->menu_settings['betterlinks']['name'] ) ? esc_html( $this->menu_settings['betterlinks']['name'] ) : '' ); |
| 294 |
$submenu_manage = ( !empty( $this->menu_settings['betterlinks']['submenu']['betterlinks']['name'] ) ? esc_html( $this->menu_settings['betterlinks']['submenu']['betterlinks']['name'] ) : '' ); |
| 295 |
$submenu_name = ( !empty( $this->menu_settings['betterlinks']['submenu']['betterlinks-analytics']['name'] ) ? esc_html( $this->menu_settings['betterlinks']['submenu']['betterlinks-analytics']['name'] ) : '' ); |
| 296 |
$submenu_settings = ( !empty( $this->menu_settings['betterlinks']['submenu']['betterlinks-settings']['name'] ) ? esc_html( $this->menu_settings['betterlinks']['submenu']['betterlinks-settings']['name'] ) : '' ); |
| 297 |
$betterlinks = [ |
| 298 |
'active' => true, |
| 299 |
'menu_name' => esc_html( $menu_name ), |
| 300 |
'submenu_manage' => esc_html( $submenu_manage ), |
| 301 |
'submenu_name' => esc_html( $submenu_name ), |
| 302 |
'submenu_settings' => esc_html( $submenu_settings ), |
| 303 |
]; |
| 304 |
} |
| 305 |
} |
| 306 |
return [ |
| 307 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 308 |
'better_links' => wp_kses_post_deep( $betterlinks ), |
| 309 |
]; |
| 310 |
} |
| 311 |
|
| 312 |
public function register_actions_on_init() { |
| 313 |
// Brizy Builder |
| 314 |
if ( isset( $_REQUEST['brizy-edit-iframe'] ) ) { |
| 315 |
add_filter( 'wp_adminify_defer_skip', '__return_true' ); |
| 316 |
add_filter( 'wp_adminify_skip_removing_dashicons', '__return_true' ); |
| 317 |
} |
| 318 |
} |
| 319 |
|
| 320 |
public function register_actions_on_admin_init() { |
| 321 |
$adminify_ui = AdminSettings::get_instance()->get( 'admin_ui' ); |
| 322 |
if ( !empty( $adminify_ui ) ) { |
| 323 |
// Commented On: 24-3-24 |
| 324 |
add_action( 'admin_enqueue_scripts', [$this, 'enqueue_scripts'], 999 ); |
| 325 |
} |
| 326 |
// Commented On: 10-6-24 |
| 327 |
// add_filter('adminify_third_party_styles', [$this, 'register_compatability_styles']); |
| 328 |
// Fluent CRM |
| 329 |
add_action( 'fluentcrm_skip_no_conflict', '__return_true' ); |
| 330 |
// Fluent FORM |
| 331 |
add_action( 'fluentform_skip_no_conflict', '__return_true' ); |
| 332 |
} |
| 333 |
|
| 334 |
/** |
| 335 |
* Register Third Party Styles |
| 336 |
* |
| 337 |
* @since 1.0.0 |
| 338 |
*/ |
| 339 |
public function register_compatability_styles( $plugin_supports ) { |
| 340 |
if ( !is_array( $plugin_supports ) ) { |
| 341 |
$plugin_supports = []; |
| 342 |
} |
| 343 |
$plugin_dir = WP_ADMINIFY_ASSETS . 'css/plugins/'; |
| 344 |
$plugin_files = list_files( WP_ADMINIFY_PATH . 'assets/css/plugins/', 1 ); |
| 345 |
if ( !empty( $plugin_files ) ) { |
| 346 |
foreach ( $plugin_files as $file ) { |
| 347 |
$plugin_supports[wp_basename( $file, '.min.css' )] = $plugin_dir . wp_basename( $file ); |
| 348 |
} |
| 349 |
} |
| 350 |
return $plugin_supports; |
| 351 |
} |
| 352 |
|
| 353 |
/** |
| 354 |
* Admin Enqueue Third Party Scripts/Styles |
| 355 |
* |
| 356 |
* @return void |
| 357 |
*/ |
| 358 |
public function enqueue_scripts() { |
| 359 |
$plugin_supports = []; |
| 360 |
$plugin_supports = apply_filters( 'adminify_third_party_styles', $plugin_supports ); |
| 361 |
// Check Plugin Activated for Site Wide |
| 362 |
if ( is_multisite() ) { |
| 363 |
$active_plugins = get_site_option( 'active_sitewide_plugins' ); |
| 364 |
foreach ( $active_plugins as $active_path => $active_plugin ) { |
| 365 |
if ( is_plugin_active_for_network( $active_path ) ) { |
| 366 |
$string = explode( '/', $active_path ); |
| 367 |
$pluginname = $string[0]; |
| 368 |
if ( isset( $plugin_supports[$pluginname] ) ) { |
| 369 |
if ( $plugin_supports[$pluginname] != '' ) { |
| 370 |
wp_register_style( |
| 371 |
'wp-adminify_site-wide_' . $pluginname . '_css', |
| 372 |
$plugin_supports[$pluginname], |
| 373 |
[], |
| 374 |
WP_ADMINIFY_VER |
| 375 |
); |
| 376 |
wp_enqueue_style( 'wp-adminify_site-wide_' . $pluginname . '_css' ); |
| 377 |
} |
| 378 |
} |
| 379 |
} |
| 380 |
} |
| 381 |
} |
| 382 |
// Check Plugin Activated for Individual Sites |
| 383 |
$activeplugins = get_option( 'active_plugins' ); |
| 384 |
foreach ( $activeplugins as $plugin ) { |
| 385 |
if ( Utils::is_plugin_active( $plugin ) ) { |
| 386 |
$string = explode( '/', $plugin ); |
| 387 |
$pluginname = $string[0]; |
| 388 |
if ( isset( $plugin_supports[$pluginname] ) ) { |
| 389 |
if ( $plugin_supports[$pluginname] != '' ) { |
| 390 |
wp_register_style( |
| 391 |
'wp-adminify_' . $pluginname . '_css', |
| 392 |
$plugin_supports[$pluginname], |
| 393 |
[], |
| 394 |
WP_ADMINIFY_VER |
| 395 |
); |
| 396 |
wp_enqueue_style( 'wp-adminify_' . $pluginname . '_css' ); |
| 397 |
} |
| 398 |
} |
| 399 |
} |
| 400 |
} |
| 401 |
} |
| 402 |
|
| 403 |
} |
| 404 |
|