| 1 |
<?php |
| 2 |
|
| 3 |
namespace UltimatePostKit; |
| 4 |
|
| 5 |
if (!defined('ABSPATH')) { |
| 6 |
exit; |
| 7 |
} // Exit if accessed directly |
| 8 |
|
| 9 |
|
| 10 |
require_once BDTUPK_ADMIN_PATH . 'class-settings-api.php'; |
| 11 |
|
| 12 |
if (current_user_can('manage_options')) { |
| 13 |
require_once BDTUPK_ADMIN_PATH . 'admin-feeds.php'; |
| 14 |
} |
| 15 |
|
| 16 |
// element pack admin settings here |
| 17 |
require_once BDTUPK_ADMIN_PATH . 'admin-settings.php'; |
| 18 |
|
| 19 |
/** |
| 20 |
* Admin class |
| 21 |
*/ |
| 22 |
|
| 23 |
class Admin |
| 24 |
{ |
| 25 |
|
| 26 |
public function __construct() |
| 27 |
{ |
| 28 |
|
| 29 |
// Embed the Script on our Plugin's Option Page Only |
| 30 |
if (isset($_GET['page']) && ($_GET['page'] == 'ultimate_post_kit_options')) { |
| 31 |
add_action('admin_enqueue_scripts', [$this, 'enqueue_styles']); |
| 32 |
} |
| 33 |
add_action('admin_init', [$this, 'enqueue_admin_script']); |
| 34 |
|
| 35 |
// Admin settings controller |
| 36 |
require_once BDTUPK_ADMIN_PATH . 'module-settings.php'; |
| 37 |
|
| 38 |
// register_activation_hook(BDTUPK__FILE__, 'install_and_activate'); |
| 39 |
|
| 40 |
add_action('admin_init', [$this, 'admin_notice_styles']); |
| 41 |
|
| 42 |
add_filter('plugin_action_links_' . BDTUPK_PBNAME, [$this, 'plugin_action_links']); |
| 43 |
|
| 44 |
} |
| 45 |
|
| 46 |
public function admin_notice_styles(){ |
| 47 |
$direction_suffix = is_rtl() ? '.rtl' : ''; |
| 48 |
wp_enqueue_style('upk-admin-biggopti', BDTUPK_ADMIN_ASSETS_URL . 'css/upk-admin-biggopti' . $direction_suffix . '.css', [], BDTUPK_VER); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
function install_and_activate() |
| 53 |
{ |
| 54 |
|
| 55 |
wp_safe_redirect(admin_url('admin.php?page=ultimate_post_kit_options')); |
| 56 |
exit; |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Enqueue styles |
| 61 |
* @access public |
| 62 |
*/ |
| 63 |
|
| 64 |
public function enqueue_styles() |
| 65 |
{ |
| 66 |
|
| 67 |
$direction_suffix = is_rtl() ? '.rtl' : ''; |
| 68 |
// $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
| 69 |
|
| 70 |
wp_enqueue_style('upk-admin', BDTUPK_ADMIN_ASSETS_URL . 'css/upk-admin' . $direction_suffix . '.css', [], BDTUPK_VER); |
| 71 |
wp_enqueue_script('upk-admin', BDTUPK_ASSETS_URL . 'js/upk-admin.min.js', ['jquery'], BDTUPK_VER, true); |
| 72 |
wp_enqueue_style('upk-editor', BDTUPK_ASSETS_URL . 'css/upk-editor' . $direction_suffix . '.css', [], BDTUPK_VER); |
| 73 |
|
| 74 |
wp_enqueue_style('bdt-uikit', BDTUPK_ADMIN_ASSETS_URL . 'css/bdt-uikit' . $direction_suffix . '.css', [], '3.17.0'); |
| 75 |
wp_enqueue_style('upk-font', BDTUPK_ASSETS_URL . 'css/upk-font' . $direction_suffix . '.css', [], BDTUPK_VER); |
| 76 |
|
| 77 |
wp_enqueue_script('bdt-uikit', BDTUPK_ADMIN_ASSETS_URL . 'js/bdt-uikit.min.js', ['jquery'], '3.17.0'); |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Row meta |
| 82 |
* @access public |
| 83 |
* @return array |
| 84 |
*/ |
| 85 |
|
| 86 |
public function plugin_row_meta($plugin_meta, $plugin_file) |
| 87 |
{ |
| 88 |
if (BDTUPK_PBNAME === $plugin_file) { |
| 89 |
$row_meta = [ |
| 90 |
'docs' => '<a href="https://postkit.pro/contact/" aria-label="' . esc_attr(__('Go for Get Support', 'ultimate-post-kit')) . '" target="_blank">' . __('Get Support', 'ultimate-post-kit') . '</a>', |
| 91 |
'video' => '<a href="https://www.youtube.com/playlist?list=PLP0S85GEw7DOJf_cbgUIL20qqwqb5x8KA" aria-label="' . esc_attr(__('View Ultimate Post Kit Video Tutorials', 'ultimate-post-kit')) . '" target="_blank">' . __('Video Tutorials', 'ultimate-post-kit') . '</a>', |
| 92 |
]; |
| 93 |
|
| 94 |
$plugin_meta = array_merge($plugin_meta, $row_meta); |
| 95 |
} |
| 96 |
|
| 97 |
return $plugin_meta; |
| 98 |
} |
| 99 |
|
| 100 |
/** |
| 101 |
* Action meta |
| 102 |
* @access public |
| 103 |
* @return array |
| 104 |
*/ |
| 105 |
|
| 106 |
|
| 107 |
public function plugin_action_meta($links) |
| 108 |
{ |
| 109 |
|
| 110 |
$links = array_merge([sprintf('<a href="%s">%s</a>', ultimate_post_kit_dashboard_link('#ultimate_post_kit_welcome'), esc_html__('Settings', 'ultimate-post-kit'))], $links); |
| 111 |
|
| 112 |
$links = array_merge($links, [ |
| 113 |
sprintf( |
| 114 |
'<a href="%s">%s</a>', |
| 115 |
ultimate_post_kit_dashboard_link('#license'), |
| 116 |
esc_html__('License', 'ultimate-post-kit') |
| 117 |
) |
| 118 |
]); |
| 119 |
|
| 120 |
return $links; |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Plugin action links |
| 125 |
* @access public |
| 126 |
* @return array |
| 127 |
*/ |
| 128 |
|
| 129 |
public function plugin_action_links( $plugin_meta ) { |
| 130 |
|
| 131 |
$row_meta = [ |
| 132 |
'settings' => '<a href="'.admin_url( 'admin.php?page=ultimate_post_kit_options' ) .'" aria-label="' . esc_attr(__('Go to settings', 'ultimate-post-kit')) . '" >' . __('Settings', 'ultimate-post-kit') . '</b></a>', |
| 133 |
]; |
| 134 |
|
| 135 |
$plugin_meta = array_merge($plugin_meta, $row_meta); |
| 136 |
|
| 137 |
return $plugin_meta; |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* Change Ultimate Post Kit Name |
| 142 |
* @access public |
| 143 |
* @return string |
| 144 |
*/ |
| 145 |
|
| 146 |
public function ultimate_post_kit_name_change($translated_text, $text, $domain) |
| 147 |
{ |
| 148 |
switch ($translated_text) { |
| 149 |
case 'Ultimate Post Kit Pro': |
| 150 |
$translated_text = BDTUPK_TITLE; |
| 151 |
break; |
| 152 |
} |
| 153 |
|
| 154 |
return $translated_text; |
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* Hiding plugins //still in testing purpose |
| 159 |
* @access public |
| 160 |
*/ |
| 161 |
|
| 162 |
public function hide_ultimate_post_kit() |
| 163 |
{ |
| 164 |
global $wp_list_table; |
| 165 |
$hide_plg_array = array('ultimate-post-kit/ultimate-post-kit.php'); |
| 166 |
$all_plugins = $wp_list_table->items; |
| 167 |
|
| 168 |
foreach ($all_plugins as $key => $val) { |
| 169 |
if (in_array($key, $hide_plg_array)) { |
| 170 |
unset($wp_list_table->items[$key]); |
| 171 |
} |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
/** |
| 176 |
* Register admin script |
| 177 |
* @access public |
| 178 |
*/ |
| 179 |
|
| 180 |
public function enqueue_admin_script() |
| 181 |
{ |
| 182 |
|
| 183 |
// $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
| 184 |
wp_enqueue_script('jquery'); |
| 185 |
wp_enqueue_script('jquery-form'); |
| 186 |
wp_enqueue_script('upk-biggopti', BDTUPK_ADMIN_ASSETS_URL . 'js/upk-biggopti.min.js', ['jquery'], BDTUPK_VER, true); |
| 187 |
|
| 188 |
$dismissals = get_option('bdt_biggopti_dismissals', []); |
| 189 |
$dismissed_display_ids = []; |
| 190 |
$prefix = 'bdt-admin-biggopti-api-biggopti-'; |
| 191 |
foreach (array_keys($dismissals) as $key) { |
| 192 |
if (strpos($key, $prefix) === 0) { |
| 193 |
$dismissed_display_ids[] = substr($key, strlen($prefix)); |
| 194 |
} else { |
| 195 |
$dismissed_display_ids[] = $key; |
| 196 |
} |
| 197 |
} |
| 198 |
|
| 199 |
$current_sector = ''; |
| 200 |
if ( isset( $_GET['page'] ) && $_GET['page'] === 'ultimate_post_kit_options' ) { |
| 201 |
$current_sector = 'plugin_dashboard'; |
| 202 |
} |
| 203 |
$script_config = [ |
| 204 |
'ajaxurl' => admin_url('admin-ajax.php'), |
| 205 |
'nonce' => wp_create_nonce('ultimate-post-kit'), |
| 206 |
'isPro' => function_exists('_is_upk_pro_activated') && _is_upk_pro_activated(), |
| 207 |
'assetsUrl' => defined('BDTUPK_ASSETS_URL') ? BDTUPK_ASSETS_URL : '', |
| 208 |
'dismissedDisplayIds' => $dismissed_display_ids, |
| 209 |
'currentSector' => $current_sector, |
| 210 |
]; |
| 211 |
wp_localize_script('upk-biggopti', 'UltimatePostKitBiggoptiConfig', $script_config); |
| 212 |
|
| 213 |
if (isset($_GET['page']) && ($_GET['page'] == 'ultimate_post_kit_options')) { |
| 214 |
wp_enqueue_script('chart', BDTUPK_ADMIN_ASSETS_URL . 'js/chart.min.js', ['jquery'], '3.9.1', true); |
| 215 |
wp_enqueue_script('upk-admin', BDTUPK_ADMIN_ASSETS_URL . 'js/upk-admin.min.js', ['jquery', 'chart'], BDTUPK_VER, true); |
| 216 |
}else{ |
| 217 |
wp_enqueue_script('upk-admin', BDTUPK_ADMIN_ASSETS_URL . 'js/upk-admin.min.js', ['jquery'], BDTUPK_VER, true); |
| 218 |
} |
| 219 |
|
| 220 |
} |
| 221 |
} |
| 222 |
|