| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPCoder; |
| 4 |
|
| 5 |
use WPCoder\Admin\AdminInitializer; |
| 6 |
use WPCoder\Dashboard\DashboardInitializer; |
| 7 |
|
| 8 |
defined( 'ABSPATH' ) || exit; |
| 9 |
|
| 10 |
class WOWP_Dashboard { |
| 11 |
|
| 12 |
public function __construct() { |
| 13 |
add_action( WOW_Plugin::PREFIX . '_admin_load_styles_scripts', [ $this, 'load_styles_scripts' ] ); |
| 14 |
add_action( WOW_Plugin::PREFIX . '_admin_page', [ $this, 'dashboard' ] ); |
| 15 |
add_action( WOW_Plugin::PREFIX . '_admin_header_links', [ $this, 'header_links' ] ); |
| 16 |
add_filter( WOW_Plugin::PREFIX . '_save_settings', [ $this, 'save_settings' ], 10, 2 ); |
| 17 |
add_filter( WOW_Plugin::PREFIX . '_default_custom_post', [ $this, 'default_custom_post' ] ); |
| 18 |
|
| 19 |
AdminInitializer::init(); |
| 20 |
} |
| 21 |
|
| 22 |
public function default_custom_post( $display_def ) { |
| 23 |
if ( str_contains( $display_def, 'custom_post_selected' ) ) { |
| 24 |
return 'post_selected'; |
| 25 |
} |
| 26 |
if ( str_contains( $display_def, 'custom_post_tax' ) ) { |
| 27 |
return 'post_category'; |
| 28 |
} |
| 29 |
if ( str_contains( $display_def, 'custom_post_all' ) ) { |
| 30 |
return 'post_all'; |
| 31 |
} |
| 32 |
|
| 33 |
return $display_def; |
| 34 |
} |
| 35 |
|
| 36 |
private function allowed_html() { |
| 37 |
$tags = wp_kses_allowed_html( 'post' ); |
| 38 |
|
| 39 |
$additional_tags = [ |
| 40 |
'input' => [ |
| 41 |
'accept', |
| 42 |
'alt', |
| 43 |
'autocomplete', |
| 44 |
'autofocus', |
| 45 |
'checked', |
| 46 |
'dirname', |
| 47 |
'disabled', |
| 48 |
'form', |
| 49 |
'formaction', |
| 50 |
'formenctype', |
| 51 |
'formmethod', |
| 52 |
'formnovalidate', |
| 53 |
'formtarget', |
| 54 |
'height', |
| 55 |
'inputmode', |
| 56 |
'list', |
| 57 |
'max', |
| 58 |
'maxlength', |
| 59 |
'min', |
| 60 |
'minlength', |
| 61 |
'multiple', |
| 62 |
'name', |
| 63 |
'pattern', |
| 64 |
'placeholder', |
| 65 |
'readonly', |
| 66 |
'required', |
| 67 |
'size', |
| 68 |
'src', |
| 69 |
'step', |
| 70 |
'type', |
| 71 |
'value', |
| 72 |
'width' |
| 73 |
], |
| 74 |
'select' => [ |
| 75 |
'autofocus', |
| 76 |
'disabled', |
| 77 |
'form', |
| 78 |
'multiple', |
| 79 |
'name', |
| 80 |
'required', |
| 81 |
'size' |
| 82 |
], |
| 83 |
'option' => [ |
| 84 |
'disabled', |
| 85 |
'label', |
| 86 |
'selected', |
| 87 |
'value' |
| 88 |
], |
| 89 |
'form' => [ |
| 90 |
'action', |
| 91 |
'accept', |
| 92 |
'accept-charset', |
| 93 |
'enctype', |
| 94 |
'method', |
| 95 |
'name', |
| 96 |
'target' |
| 97 |
], |
| 98 |
'iframe' => [ |
| 99 |
'align', |
| 100 |
'allow', |
| 101 |
'allowfullscreen', |
| 102 |
'allowpaymentrequest', |
| 103 |
'allowusermedia', |
| 104 |
'csp', |
| 105 |
'height', |
| 106 |
'importance', |
| 107 |
'loading', |
| 108 |
'name', |
| 109 |
'referrerpolicy', |
| 110 |
'sandbox', |
| 111 |
'src', |
| 112 |
'srcdoc', |
| 113 |
'width', |
| 114 |
'frameborder', |
| 115 |
'longdesc', |
| 116 |
'marginheight', |
| 117 |
'marginwidth', |
| 118 |
'scrolling' |
| 119 |
], |
| 120 |
]; |
| 121 |
|
| 122 |
foreach ( $additional_tags as $tag => $attributes ) { |
| 123 |
$tags[ $tag ] = array_fill_keys( $attributes, true ); |
| 124 |
} |
| 125 |
|
| 126 |
return $tags; |
| 127 |
} |
| 128 |
|
| 129 |
public function save_settings( $settings, $request ): array { |
| 130 |
$param = ! empty( $request['param'] ) ? map_deep( $request['param'], [ $this, 'sanitize_param' ] ) : []; |
| 131 |
|
| 132 |
$settings['data']['title'] = ! empty( $request['title'] ) ? sanitize_text_field( wp_unslash( $request['title'] ) ) : ''; |
| 133 |
$settings['formats'][] = '%s'; |
| 134 |
$settings['data']['html_code'] = ! empty( $request['html_code'] ) ? wp_unslash( $request['html_code'] ) : ''; |
| 135 |
$settings['formats'][] = '%s'; |
| 136 |
$settings['data']['css_code'] = ! empty( $request['css_code'] ) ? wp_unslash( $request['css_code'] ) : ''; |
| 137 |
$settings['formats'][] = '%s'; |
| 138 |
$settings['data']['js_code'] = ! empty( $request['js_code'] ) ? wp_unslash( $request['js_code'] ) : ''; |
| 139 |
$settings['formats'][] = '%s'; |
| 140 |
$settings['data']['status'] = ! empty( $request['status'] ) ? sanitize_textarea_field( wp_unslash( $request['status'] ) ) : ''; |
| 141 |
$settings['formats'][] = '%d'; |
| 142 |
$settings['data']['mode'] = ! empty( $request['mode'] ) ? sanitize_textarea_field( wp_unslash( $request['mode'] ) ) : ''; |
| 143 |
$settings['formats'][] = '%d'; |
| 144 |
$settings['data']['tag'] = ! empty( $request['tag'] ) ? sanitize_textarea_field( wp_unslash( $request['tag'] ) ) : ''; |
| 145 |
$settings['formats'][] = '%s'; |
| 146 |
|
| 147 |
if ( ! empty( $request['param']['include_file'] ) ) { |
| 148 |
$param['include_file'] = ! empty( $request['param']['include_file'] ) ? map_deep( $request['param']['include_file'], |
| 149 |
'esc_url' ) : []; |
| 150 |
} |
| 151 |
|
| 152 |
$settings['data']['param'] = maybe_serialize( $param ); |
| 153 |
$settings['formats'][] = '%s'; |
| 154 |
|
| 155 |
return $settings; |
| 156 |
} |
| 157 |
|
| 158 |
public function sanitize_param( $value ) { |
| 159 |
return wp_unslash( sanitize_text_field( $value ) ); |
| 160 |
} |
| 161 |
|
| 162 |
public function load_styles_scripts(): void { |
| 163 |
$assets_url = WOW_Plugin::url() . 'assets/'; |
| 164 |
$version = WOW_Plugin::VERSION; |
| 165 |
$slug = WOW_Plugin::SLUG; |
| 166 |
|
| 167 |
wp_enqueue_style( $slug . '-admin', $assets_url . 'css/admin.css', null, $version ); |
| 168 |
|
| 169 |
wp_enqueue_style( $slug . '-admin-icons', $assets_url . 'icons/wowpicon/css/style.css', null, $version ); |
| 170 |
|
| 171 |
wp_enqueue_script( 'code-editor' ); |
| 172 |
wp_enqueue_style( 'code-editor' ); |
| 173 |
wp_enqueue_script( 'htmlhint' ); |
| 174 |
wp_enqueue_script( 'csslint' ); |
| 175 |
wp_enqueue_script( 'jshint' ); |
| 176 |
|
| 177 |
wp_enqueue_script( $slug . '-admin', $assets_url . 'js/admin.js', array( 'jquery' ), $version ); |
| 178 |
} |
| 179 |
|
| 180 |
public function dashboard(): void { |
| 181 |
DashboardInitializer::init(); |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
public function header_links(): void { |
| 186 |
$logo = WOW_Plugin::url() . 'assets/img/wow-icon.png'; |
| 187 |
?> |
| 188 |
<div class="wowp-links"> |
| 189 |
<a href="https://wow-estore.com/" target="_blank"> |
| 190 |
<img src="<?php |
| 191 |
echo esc_url( $logo ); ?>" alt="Logo Wow-Estore.com"> |
| 192 |
<span>Wow-Estore</span> |
| 193 |
</a> |
| 194 |
<a href="https://wow-estore.com/guides/wp-coder/" target="_blank"> |
| 195 |
<span class="dashicons dashicons-book-alt"></span> |
| 196 |
<span>Docs</span> |
| 197 |
</a> |
| 198 |
<a href="https://wordpress.org/support/plugin/wp-coder/reviews/" target="_blank"> |
| 199 |
<span class="dashicons dashicons-star-filled"></span> |
| 200 |
<span>Reviews</span> |
| 201 |
</a> |
| 202 |
</div> |
| 203 |
|
| 204 |
<?php |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
} |