| 1 |
<?php |
| 2 |
|
| 3 |
namespace PXLBSAdminify; |
| 4 |
|
| 5 |
use PXLBSAdminify\Libs\Featured; |
| 6 |
use PXLBSAdminify\Inc\Admin\Admin; |
| 7 |
use PXLBSAdminify\Inc\Classes\Assets; |
| 8 |
use PXLBSAdminify\Inc\Classes\Upgrade; |
| 9 |
use PXLBSAdminify\Inc\Classes\Feedback; |
| 10 |
use PXLBSAdminify\Inc\Admin\AdminSettings; |
| 11 |
use PXLBSAdminify\Inc\Classes\Pro_Upgrade; |
| 12 |
use PXLBSAdminify\Inc\Classes\Addons_Plugins; |
| 13 |
use PXLBSAdminify\Inc\Classes\GoogleFontsLocal; |
| 14 |
use PXLBSAdminify\Inc\Classes\Notifications\Notifications; |
| 15 |
|
| 16 |
// No, Direct access Sir !!! |
| 17 |
if (!defined('ABSPATH')) { |
| 18 |
exit; |
| 19 |
} |
| 20 |
|
| 21 |
if (!class_exists('WP_Adminify')) { |
| 22 |
|
| 23 |
class WP_Adminify |
| 24 |
{ |
| 25 |
const VERSION = PXLBSADMINIFY_VER; |
| 26 |
private static $instance = null; |
| 27 |
|
| 28 |
public function __construct() |
| 29 |
{ |
| 30 |
|
| 31 |
add_action('plugins_loaded', array($this, 'maybe_run_upgrades'), -100); // This should run earlier |
| 32 |
add_action('plugins_loaded', array($this, 'maybe_loaded_addons'), -200); |
| 33 |
// add_action('plugins_loaded', array($this, 'pxlbsadminify_plugins_loaded'), 999); |
| 34 |
add_filter('plugin_action_links_' . PXLBSADMINIFY_BASE, array($this, 'plugin_action_links')); |
| 35 |
add_filter('network_admin_plugin_action_links_' . PXLBSADMINIFY_BASE, array($this, 'plugin_action_links')); |
| 36 |
|
| 37 |
add_filter('admin_body_class', array($this, 'pxlbsadminify_body_class'), 99); |
| 38 |
|
| 39 |
// Load textdomain and include files on init for WP 6.7+ compatibility |
| 40 |
// Textdomain must be loaded before files that use translations |
| 41 |
// Priority order: 0=textdomain, 1=include files (registers options), 5=framework setup |
| 42 |
add_action('init', array($this, 'pxlbsadminify_load_textdomain'), 0); |
| 43 |
add_action('init', array($this, 'pxlbsadminify_include_files'), 1); |
| 44 |
add_action('init', array($this, 'pxlbsadminify_is_plugin_row_meta'), 1); |
| 45 |
|
| 46 |
$is_finished = get_option('pxlbsadminify_setup_wizard_ran'); |
| 47 |
if ($is_finished !== '1') { |
| 48 |
if (apply_filters('pxlbsadminify_show_setup_wizard', true)) { |
| 49 |
new \PXLBSAdminify\Inc\Classes\Wizard\Setup_Wizard(); |
| 50 |
set_transient('pxlbsadminify_activation_redirect', 1, 30); |
| 51 |
} |
| 52 |
} |
| 53 |
jltwp_adminify()->add_filter('pricing_url', [$this, 'pxlbsadminify_pricing_url']); |
| 54 |
|
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
function pxlbsadminify_pricing_url( $pricing_url ) { |
| 60 |
$pricing_url = 'https://wpadminify.com/pricing'; |
| 61 |
|
| 62 |
return $pricing_url; |
| 63 |
} |
| 64 |
|
| 65 |
public function pxlbsadminify_is_plugin_row_meta() |
| 66 |
{ |
| 67 |
if (jltwp_adminify()->can_use_premium_code__premium_only()) { |
| 68 |
if (jltwp_adminify()->is_plan('agency')) { |
| 69 |
$pxlbsadminify_wl_plugin_row_links = AdminSettings::get_instance()->get('pxlbsadminify_wl_plugin_row_links'); |
| 70 |
if (!empty($pxlbsadminify_wl_plugin_row_links)) { |
| 71 |
return; |
| 72 |
} else { |
| 73 |
add_filter('plugin_row_meta', array($this, 'pxlbsadminify_plugin_row_meta'), 10, 2); |
| 74 |
add_filter('network_admin_plugin_row_meta', array($this, 'pxlbsadminify_plugin_row_meta'), 10, 2); |
| 75 |
} |
| 76 |
} |
| 77 |
} else { |
| 78 |
add_filter('plugin_row_meta', array($this, 'pxlbsadminify_plugin_row_meta'), 10, 2); |
| 79 |
add_filter('network_admin_plugin_row_meta', array($this, 'pxlbsadminify_plugin_row_meta'), 10, 2); |
| 80 |
} |
| 81 |
} |
| 82 |
/** |
| 83 |
* Add Body Class |
| 84 |
*/ |
| 85 |
public function pxlbsadminify_body_class($classes) |
| 86 |
{ |
| 87 |
$classes .= ' wp-adminify '; |
| 88 |
$adminify_ui = AdminSettings::get_instance()->get('admin_ui'); |
| 89 |
if (!empty($adminify_ui)) { |
| 90 |
$classes .= ' adminify-ui'; |
| 91 |
} |
| 92 |
if (is_rtl()) { |
| 93 |
$classes .= ' adminify-rtl '; |
| 94 |
} |
| 95 |
return $classes; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
/** |
| 100 |
* Plugin action links |
| 101 |
* |
| 102 |
* @param array $links |
| 103 |
* |
| 104 |
* @return array |
| 105 |
*/ |
| 106 |
public function plugin_action_links($links) |
| 107 |
{ |
| 108 |
|
| 109 |
$links['settings'] = apply_filters( |
| 110 |
'adminify_settings_link', |
| 111 |
sprintf('<a class="adminify-plugin-settings" href="%1$s">%2$s</a>', admin_url('admin.php?page=wp-adminify-settings'), __('Settings', 'adminify')) |
| 112 |
); |
| 113 |
|
| 114 |
if (jltwp_adminify()->can_use_premium_code__premium_only()) { |
| 115 |
$account_url = is_network_admin() ? network_admin_url('admin.php?page=wp-adminify-settings-account') : admin_url('admin.php?page=wp-adminify-settings-account'); |
| 116 |
|
| 117 |
$links['account'] = apply_filters( |
| 118 |
'adminify_account_link', |
| 119 |
sprintf( |
| 120 |
'<a class="adminify-plugin-account" href="%1$s">%2$s</a>', |
| 121 |
esc_url($account_url), |
| 122 |
__('Account', 'adminify') |
| 123 |
) |
| 124 |
); |
| 125 |
} |
| 126 |
|
| 127 |
// Check If Pro/Free |
| 128 |
if (!jltwp_adminify()->can_use_premium_code__premium_only()) { |
| 129 |
$links['pricing'] = apply_filters( |
| 130 |
'pxlbsadminify_upgrade_now_link', |
| 131 |
sprintf('<a href="%1$s" class="adminify-upgrade-pro" target="_blank" style="color: orangered;font-weight: bold;">%2$s</a>', 'https://wpadminify.com/pricing', __('Upgrade Now', 'adminify')) |
| 132 |
); |
| 133 |
} |
| 134 |
|
| 135 |
if (jltwp_adminify()->can_use_premium_code__premium_only()) { |
| 136 |
if (jltwp_adminify()->is_plan('agency')) { |
| 137 |
$settings = AdminSettings::get_instance()->get(); |
| 138 |
$plugin_row_links = !empty( $settings['white_label']['adminify']['row_links'] ) ? $settings['white_label']['adminify']['row_links'] : ''; |
| 139 |
$plugin_action_links = !empty($settings['white_label']['adminify']['remove_action_links'] ) ? $settings['white_label']['adminify']['remove_action_links'] : ''; |
| 140 |
if(empty($plugin_row_links)){ |
| 141 |
if (! empty($plugin_action_links)) { |
| 142 |
foreach ($plugin_action_links as $value) { |
| 143 |
unset($links[$value]); |
| 144 |
} |
| 145 |
} |
| 146 |
} else { |
| 147 |
unset($links['upgrade']); |
| 148 |
unset($links['activate_license']); |
| 149 |
unset($links['opt-in-or-opt-out']); |
| 150 |
unset($links['settings']); |
| 151 |
unset($links['account']); |
| 152 |
} |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
return apply_filters('adminify_plugin_row_links', $links); |
| 157 |
} |
| 158 |
|
| 159 |
public function pxlbsadminify_plugin_row_meta($plugin_meta, $plugin_file) |
| 160 |
{ |
| 161 |
if (PXLBSADMINIFY_BASE === $plugin_file) { |
| 162 |
$row_meta = array( |
| 163 |
'docs' => sprintf( |
| 164 |
'<a href="%1$s" target="_blank">%2$s</a>', |
| 165 |
esc_url_raw('https://wpadminify.com/kb'), |
| 166 |
__('Docs', 'adminify') |
| 167 |
), |
| 168 |
'changelogs' => sprintf( |
| 169 |
'<a href="%1$s" target="_blank">%2$s</a>', |
| 170 |
esc_url_raw('https://wpadminify.com/changelogs/'), |
| 171 |
__('Changelogs', 'adminify') |
| 172 |
), |
| 173 |
'tutorials' => '<a href="https://www.youtube.com/playlist?list=PLqpMw0NsHXV-EKj9Xm1DMGa6FGniHHly8" aria-label="' . esc_attr(__('View Adminify Video Tutorials', 'adminify')) . '" target="_blank">' . __('Video Tutorials', 'adminify') . '</a>', |
| 174 |
); |
| 175 |
|
| 176 |
$plugin_meta = array_merge($plugin_meta, $row_meta); |
| 177 |
} |
| 178 |
|
| 179 |
return $plugin_meta; |
| 180 |
} |
| 181 |
|
| 182 |
public function pxlbsadminify_plugins_loaded() |
| 183 |
{ |
| 184 |
self::pxlbsadminify_activation_hook(); |
| 185 |
} |
| 186 |
|
| 187 |
/** |
| 188 |
* Addons Loaded Method |
| 189 |
* |
| 190 |
* @return void |
| 191 |
*/ |
| 192 |
public function maybe_loaded_addons() |
| 193 |
{ |
| 194 |
do_action('pxlbsadminify_plugin_loaded', WP_Adminify::get_instance()); |
| 195 |
} |
| 196 |
|
| 197 |
public function maybe_run_upgrades() |
| 198 |
{ |
| 199 |
if (!is_admin() && !current_user_can('manage_options')) { |
| 200 |
return; |
| 201 |
} |
| 202 |
|
| 203 |
$upgrade = new Upgrade(); |
| 204 |
|
| 205 |
if ($upgrade->if_updates_available()) { |
| 206 |
$upgrade->run_updates(); |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
public function pxlbsadminify_include_files() |
| 211 |
{ |
| 212 |
new Assets(); |
| 213 |
new Admin(); |
| 214 |
new Featured(); |
| 215 |
new Feedback(); |
| 216 |
new Notifications(); |
| 217 |
new Pro_Upgrade(); |
| 218 |
new Addons_Plugins(); |
| 219 |
// Initialize Google Fonts Local early to catch option updates |
| 220 |
GoogleFontsLocal::get_instance(); |
| 221 |
|
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
public function pxlbsadminify_init() |
| 226 |
{ |
| 227 |
// Backup for OLD Database |
| 228 |
$current_version = get_option('pxlbsadminify_version'); |
| 229 |
$is_backup = $old_data = get_option( 'pxlbsadminify_settings_backup' ); |
| 230 |
if ( version_compare( $current_version, PXLBSADMINIFY_VER, '<' ) && empty($is_backup) ) { |
| 231 |
$old_data = get_option( 'pxlbsadminify_settings' ); |
| 232 |
update_option( 'pxlbsadminify_settings_backup', $old_data ); |
| 233 |
} |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
/** |
| 238 |
* Loads the text domain for localization. |
| 239 |
* |
| 240 |
* This function sets up the text domain for the WP Adminify plugin, |
| 241 |
* allowing it to load translation files for the specified locale. |
| 242 |
* It first attempts to load a custom translation file from the WordPress |
| 243 |
* languages directory and then loads the default translation file from |
| 244 |
* the plugin's languages directory. |
| 245 |
* |
| 246 |
* @return void |
| 247 |
*/ |
| 248 |
public function pxlbsadminify_load_textdomain() |
| 249 |
{ |
| 250 |
$locale = apply_filters('plugin_locale', get_locale(), 'adminify'); |
| 251 |
|
| 252 |
load_textdomain('adminify', WP_LANG_DIR . '/adminify/adminify-' . $locale . '.mo'); |
| 253 |
// phpcs:ignore PluginCheck.CodeAnalysis.DiscouragedFunctions.load_plugin_textdomainFound -- retained for non-hosted / older-WP installs. |
| 254 |
load_plugin_textdomain('adminify', false, dirname(PXLBSADMINIFY_BASE) . '/languages/'); |
| 255 |
} |
| 256 |
|
| 257 |
// Activation Hook |
| 258 |
public static function pxlbsadminify_activation_hook() |
| 259 |
{ |
| 260 |
$current_adminify_version = get_option('pxlbsadminify_version', null); |
| 261 |
|
| 262 |
if (get_option('pxlbsadminify_activation_time') === false) { |
| 263 |
update_option('pxlbsadminify_activation_time', strtotime('now')); |
| 264 |
} |
| 265 |
|
| 266 |
if("dismissed" === get_option('pxlbsadminify_plugin_update_info_notice', true )){ |
| 267 |
update_option('pxlbsadminify_plugin_update_info_notice', ''); |
| 268 |
} |
| 269 |
|
| 270 |
if (is_null($current_adminify_version)) { |
| 271 |
update_option('pxlbsadminify_version', self::VERSION); |
| 272 |
} |
| 273 |
|
| 274 |
//database upgrade logic here |
| 275 |
$old_data = get_option('pxlbsadminify_settings'); |
| 276 |
update_option('pxlbsadminify_settings_backup', $old_data); |
| 277 |
|
| 278 |
// Create term_order collumn in terms table, to support post type order |
| 279 |
global $wpdb; |
| 280 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- direct query required for one-time schema inspection on activation; not cached intentionally. |
| 281 |
$check_term_order_column = $wpdb->query("SHOW COLUMNS FROM $wpdb->terms LIKE 'term_order'"); |
| 282 |
if ( $check_term_order_column == 0 ) { |
| 283 |
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange -- direct query required for one-time schema change on activation; not cached intentionally. |
| 284 |
$wpdb->query("ALTER TABLE $wpdb->terms ADD term_order INT( 4 ) NULL DEFAULT '0'"); |
| 285 |
} |
| 286 |
} |
| 287 |
|
| 288 |
// Deactivation Hook |
| 289 |
public static function pxlbsadminify_deactivation_hook() |
| 290 |
{ |
| 291 |
delete_option('pxlbsadminify_activation_time'); |
| 292 |
delete_option('pxlbsadminify_customizer_flush_url'); |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
/** |
| 297 |
* Returns the singleton instance of the class. |
| 298 |
*/ |
| 299 |
|
| 300 |
public static function get_instance() |
| 301 |
{ |
| 302 |
if (!isset(self::$instance) && !(self::$instance instanceof WP_Adminify)) { |
| 303 |
self::$instance = new WP_Adminify(); |
| 304 |
self::$instance->pxlbsadminify_init(); |
| 305 |
} |
| 306 |
|
| 307 |
return self::$instance; |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
WP_Adminify::get_instance(); |
| 312 |
} |
| 313 |
|