| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPAdminify\Inc\Modules\CustomHeaderFooter; |
| 4 |
|
| 5 |
use WPAdminify\Inc\Utils; |
| 6 |
// no direct access allowed |
| 7 |
if (!defined('ABSPATH')) exit; |
| 8 |
|
| 9 |
/** |
| 10 |
* WPAdminify |
| 11 |
* @package Module: Dashboard Widget |
| 12 |
* |
| 13 |
* @author Jewel Theme <support@jeweltheme.com> |
| 14 |
*/ |
| 15 |
|
| 16 |
class CustomHeaderFooterSettings extends CustomHeaderFooterModel |
| 17 |
{ |
| 18 |
public function __construct() |
| 19 |
{ |
| 20 |
// this should be first so the default values get stored |
| 21 |
$this->custom_header_footer_settings(); |
| 22 |
parent::__construct((array) get_site_option($this->prefix)); |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
public function get_defaults() |
| 27 |
{ |
| 28 |
return [ |
| 29 |
'custom_scripts' => array( |
| 30 |
'title' => '', |
| 31 |
'display_on' => 'full_site', |
| 32 |
'custom_posts' => '', |
| 33 |
'custom_category' => '', |
| 34 |
'custom_post_types' => '', |
| 35 |
'custom_pages' => '', |
| 36 |
'custom_tags' => '', |
| 37 |
'location' => 'header', |
| 38 |
'device_type' => 'all_devices', |
| 39 |
'script_type' => 'css', |
| 40 |
'custom_js' => '', |
| 41 |
'custom_css' => '', |
| 42 |
) |
| 43 |
]; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
/** |
| 48 |
* Settings Fields |
| 49 |
* |
| 50 |
* @return void |
| 51 |
*/ |
| 52 |
public function custom_header_footer_setting_fields(&$fields) |
| 53 |
{ |
| 54 |
$fields[] = array( |
| 55 |
'id' => 'title', |
| 56 |
'type' => 'text', |
| 57 |
'title' => __('Snippet Title', WP_ADMINIFY_TD), |
| 58 |
'default' => $this->get_default_field('custom_scripts')['title'], |
| 59 |
); |
| 60 |
|
| 61 |
if (jltwp_adminify()->can_use_premium_code__premium_only()) { |
| 62 |
$fields[] = array( |
| 63 |
'id' => 'display_on', |
| 64 |
'type' => 'select', |
| 65 |
'title' => __('Display on', WP_ADMINIFY_TD), |
| 66 |
'placeholder' => __('Select an option', WP_ADMINIFY_TD), |
| 67 |
'options' => array( |
| 68 |
'full_site' => __('Full Site', WP_ADMINIFY_TD), |
| 69 |
's_posts' => __('Specific Posts', WP_ADMINIFY_TD), |
| 70 |
's_pages' => __('Specific Page', WP_ADMINIFY_TD), |
| 71 |
's_categories' => __('Specific Categories', WP_ADMINIFY_TD), |
| 72 |
's_custom_posts' => __('Specific Post Types', WP_ADMINIFY_TD), |
| 73 |
's_tags' => __('Specific Tags', WP_ADMINIFY_TD) |
| 74 |
), |
| 75 |
'default' => $this->get_default_field('custom_scripts')['display_on'], |
| 76 |
); |
| 77 |
} else { |
| 78 |
$fields[] = array( |
| 79 |
'id' => 'display_on', |
| 80 |
'type' => 'select', |
| 81 |
'title' => __('Display on', WP_ADMINIFY_TD), |
| 82 |
'placeholder' => __('Select an option', WP_ADMINIFY_TD), |
| 83 |
'options' => array( |
| 84 |
'full_site' => __('Full Site', WP_ADMINIFY_TD), |
| 85 |
'posts_pro' => __('Specific Posts (Pro)', WP_ADMINIFY_TD), |
| 86 |
'pages_pro' => __('Specific Page (Pro)', WP_ADMINIFY_TD), |
| 87 |
'categories_pro' => __('Specific Categories (Pro)', WP_ADMINIFY_TD), |
| 88 |
'custom_posts_pro' => __('Specific Post Types (Pro)', WP_ADMINIFY_TD), |
| 89 |
'tags_pro' => __('Specific Tags (Pro)', WP_ADMINIFY_TD), |
| 90 |
), |
| 91 |
'default' => $this->get_default_field('custom_scripts')['display_on'], |
| 92 |
); |
| 93 |
} |
| 94 |
|
| 95 |
if (jltwp_adminify()->can_use_premium_code__premium_only()) { |
| 96 |
$fields[] = array( |
| 97 |
'id' => 'custom_posts', |
| 98 |
'type' => 'select', |
| 99 |
'title' => __('Select Post', WP_ADMINIFY_TD), |
| 100 |
'placeholder' => __('Select a Post', WP_ADMINIFY_TD), |
| 101 |
'options' => 'posts', |
| 102 |
'dependency' => array('display_on', '==', 's_posts'), |
| 103 |
'default' => $this->get_default_field('custom_scripts')['custom_posts'], |
| 104 |
); |
| 105 |
|
| 106 |
$fields[] = array( |
| 107 |
'id' => 'custom_category', |
| 108 |
'type' => 'select', |
| 109 |
'title' => __('Select Category', WP_ADMINIFY_TD), |
| 110 |
'placeholder' => __('Select a category', WP_ADMINIFY_TD), |
| 111 |
'options' => 'categories', |
| 112 |
'dependency' => array('display_on', '==', 's_categories'), |
| 113 |
'default' => $this->get_default_field('custom_scripts')['custom_category'], |
| 114 |
); |
| 115 |
|
| 116 |
$fields[] = array( |
| 117 |
'id' => 'custom_post_types', |
| 118 |
'type' => 'select', |
| 119 |
'title' => __('Select Post Types', WP_ADMINIFY_TD), |
| 120 |
'placeholder' => __('Select a post type', WP_ADMINIFY_TD), |
| 121 |
'options' => 'post_types', |
| 122 |
'dependency' => array('display_on', '==', 's_custom_posts'), |
| 123 |
'default' => $this->get_default_field('custom_scripts')['custom_post_types'], |
| 124 |
); |
| 125 |
|
| 126 |
$fields[] = array( |
| 127 |
'id' => 'custom_pages', |
| 128 |
'type' => 'select', |
| 129 |
'title' => __('Select Page', WP_ADMINIFY_TD), |
| 130 |
'placeholder' => __('Select a Page', WP_ADMINIFY_TD), |
| 131 |
'options' => 'pages', |
| 132 |
'dependency' => array('display_on', '==', 's_pages'), |
| 133 |
'default' => $this->get_default_field('custom_scripts')['custom_pages'], |
| 134 |
); |
| 135 |
|
| 136 |
$fields[] = array( |
| 137 |
'id' => 'custom_tags', |
| 138 |
'type' => 'select', |
| 139 |
'title' => __('Select Tag', WP_ADMINIFY_TD), |
| 140 |
'placeholder' => __('Select a Tag', WP_ADMINIFY_TD), |
| 141 |
'options' => 'tags', |
| 142 |
'dependency' => array('display_on', '==', 's_tags'), |
| 143 |
'default' => $this->get_default_field('custom_scripts')['custom_tags'], |
| 144 |
); |
| 145 |
} |
| 146 |
|
| 147 |
if (jltwp_adminify()->can_use_premium_code__premium_only()) { |
| 148 |
$fields[] = array( |
| 149 |
'id' => 'location', |
| 150 |
'type' => 'button_set', |
| 151 |
'title' => __('Location', WP_ADMINIFY_TD), |
| 152 |
'options' => array( |
| 153 |
'header' => __('Header', WP_ADMINIFY_TD), |
| 154 |
'before_content' => __('Before Content', WP_ADMINIFY_TD), |
| 155 |
'after_content' => __('After Content', WP_ADMINIFY_TD), |
| 156 |
'footer' => __('Footer', WP_ADMINIFY_TD), |
| 157 |
), |
| 158 |
'default' => $this->get_default_field('custom_scripts')['location'], |
| 159 |
); |
| 160 |
} else { |
| 161 |
$fields[] = array( |
| 162 |
'id' => 'location', |
| 163 |
'type' => 'button_set', |
| 164 |
'title' => __('Location', WP_ADMINIFY_TD), |
| 165 |
'options' => array( |
| 166 |
'header' => __('Header', WP_ADMINIFY_TD), |
| 167 |
'footer' => __('Footer', WP_ADMINIFY_TD), |
| 168 |
'content_before_pro' => __('Before Content (Pro)', WP_ADMINIFY_TD), |
| 169 |
'content_after_pro' => __('After Content (Pro)', WP_ADMINIFY_TD), |
| 170 |
), |
| 171 |
'default' => $this->get_default_field('custom_scripts')['location'], |
| 172 |
); |
| 173 |
} |
| 174 |
|
| 175 |
if (jltwp_adminify()->can_use_premium_code__premium_only()) { |
| 176 |
|
| 177 |
$fields[] = array( |
| 178 |
'id' => 'device_type', |
| 179 |
'type' => 'button_set', |
| 180 |
'title' => __('Display Device', WP_ADMINIFY_TD), |
| 181 |
'options' => array( |
| 182 |
'all_devices' => __('Show on All Devices', WP_ADMINIFY_TD), |
| 183 |
'desktop' => __('Only Desktop', WP_ADMINIFY_TD), |
| 184 |
'mobile' => __('Only Mobile Devices', WP_ADMINIFY_TD), |
| 185 |
), |
| 186 |
'default' => $this->get_default_field('custom_scripts')['device_type'], |
| 187 |
); |
| 188 |
} else { |
| 189 |
$fields[] = array( |
| 190 |
'id' => 'device_type_notice', |
| 191 |
'type' => 'notice', |
| 192 |
'title' => __('Display Device', WP_ADMINIFY_TD), |
| 193 |
'style' => 'warning', |
| 194 |
'content' => Utils::adminify_upgrade_pro() |
| 195 |
); |
| 196 |
} |
| 197 |
|
| 198 |
$fields[] = array( |
| 199 |
'id' => 'script_type', |
| 200 |
'type' => 'button_set', |
| 201 |
'title' => __('Snippet Type', WP_ADMINIFY_TD), |
| 202 |
'options' => array( |
| 203 |
'css' => 'CSS', |
| 204 |
'js' => 'JS' |
| 205 |
), |
| 206 |
'default' => $this->get_default_field('custom_scripts')['script_type'], |
| 207 |
); |
| 208 |
|
| 209 |
$fields[] = array( |
| 210 |
'id' => 'custom_js', |
| 211 |
'type' => 'code_editor', |
| 212 |
'title' => __('Custom JavaScript', WP_ADMINIFY_TD), |
| 213 |
'subtitle' => __('Add your Custom Script here', WP_ADMINIFY_TD), |
| 214 |
'settings' => array( |
| 215 |
'theme' => 'dracula', |
| 216 |
'mode' => 'javascript', |
| 217 |
), |
| 218 |
'dependency' => array('script_type', '==', 'js'), |
| 219 |
'default' => $this->get_default_field('custom_scripts')['custom_js'], |
| 220 |
); |
| 221 |
|
| 222 |
$fields[] = array( |
| 223 |
'id' => 'custom_css', |
| 224 |
'type' => 'code_editor', |
| 225 |
'title' => __('Custom CSS', WP_ADMINIFY_TD), |
| 226 |
'subtitle' => __('Add your Custom CSS here', WP_ADMINIFY_TD), |
| 227 |
'settings' => array( |
| 228 |
'theme' => 'mbo', |
| 229 |
'mode' => 'css', |
| 230 |
), |
| 231 |
'dependency' => array('script_type', '==', 'css'), |
| 232 |
'default' => $this->get_default_field('custom_scripts')['custom_css'], |
| 233 |
); |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
public function custom_header_footer_settings() |
| 238 |
{ |
| 239 |
if (!class_exists('ADMINIFY')) { |
| 240 |
return; |
| 241 |
} |
| 242 |
|
| 243 |
// WP Adminify Custom Header & Footer Options |
| 244 |
\ADMINIFY::createOptions($this->prefix, array( |
| 245 |
|
| 246 |
// Framework Title |
| 247 |
'framework_title' => 'WP Adminify Custom CSS/JS <small>by WP Adminify</small>', |
| 248 |
'framework_class' => 'adminify-custom-css-js', |
| 249 |
|
| 250 |
// menu settings |
| 251 |
'menu_title' => 'Custom CSS / JS', |
| 252 |
'menu_slug' => 'adminify-custom-css-js', |
| 253 |
'menu_type' => 'submenu', // menu, submenu, options, theme, etc. |
| 254 |
'menu_capability' => 'manage_options', |
| 255 |
'menu_icon' => '', |
| 256 |
'menu_position' => 54, |
| 257 |
'menu_hidden' => false, |
| 258 |
'menu_parent' => 'wp-adminify-settings', |
| 259 |
|
| 260 |
// footer |
| 261 |
'footer_text' => ' ', |
| 262 |
'footer_after' => ' ', |
| 263 |
'footer_credit' => ' ', |
| 264 |
|
| 265 |
// menu extras |
| 266 |
'show_bar_menu' => false, |
| 267 |
'show_sub_menu' => false, |
| 268 |
'show_in_network' => false, |
| 269 |
'show_in_customizer' => false, |
| 270 |
|
| 271 |
'show_search' => false, |
| 272 |
'show_reset_all' => false, |
| 273 |
'show_reset_section' => false, |
| 274 |
'show_footer' => true, |
| 275 |
'show_all_options' => true, |
| 276 |
'show_form_warning' => true, |
| 277 |
'sticky_header' => false, |
| 278 |
'save_defaults' => true, |
| 279 |
'ajax_save' => true, |
| 280 |
|
| 281 |
// admin bar menu settings |
| 282 |
'admin_bar_menu_icon' => '', |
| 283 |
'admin_bar_menu_priority' => 45, |
| 284 |
|
| 285 |
|
| 286 |
// database model |
| 287 |
'database' => 'network', // options, transient, theme_mod, network(multisite support) |
| 288 |
'transient_time' => 0, |
| 289 |
|
| 290 |
|
| 291 |
// typography options |
| 292 |
'enqueue_webfont' => true, |
| 293 |
'async_webfont' => false, |
| 294 |
|
| 295 |
// others |
| 296 |
'output_css' => false, |
| 297 |
|
| 298 |
// theme and wrapper classname |
| 299 |
'nav' => 'normal', |
| 300 |
'theme' => 'dark', |
| 301 |
'class' => 'wp-adminify-custom-css-js', |
| 302 |
)); |
| 303 |
|
| 304 |
|
| 305 |
$fields = []; |
| 306 |
$this->custom_header_footer_setting_fields($fields); |
| 307 |
|
| 308 |
|
| 309 |
// Custom CSS/JS Settings |
| 310 |
\ADMINIFY::createSection($this->prefix, array( |
| 311 |
'title' => __('Others', WP_ADMINIFY_TD), |
| 312 |
'icon' => 'fas fa-bolt', |
| 313 |
'fields' => [ |
| 314 |
[ |
| 315 |
'type' => 'subheading', |
| 316 |
'content' => Utils::adminfiy_help_urls( |
| 317 |
__('Header/Footer Snippets', WP_ADMINIFY_TD), |
| 318 |
'https://wpadminify.com/kb/how-to-add-custom-css-or-js-in-full-site-or-specific-page/', |
| 319 |
'https://www.youtube.com/playlist?list=PLqpMw0NsHXV-EKj9Xm1DMGa6FGniHHly8', |
| 320 |
'https://www.facebook.com/groups/jeweltheme', |
| 321 |
'https://wpadminify.com/support/header-footer-scripts/' |
| 322 |
) |
| 323 |
], |
| 324 |
[ |
| 325 |
'id' => 'custom_scripts', |
| 326 |
'type' => 'group', |
| 327 |
'title' => '', |
| 328 |
'accordion_title_prefix' => __('Snippet Name: ', WP_ADMINIFY_TD), |
| 329 |
'accordion_title_number' => true, |
| 330 |
'accordion_title_auto' => true, |
| 331 |
'button_title' => __('Add New Snippet', WP_ADMINIFY_TD), |
| 332 |
'fields' => $fields |
| 333 |
], |
| 334 |
] |
| 335 |
)); |
| 336 |
} |
| 337 |
} |
| 338 |
|