| 1 |
<?php |
| 2 |
|
| 3 |
namespace FloatingButton; |
| 4 |
|
| 5 |
use FloatingButton\Admin\AdminInitializer; |
| 6 |
use FloatingButton\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 |
public function save_settings( $settings, $request ): array { |
| 37 |
$param = ! empty( $request['param'] ) ? map_deep( $request['param'], [ $this, 'sanitize_param' ] ) : []; |
| 38 |
|
| 39 |
$settings['data']['title'] = ! empty( $request['title'] ) ? sanitize_text_field( wp_unslash( $request['title'] ) ) : ''; |
| 40 |
$settings['formats'][] = '%s'; |
| 41 |
|
| 42 |
$settings['data']['status'] = ! empty( $request['status'] ) ? sanitize_textarea_field( wp_unslash( $request['status'] ) ) : ''; |
| 43 |
$settings['formats'][] = '%d'; |
| 44 |
|
| 45 |
$settings['data']['mode'] = ! empty( $request['mode'] ) ? sanitize_textarea_field( wp_unslash( $request['mode'] ) ) : ''; |
| 46 |
$settings['formats'][] = '%d'; |
| 47 |
|
| 48 |
$settings['data']['tag'] = ! empty( $request['tag'] ) ? sanitize_textarea_field( wp_unslash( $request['tag'] ) ) : ''; |
| 49 |
$settings['formats'][] = '%s'; |
| 50 |
|
| 51 |
|
| 52 |
$param = $this->additional_sanitize( $param, $request['param'] ); |
| 53 |
$settings['data']['param'] = maybe_serialize( $param ); |
| 54 |
$settings['formats'][] = '%s'; |
| 55 |
|
| 56 |
return $settings; |
| 57 |
} |
| 58 |
|
| 59 |
public function additional_sanitize( $param, $arr ) { |
| 60 |
// For main button |
| 61 |
if ( isset( $arr['extra_style'] ) ) { |
| 62 |
$param['extra_style'] = sanitize_textarea_field( wp_unslash( $arr['extra_style'] ) ); |
| 63 |
} |
| 64 |
if ( isset( $arr['item_link'] ) ) { |
| 65 |
$param['item_link'] = sanitize_url( $arr['item_link'] ); |
| 66 |
} |
| 67 |
|
| 68 |
if ( isset( $arr['custom_icon_url'] ) ) { |
| 69 |
$param['custom_icon_url'] = sanitize_url( $arr['custom_icon_url'] ); |
| 70 |
} |
| 71 |
|
| 72 |
if ( isset( $arr['custom_icon_emoji'] ) ) { |
| 73 |
$param['custom_icon_emoji'] = wp_kses_post( wp_encode_emoji( $arr['custom_icon_emoji'] ) ); |
| 74 |
} |
| 75 |
|
| 76 |
// For menu 1 |
| 77 |
if ( isset( $arr['menu_1']['item_link'] ) && is_array( $arr['menu_1']['item_link'] ) ) { |
| 78 |
$param['menu_1']['item_link'] = map_deep( $arr['menu_1']['item_link'], 'sanitize_url' ); |
| 79 |
} |
| 80 |
|
| 81 |
if ( isset( $arr['menu_1']['custom_icon_url'] ) && is_array( $arr['menu_1']['custom_icon_url'] ) ) { |
| 82 |
$param['menu_1']['custom_icon_url'] = map_deep( $arr['menu_1']['custom_icon_url'], 'sanitize_url' ); |
| 83 |
} |
| 84 |
|
| 85 |
if ( isset( $arr['menu_1']['custom_icon_emoji'] ) && is_array( $arr['menu_1']['custom_icon_emoji'] ) ) { |
| 86 |
$param['menu_1']['custom_icon_emoji'] = map_deep( $arr['menu_1']['custom_icon_emoji'], [ |
| 87 |
$this, |
| 88 |
'sanitize_emoji' |
| 89 |
] ); |
| 90 |
} |
| 91 |
|
| 92 |
// For menu 2 |
| 93 |
if ( isset( $arr['menu_2']['item_link'] ) && is_array( $arr['menu_2']['item_link'] ) ) { |
| 94 |
$param['menu_2']['item_link'] = map_deep( $arr['menu_2']['item_link'], 'sanitize_url' ); |
| 95 |
} |
| 96 |
|
| 97 |
if ( isset( $arr['menu_2']['custom_icon_url'] ) && is_array( $arr['menu_2']['custom_icon_url'] ) ) { |
| 98 |
$param['menu_2']['custom_icon_url'] = map_deep( $arr['menu_2']['custom_icon_url'], 'sanitize_url' ); |
| 99 |
} |
| 100 |
|
| 101 |
if ( isset( $arr['menu_2']['custom_icon_emoji'] ) && is_array( $arr['menu_2']['custom_icon_emoji'] ) ) { |
| 102 |
$param['menu_2']['custom_icon_emoji'] = map_deep( $arr['menu_2']['custom_icon_emoji'], [ |
| 103 |
$this, |
| 104 |
'sanitize_emoji' |
| 105 |
] ); |
| 106 |
} |
| 107 |
|
| 108 |
return $param; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
public function sanitize_emoji( $text ): string { |
| 113 |
return wp_kses_post( wp_encode_emoji( wp_unslash( $text ) ) ); |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
public function sanitize_param( $value ): string { |
| 118 |
return sanitize_text_field( wp_unslash( $value ) ); |
| 119 |
} |
| 120 |
|
| 121 |
public function load_styles_scripts(): void { |
| 122 |
$assets_url = WOW_Plugin::url() . 'assets/'; |
| 123 |
$version = WOW_Plugin::info( 'version' ); |
| 124 |
$slug = WOW_Plugin::SLUG; |
| 125 |
|
| 126 |
wp_enqueue_style( $slug . '-admin', $assets_url . 'css/admin.css', null, $version ); |
| 127 |
|
| 128 |
wp_enqueue_style( $slug . '-admin-fontawesome', $assets_url . 'vendors/fontawesome/css/fontawesome-all.min.css', |
| 129 |
null, '6.6' ); |
| 130 |
|
| 131 |
// include fonticonpicker styles & scripts |
| 132 |
|
| 133 |
|
| 134 |
$fonticonpicker_css = $assets_url . 'vendors/fonticonpicker/jquery.fonticonpicker.min.css'; |
| 135 |
wp_enqueue_style( $slug . '-fonticonpicker', $fonticonpicker_css, null, $version ); |
| 136 |
|
| 137 |
$fonticonpicker_dark_css = $assets_url . 'vendors/fonticonpicker/jquery.fonticonpicker.grey.min.css'; |
| 138 |
wp_enqueue_style( $slug . '-fonticonpicker-darkgrey', $fonticonpicker_dark_css, null, $version ); |
| 139 |
|
| 140 |
$fonticonpicker_js = $assets_url . 'vendors/fonticonpicker/jquery.fonticonpicker.js'; |
| 141 |
wp_enqueue_script( $slug . '-fonticonpicker', $fonticonpicker_js, [ 'jquery' ], $version, true ); |
| 142 |
|
| 143 |
// include the color picker |
| 144 |
wp_enqueue_script( 'code-editor' ); |
| 145 |
wp_enqueue_style( 'code-editor' ); |
| 146 |
wp_enqueue_script( 'csslint' ); |
| 147 |
|
| 148 |
wp_enqueue_style( 'wp-color-picker' ); |
| 149 |
wp_enqueue_script( 'wp-color-picker' ); |
| 150 |
wp_enqueue_media(); |
| 151 |
|
| 152 |
wp_enqueue_script( 'jquery-ui-sortable' ); |
| 153 |
|
| 154 |
$url_alpha = $assets_url . 'js/wp-color-picker-alpha.js'; |
| 155 |
wp_enqueue_script( 'wp-color-picker-alpha', $url_alpha, array( 'wp-color-picker' ), '3.0.0', true ); |
| 156 |
|
| 157 |
|
| 158 |
wp_enqueue_script( $slug . '-admin-jquery', $assets_url . 'js/admin-jquery.js', [ |
| 159 |
'jquery', |
| 160 |
'wp-color-picker-alpha' |
| 161 |
], $version, true ); |
| 162 |
} |
| 163 |
|
| 164 |
public function dashboard(): void { |
| 165 |
DashboardInitializer::init(); |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
public function header_links(): void { |
| 170 |
// phpcs:disable PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage |
| 171 |
$logo = WOW_Plugin::url() . 'assets/img/wow-icon.png'; |
| 172 |
?> |
| 173 |
<div class="wowp-links"> |
| 174 |
<a href="https://wow-estore.com/" target="_blank"> |
| 175 |
<img src="<?php |
| 176 |
echo esc_url( $logo ); ?>" alt="Logo Wow-Estore.com"> |
| 177 |
<span>Wow-Estore</span> |
| 178 |
</a> |
| 179 |
<a href="https://wow-estore.com/guides/floating-button/" target="_blank"> |
| 180 |
<span class="dashicons dashicons-book-alt"></span> |
| 181 |
<span>Docs</span> |
| 182 |
</a> |
| 183 |
<a href="https://wordpress.org/support/plugin/floating-button/reviews/?filter=5" target="_blank"> |
| 184 |
<span class="dashicons dashicons-star-filled"></span> |
| 185 |
<span>Reviews</span> |
| 186 |
</a> |
| 187 |
</div> |
| 188 |
|
| 189 |
<?php |
| 190 |
// phpcs:enable |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
} |