| 1 |
<?php |
| 2 |
|
| 3 |
namespace PixelGallery; |
| 4 |
|
| 5 |
if (!defined('ABSPATH')) { |
| 6 |
exit; |
| 7 |
} // Exit if accessed directly |
| 8 |
|
| 9 |
|
| 10 |
require_once BDTPG_ADMIN_PATH . 'class-settings-api.php'; |
| 11 |
// require_once BDTPG_ADMIN_PATH . 'admin-feeds.php'; |
| 12 |
// pixel gallery admin settings here |
| 13 |
require_once BDTPG_ADMIN_PATH . 'admin-settings.php'; |
| 14 |
|
| 15 |
/** |
| 16 |
* Admin class |
| 17 |
*/ |
| 18 |
|
| 19 |
class Admin { |
| 20 |
|
| 21 |
public function __construct() { |
| 22 |
|
| 23 |
// Embed the Script on our Plugin's Option Page Only |
| 24 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading the page query var for admin menu routing only, no state change. |
| 25 |
if (isset($_GET['page']) && ('pixel_gallery_options' === sanitize_text_field(wp_unslash($_GET['page'])))) { |
| 26 |
add_action('admin_enqueue_scripts', [$this, 'enqueue_styles']); |
| 27 |
} |
| 28 |
|
| 29 |
add_action('admin_init', [$this, 'admin_script']); |
| 30 |
|
| 31 |
add_action('upgrader_process_complete', [$this, 'pixel_gallery_plugin_on_upgrade_process_complete'], 10, 2); |
| 32 |
|
| 33 |
register_deactivation_hook(BDTPG__FILE__, [$this, 'pixel_gallery_plugin_on_deactivate']); |
| 34 |
|
| 35 |
add_action('after_setup_theme', [$this, 'plugin_meta_links']); |
| 36 |
|
| 37 |
add_filter('plugin_action_links_' . BDTPG_PBNAME, [$this, 'plugin_action_links']); |
| 38 |
|
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
function install_and_activate() { |
| 43 |
|
| 44 |
// I don't know of any other redirect function, so this'll have to do. |
| 45 |
wp_safe_redirect(admin_url('admin.php?page=pixel_gallery_options')); |
| 46 |
exit; |
| 47 |
// You could use a header(sprintf('Location: %s', admin_url(...)); here instead too. |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Register the plugin row meta and action links. |
| 52 |
* @access public |
| 53 |
*/ |
| 54 |
public function plugin_meta_links() { |
| 55 |
add_filter('plugin_row_meta', [$this, 'plugin_row_meta'], 10, 2); |
| 56 |
add_filter('plugin_action_links_' . BDTPG_PBNAME, [$this, 'plugin_action_meta']); |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Enqueue styles |
| 61 |
* @access public |
| 62 |
*/ |
| 63 |
|
| 64 |
public function enqueue_styles() { |
| 65 |
|
| 66 |
$direction_suffix = is_rtl() ? '.rtl' : ''; |
| 67 |
|
| 68 |
wp_enqueue_style('bdt-uikit', BDTPG_ADMIN_URL . 'assets/css/bdt-uikit'. $direction_suffix .'.css', [], '3.21.7'); |
| 69 |
wp_enqueue_style('pg-editor', BDTPG_ASSETS_URL . 'css/pg-editor.css', [], BDTPG_VER); |
| 70 |
wp_enqueue_style('pg-admin', BDTPG_ADMIN_URL . 'assets/css/pg-admin.css', [], BDTPG_VER); |
| 71 |
|
| 72 |
|
| 73 |
wp_enqueue_script('bdt-uikit', BDTPG_ADMIN_URL . 'assets/js/bdt-uikit.min.js', ['jquery'], '3.21.7', true); |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Row meta |
| 78 |
* @access public |
| 79 |
* @return array |
| 80 |
*/ |
| 81 |
|
| 82 |
public function plugin_row_meta($plugin_meta, $plugin_file) { |
| 83 |
if (BDTPG_PBNAME === $plugin_file) { |
| 84 |
$row_meta = [ |
| 85 |
'docs' => '<a href="https://bdthemes.com/contact/" aria-label="' . esc_attr(__('Go for Get Support', 'pixel-gallery')) . '" target="_blank">' . __('Get Support', 'pixel-gallery') . '</a>', |
| 86 |
'video' => '<a href="https://www.youtube.com/playlist?list=PLP0S85GEw7DPv5T-Ara11Zvplmk4ty0jy" aria-label="' . esc_attr(__('View Pixel Gallery Video Tutorials', 'pixel-gallery')) . '" target="_blank">' . __('Video Tutorials', 'pixel-gallery') . '</a>', |
| 87 |
]; |
| 88 |
|
| 89 |
$plugin_meta = array_merge($plugin_meta, $row_meta); |
| 90 |
} |
| 91 |
|
| 92 |
return $plugin_meta; |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Plugin action links |
| 97 |
* @access public |
| 98 |
* @return array |
| 99 |
*/ |
| 100 |
|
| 101 |
public function plugin_action_links( $plugin_meta ) { |
| 102 |
|
| 103 |
$row_meta = [ |
| 104 |
'settings' => '<a href="'.admin_url( 'admin.php?page=pixel_gallery_options' ) .'" aria-label="' . esc_attr(__('Go to settings', 'pixel-gallery')) . '" >' . __('Settings', 'pixel-gallery') . '</b></a>', |
| 105 |
]; |
| 106 |
|
| 107 |
$plugin_meta = array_merge($plugin_meta, $row_meta); |
| 108 |
|
| 109 |
return $plugin_meta; |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* Action meta |
| 114 |
* @access public |
| 115 |
* @return array |
| 116 |
*/ |
| 117 |
|
| 118 |
|
| 119 |
public function plugin_action_meta($links) { |
| 120 |
|
| 121 |
$links = array_merge([sprintf('<a href="%s">%s</a>', pixel_gallery_dashboard_link('#pixel_gallery_welcome'), esc_html__('Settings', 'pixel-gallery'))], $links); |
| 122 |
|
| 123 |
$links = array_merge($links, [ |
| 124 |
sprintf( |
| 125 |
'<a href="%s">%s</a>', |
| 126 |
pixel_gallery_dashboard_link('#pixel_gallery_license_settings'), |
| 127 |
esc_html__('License', 'pixel-gallery') |
| 128 |
) |
| 129 |
]); |
| 130 |
|
| 131 |
return $links; |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* Register admin script |
| 136 |
* @access public |
| 137 |
*/ |
| 138 |
|
| 139 |
public function admin_script() { |
| 140 |
|
| 141 |
if (is_admin()) { // for Admin Dashboard Only |
| 142 |
|
| 143 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading the page query var for admin menu routing only, no state change. |
| 144 |
if (isset($_GET['page']) && ('pixel_gallery_options' === sanitize_text_field(wp_unslash($_GET['page'])))) { |
| 145 |
wp_enqueue_script('chart', BDTPG_ADMIN_URL . 'assets/js/chart.min.js', ['jquery'], '2.7.3', true); |
| 146 |
wp_enqueue_script('pg-admin', BDTPG_ADMIN_URL . 'assets/js/pg-admin.min.js', ['jquery', 'chart'], BDTPG_VER, true); |
| 147 |
}else{ |
| 148 |
wp_enqueue_script('pg-admin', BDTPG_ADMIN_URL . 'assets/js/pg-admin.min.js', ['jquery'], BDTPG_VER, true); |
| 149 |
} |
| 150 |
|
| 151 |
wp_enqueue_script('jquery'); |
| 152 |
wp_enqueue_script('jquery-form'); |
| 153 |
|
| 154 |
wp_enqueue_style('bdt-product-feed', BDTPG_ADMIN_URL . 'assets/css/pg-admin-feeds.css', [], BDTPG_VER); |
| 155 |
|
| 156 |
wp_enqueue_script('pg-biggopti', BDTPG_ADMIN_URL . 'assets/js/pg-biggopti.min.js', ['jquery'], BDTPG_VER, true); |
| 157 |
|
| 158 |
$dismissals = get_option('bdt_biggopti_dismissals', []); |
| 159 |
$dismissed_display_ids = []; |
| 160 |
$prefix = 'bdt-admin-biggopti-api-biggopti-'; |
| 161 |
foreach (array_keys($dismissals) as $key) { |
| 162 |
if (strpos($key, $prefix) === 0) { |
| 163 |
$dismissed_display_ids[] = substr($key, strlen($prefix)); |
| 164 |
} else { |
| 165 |
$dismissed_display_ids[] = $key; |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
$current_sector = ''; |
| 170 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reading the page query var for admin menu routing only, no state change. |
| 171 |
if ( isset( $_GET['page'] ) && 'pixel_gallery_options' === sanitize_text_field( wp_unslash( $_GET['page'] ) ) ) { |
| 172 |
$current_sector = 'plugin_dashboard'; |
| 173 |
} |
| 174 |
|
| 175 |
$script_config = [ |
| 176 |
'ajaxurl' => admin_url('admin-ajax.php'), |
| 177 |
'nonce' => wp_create_nonce('pixel-gallery'), |
| 178 |
'isPro' => function_exists('_is_pg_pro_activated') && _is_pg_pro_activated(), |
| 179 |
'assetsUrl' => defined('BDTPG_ASSETS_URL') ? BDTPG_ASSETS_URL : '', |
| 180 |
'dismissedDisplayIds' => $dismissed_display_ids, |
| 181 |
'currentSector' => $current_sector, |
| 182 |
]; |
| 183 |
|
| 184 |
wp_localize_script('pg-biggopti', 'PixelGalleryBiggoptiConfig', $script_config); |
| 185 |
|
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
/** |
| 190 |
* Drop Tables on deactivated plugin |
| 191 |
* @access public |
| 192 |
*/ |
| 193 |
|
| 194 |
public function pixel_gallery_plugin_on_deactivate() { |
| 195 |
|
| 196 |
global $wpdb; |
| 197 |
|
| 198 |
$table_cat = $wpdb->prefix . 'pg_template_library_cat'; |
| 199 |
$table_post = $wpdb->prefix . 'pg_template_library_post'; |
| 200 |
$table_cat_post = $wpdb->prefix . 'pg_template_library_cat_post'; |
| 201 |
// Removing the plugin's own tables on deactivation is a one-time schema |
| 202 |
// change; there is nothing to cache and no core API for dropping tables. |
| 203 |
$wpdb->query('DROP TABLE IF EXISTS ' . $table_cat_post); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange -- Table name derived from $wpdb->prefix, not user input. |
| 204 |
$wpdb->query('DROP TABLE IF EXISTS ' . $table_cat); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange -- Table name derived from $wpdb->prefix, not user input. |
| 205 |
$wpdb->query('DROP TABLE IF EXISTS ' . $table_post); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange -- Table name derived from $wpdb->prefix, not user input. |
| 206 |
} |
| 207 |
|
| 208 |
/** |
| 209 |
* Upgrade Process Complete |
| 210 |
* @access public |
| 211 |
*/ |
| 212 |
|
| 213 |
public function pixel_gallery_plugin_on_upgrade_process_complete($upgrader_object, $options) { |
| 214 |
if (isset($options['action']) && $options['action'] == 'update' && $options['type'] == 'plugin') { |
| 215 |
if (isset($options['plugins']) && is_array($options['plugins'])) { |
| 216 |
foreach ($options['plugins'] as $each_plugin) { |
| 217 |
if ($each_plugin == BDTPG_PBNAME) { |
| 218 |
@$this->pixel_gallery_plugin_on_deactivate(); |
| 219 |
} |
| 220 |
} |
| 221 |
} |
| 222 |
} |
| 223 |
} |
| 224 |
} |
| 225 |
|