| 1 |
<?php |
| 2 |
namespace JewelTheme\AdminBarEditor; |
| 3 |
|
| 4 |
use JewelTheme\AdminBarEditor\Libs\Assets; |
| 5 |
use JewelTheme\AdminBarEditor\Libs\Helper; |
| 6 |
use JewelTheme\AdminBarEditor\Inc\Utils; |
| 7 |
use JewelTheme\AdminBarEditor\Libs\Featured; |
| 8 |
use JewelTheme\AdminBarEditor\Inc\Classes\Core; |
| 9 |
use JewelTheme\AdminBarEditor\Inc\Classes\Recommended_Plugins; |
| 10 |
use JewelTheme\AdminBarEditor\Inc\Classes\Notifications\Notifications; |
| 11 |
use JewelTheme\AdminBarEditor\Inc\Classes\Upgrade_Plugin; |
| 12 |
use JewelTheme\AdminBarEditor\Inc\Classes\Feedback; |
| 13 |
|
| 14 |
/** |
| 15 |
* Main Class |
| 16 |
* |
| 17 |
* @admin-bar |
| 18 |
* Jewel Theme <support@jeweltheme.com> |
| 19 |
* @version 1.0.2.3 |
| 20 |
*/ |
| 21 |
|
| 22 |
// No, Direct access Sir !!! |
| 23 |
if ( ! defined( 'ABSPATH' ) ) { |
| 24 |
exit; |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* AdminBarEditor Class |
| 29 |
*/ |
| 30 |
if ( ! class_exists( '\JewelTheme\AdminBarEditor\AdminBarEditor' ) ) { |
| 31 |
|
| 32 |
/** |
| 33 |
* Class: AdminBarEditor |
| 34 |
*/ |
| 35 |
final class AdminBarEditor { |
| 36 |
|
| 37 |
const VERSION = JLT_ADMIN_BAR_EDITOR_VER; |
| 38 |
private static $instance = null; |
| 39 |
|
| 40 |
/** |
| 41 |
* construct method |
| 42 |
* |
| 43 |
* @author Jewel Theme <support@jeweltheme.com> |
| 44 |
*/ |
| 45 |
public function __construct() { |
| 46 |
add_action( 'plugins_loaded', array( $this, 'jlt_admin_bar_editor_plugins_loaded' ) ); |
| 47 |
|
| 48 |
// Body Class. |
| 49 |
add_filter( 'admin_body_class', array( $this, 'jlt_admin_bar_editor_body_class' ) ); |
| 50 |
add_filter( 'body_class', array( $this, 'jlt_admin_bar_editor_body_class' ) ); |
| 51 |
|
| 52 |
// This should run earlier . |
| 53 |
add_action( 'plugins_loaded', [ $this, 'jlt_admin_bar_editor_maybe_run_upgrades' ], -100 ); |
| 54 |
|
| 55 |
// Register admin menu - check for Adminify plugin is done in the callback |
| 56 |
add_action( 'admin_menu', array( $this, 'register_admin_menu' ), 13 ); |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Register Admin Menu |
| 61 |
* Checks if Adminify plugin is active and registers appropriate menu |
| 62 |
* |
| 63 |
* @return void |
| 64 |
*/ |
| 65 |
public function register_admin_menu() { |
| 66 |
if ( Utils::is_plugin_active( 'adminify/adminify.php' ) || Utils::is_plugin_active( 'adminify-pro/adminify.php' ) ) { |
| 67 |
$this->jltwp_adminify_adminbar_submenu(); |
| 68 |
} else { |
| 69 |
$this->settings_menu(); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Adminify Sub Menu |
| 75 |
*/ |
| 76 |
public function jltwp_adminify_adminbar_submenu(){ |
| 77 |
$submenu_position = apply_filters('jltwp_adminify_submenu_position', 3); |
| 78 |
|
| 79 |
// If WP Adminify Plugin Installed then show on Sub Menu |
| 80 |
add_submenu_page( |
| 81 |
'wp-adminify-settings', |
| 82 |
__('Adminbar Editor Settings', 'admin-bar'), |
| 83 |
__('Adminbar Editor', 'admin-bar'), |
| 84 |
'manage_options', |
| 85 |
'jlt_admin_bar_editor' . '-settings', // Page slug, will be displayed in URL |
| 86 |
array($this, 'settings_page'), |
| 87 |
$submenu_position |
| 88 |
); |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Register Main Menu. |
| 93 |
* |
| 94 |
* @return void |
| 95 |
* |
| 96 |
* @author Jewel Theme <support@jeweltheme.com> |
| 97 |
*/ |
| 98 |
public function settings_menu() { |
| 99 |
|
| 100 |
// If WP Adminify Plugin not Installed then show on Main Menu |
| 101 |
add_menu_page( |
| 102 |
__( 'Adminbar Editor', 'admin-bar' ), |
| 103 |
__( 'Adminbar Editor', 'admin-bar' ), |
| 104 |
'manage_options', |
| 105 |
'jlt_admin_bar_editor' . '-settings', |
| 106 |
array( $this, 'settings_page' ), |
| 107 |
JLT_ADMIN_BAR_EDITOR_IMAGES . 'menu-icon.svg', |
| 108 |
40 |
| 109 |
); |
| 110 |
|
| 111 |
add_submenu_page( |
| 112 |
'jlt_admin_bar_editor' . '-settings', |
| 113 |
__( 'Adminbar Editor Settings', 'admin-bar' ), |
| 114 |
__( 'Settings', 'admin-bar' ), |
| 115 |
'manage_options', |
| 116 |
'jlt_admin_bar_editor' . '-settings', |
| 117 |
array( $this, 'settings_page' ), |
| 118 |
10 |
| 119 |
); |
| 120 |
} |
| 121 |
|
| 122 |
function settings_page() { |
| 123 |
echo '<div id="jlt-admin-bar-editor-root"></div>'; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
/** |
| 128 |
* plugins_loaded method |
| 129 |
* |
| 130 |
* @author Jewel Theme <support@jeweltheme.com> |
| 131 |
*/ |
| 132 |
public function jlt_admin_bar_editor_plugins_loaded() { |
| 133 |
new Assets(); |
| 134 |
new Recommended_Plugins(); |
| 135 |
new Notifications(); |
| 136 |
new Featured(); |
| 137 |
new Feedback(); |
| 138 |
new Core(); |
| 139 |
} |
| 140 |
|
| 141 |
/** |
| 142 |
* Version Key |
| 143 |
* |
| 144 |
* @author Jewel Theme <support@jeweltheme.com> |
| 145 |
*/ |
| 146 |
public static function plugin_version_key() { |
| 147 |
return Helper::jlt_admin_bar_editor_slug_cleanup() . '_version'; |
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* Activation Hook |
| 152 |
* |
| 153 |
* @author Jewel Theme <support@jeweltheme.com> |
| 154 |
*/ |
| 155 |
public static function jlt_admin_bar_editor_activate() { |
| 156 |
$current_jlt_admin_bar_editor_version = get_option( self::plugin_version_key(), null ); |
| 157 |
|
| 158 |
if ( get_option( 'jlt_admin_bar_editor_activation_time' ) === false ) { |
| 159 |
update_option( 'jlt_admin_bar_editor_activation_time', strtotime( 'now' ) ); |
| 160 |
} |
| 161 |
|
| 162 |
if ( is_null( $current_jlt_admin_bar_editor_version ) ) { |
| 163 |
update_option( self::plugin_version_key(), self::VERSION ); |
| 164 |
} |
| 165 |
|
| 166 |
$allowed = get_option( Helper::jlt_admin_bar_editor_slug_cleanup() . '_allow_tracking', 'no' ); |
| 167 |
|
| 168 |
// if it wasn't allowed before, do nothing . |
| 169 |
if ( 'yes' !== $allowed ) { |
| 170 |
return; |
| 171 |
} |
| 172 |
// re-schedule and delete the last sent time so we could force send again . |
| 173 |
$hook_name = Helper::jlt_admin_bar_editor_slug_cleanup() . '_tracker_send_event'; |
| 174 |
if ( ! wp_next_scheduled( $hook_name ) ) { |
| 175 |
wp_schedule_event( time(), 'weekly', $hook_name ); |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
/** |
| 181 |
* Add Body Class |
| 182 |
* |
| 183 |
* @param [type] $classes . |
| 184 |
* |
| 185 |
* @author Jewel Theme <support@jeweltheme.com> |
| 186 |
*/ |
| 187 |
public function jlt_admin_bar_editor_body_class( $classes ) { |
| 188 |
// $classes .= ' jlt-admin-bar_editor '; // TODO: Need to change all classes |
| 189 |
if( is_array($classes)){ |
| 190 |
array_push($classes, 'jlt-admin-bar' ); |
| 191 |
} else { |
| 192 |
$classes .= ' jlt-admin-bar '; |
| 193 |
} |
| 194 |
return $classes; |
| 195 |
} |
| 196 |
|
| 197 |
/** |
| 198 |
* Run Upgrader Class |
| 199 |
* |
| 200 |
* @return void |
| 201 |
*/ |
| 202 |
public function jlt_admin_bar_editor_maybe_run_upgrades() { |
| 203 |
if ( ! is_admin() && ! current_user_can( 'manage_options' ) ) { |
| 204 |
return; |
| 205 |
} |
| 206 |
|
| 207 |
// Run Upgrader . |
| 208 |
$upgrade = new Upgrade_Plugin(); |
| 209 |
|
| 210 |
// Need to work on Upgrade Class . |
| 211 |
if ( $upgrade->if_updates_available() ) { |
| 212 |
$upgrade->run_updates(); |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
/** |
| 218 |
* Initialization |
| 219 |
* |
| 220 |
* @author Jewel Theme <support@jeweltheme.com> |
| 221 |
*/ |
| 222 |
public function jlt_admin_bar_editor_init() { |
| 223 |
// WordPress 6.7+ automatically loads text domains based on plugin headers. |
| 224 |
// Manual loading is no longer needed. |
| 225 |
} |
| 226 |
|
| 227 |
/** |
| 228 |
* Returns the singleton instance of the class. |
| 229 |
*/ |
| 230 |
public static function get_instance() { |
| 231 |
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AdminBarEditor ) ) { |
| 232 |
self::$instance = new AdminBarEditor(); |
| 233 |
self::$instance->jlt_admin_bar_editor_init(); |
| 234 |
} |
| 235 |
|
| 236 |
return self::$instance; |
| 237 |
} |
| 238 |
} |
| 239 |
|
| 240 |
// Get Instant of AdminBarEditor Class . |
| 241 |
AdminBarEditor::get_instance(); |
| 242 |
} |
| 243 |
|