| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPAdminify\Inc\Admin\Options; |
| 4 |
|
| 5 |
use WPAdminify\Inc\Utils; |
| 6 |
use WPAdminify\Inc\Admin\AdminSettingsModel; |
| 7 |
|
| 8 |
|
| 9 |
if (!defined('ABSPATH')) { |
| 10 |
die; |
| 11 |
} // Cannot access directly. |
| 12 |
|
| 13 |
if (!class_exists('CustomCSSJS')) { |
| 14 |
class CustomCSSJS extends AdminSettingsModel |
| 15 |
{ |
| 16 |
|
| 17 |
public $defaults = []; |
| 18 |
|
| 19 |
public function __construct() |
| 20 |
{ |
| 21 |
$this->developer_settings(); |
| 22 |
} |
| 23 |
|
| 24 |
protected function get_defaults() |
| 25 |
{ |
| 26 |
return [ |
| 27 |
'devtools_tabs' => [ |
| 28 |
'custom_css' => '', |
| 29 |
'custom_js' => '', |
| 30 |
] |
| 31 |
]; |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
/** |
| 37 |
* Post Status Columns |
| 38 |
*/ |
| 39 |
|
| 40 |
public function devtools_admin_area_custom_css_js_fields( &$fields ) { |
| 41 |
|
| 42 |
$fields[] = array( |
| 43 |
'id' => 'custom_css', |
| 44 |
'type' => 'code_editor', |
| 45 |
'title' => __( 'Custom CSS', 'adminify' ), |
| 46 |
'subtitle' => __( 'Write your own <strong>Custom CSS</strong> for WordPress Admin Area.', 'adminify' ), |
| 47 |
'desc' => __( 'Don\'t place <style></style> tag inside editor.', 'adminify' ), |
| 48 |
'settings' => array( |
| 49 |
'theme' => 'monokai', |
| 50 |
'mode' => 'css', |
| 51 |
), |
| 52 |
'sanitize' => false, |
| 53 |
'default' => $this->get_default_field('devtools_tabs')['custom_css'], |
| 54 |
); |
| 55 |
|
| 56 |
$fields[] = array( |
| 57 |
'id' => 'custom_js', |
| 58 |
'type' => 'code_editor', |
| 59 |
'title' => __( 'Custom JavaScript', 'adminify' ), |
| 60 |
'subtitle' => __('Write your own <strong>Custom Script</strong> for WordPress Admin Area.', 'adminify' ), |
| 61 |
'desc' => __( 'Don\'t place <script></script> tag inside editor.', 'adminify' ), |
| 62 |
'settings' => array( |
| 63 |
'theme' => 'dracula', |
| 64 |
'mode' => 'javascript', |
| 65 |
), |
| 66 |
'sanitize' => false, |
| 67 |
'default' => $this->get_default_field('devtools_tabs')['custom_js'], |
| 68 |
); |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Maybe Trigger Reset |
| 73 |
* |
| 74 |
* @param [type] $data |
| 75 |
* @param [type] $class |
| 76 |
* |
| 77 |
* @return void |
| 78 |
*/ |
| 79 |
public function maybe_trigger_reset( $data, $class ) { |
| 80 |
|
| 81 |
if ( !empty( $_POST['adminify_transient']['reset'] ) ) { |
| 82 |
|
| 83 |
delete_option( '_wpadminify_custom_js_css' ); |
| 84 |
|
| 85 |
} else if ( !empty( $_POST['adminify_transient']['reset_section'] ) && isset( $_POST['adminify_transient']['section'] ) ) { |
| 86 |
|
| 87 |
$section = $_POST['adminify_transient']['section']; |
| 88 |
if ( $class->pre_sections[ $section - 2 ]['id'] === 'custom_css_js' ) { |
| 89 |
delete_option( '_wpadminify_custom_js_css' ); |
| 90 |
} |
| 91 |
|
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
/** |
| 97 |
* Tabs: Frontend & Backend |
| 98 |
* |
| 99 |
* @param [type] $fields |
| 100 |
* |
| 101 |
* @return void |
| 102 |
*/ |
| 103 |
public function devtools_tabbed_settings( &$fields ){ |
| 104 |
|
| 105 |
$backend_custom_scripts = []; |
| 106 |
$frontend_custom_scripts = []; |
| 107 |
$this->devtools_admin_area_custom_css_js_fields( $backend_custom_scripts ); |
| 108 |
|
| 109 |
if ( !Utils::is_plugin_active( 'adminify-header-footer-scripts/adminify-header-footer-scripts.php' ) ) { |
| 110 |
$frontend_custom_scripts[] = [ |
| 111 |
'type' => 'notice', |
| 112 |
'title' => __(' ', 'adminify'), |
| 113 |
'class' => 'adminify-missing-plugins adminify-one-col', |
| 114 |
'style' => 'warning', |
| 115 |
'content' => Utils::missing_plugin_notice('Custom Header & Footer'), |
| 116 |
]; |
| 117 |
} else { |
| 118 |
|
| 119 |
add_action( "adminify__wpadminify_save_after", [ $this, 'maybe_trigger_reset' ], 10, 2 ); |
| 120 |
|
| 121 |
if ( class_exists( '\WPAdminify\Modules\CustomHeaderFooter\Inc\CustomHeaderFooter\CustomHeaderFooterSettings' ) ) { |
| 122 |
$customHeaderFooterSettings = new \WPAdminify\Modules\CustomHeaderFooter\Inc\CustomHeaderFooter\CustomHeaderFooterSettings(); |
| 123 |
$frontend_custom_scripts = $customHeaderFooterSettings->get_fields(); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
$fields = [ |
| 128 |
[ |
| 129 |
'id' => 'devtools_tabs', |
| 130 |
'type' => 'tabbed', |
| 131 |
'title' => '', |
| 132 |
'tabs' => [ |
| 133 |
[ |
| 134 |
'title' => __( 'Admin Scripts', 'adminify' ), |
| 135 |
'fields' => $backend_custom_scripts, |
| 136 |
], |
| 137 |
[ |
| 138 |
'title' => __( 'Frontend Scripts', 'adminify' ), |
| 139 |
'fields' => $frontend_custom_scripts, |
| 140 |
], |
| 141 |
] |
| 142 |
] |
| 143 |
]; |
| 144 |
} |
| 145 |
|
| 146 |
public function developer_settings() |
| 147 |
{ |
| 148 |
if (!class_exists('ADMINIFY')) { |
| 149 |
return; |
| 150 |
} |
| 151 |
|
| 152 |
$fields = array(); |
| 153 |
$this->devtools_tabbed_settings( $fields ); |
| 154 |
|
| 155 |
// DevTools Section |
| 156 |
\ADMINIFY::createSection( |
| 157 |
$this->prefix, |
| 158 |
[ |
| 159 |
'title' => __('Code Snippets', 'adminify'), |
| 160 |
'id' => 'custom_css_js', |
| 161 |
'icon' => 'fas fa-code', |
| 162 |
'fields' => $fields, |
| 163 |
] |
| 164 |
); |
| 165 |
} |
| 166 |
} |
| 167 |
} |
| 168 |
|