| 1 |
<?php |
| 2 |
/** |
| 3 |
* Upgrade routine for v4.3.0 — Font Awesome icon values migrated to Dashicons. |
| 4 |
* |
| 5 |
* The Dashboard Widget and Pro Admin Page icon fields now use the shared WP |
| 6 |
* Adminify icon picker (Dashicons, Simple Line Icons, Custom Icons), which no |
| 7 |
* longer offers Font Awesome. Values saved by the old Font Awesome modal would |
| 8 |
* render as a blank square, so they are rewritten to the closest Dashicon here. |
| 9 |
* |
| 10 |
* Mapping is best-effort: anything without a sensible equivalent falls back to |
| 11 |
* `dashicons-admin-generic` rather than being left broken or emptied. |
| 12 |
* |
| 13 |
* This file is included by PXLBSAdminify\Inc\Classes\Upgrade::run_updates(). |
| 14 |
* |
| 15 |
* @package Adminify |
| 16 |
*/ |
| 17 |
|
| 18 |
if ( ! defined( 'ABSPATH' ) ) { |
| 19 |
exit; // Exit if accessed directly. |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Font Awesome class (without the style prefix) => Dashicons class. |
| 24 |
* |
| 25 |
* @return array<string, string> |
| 26 |
*/ |
| 27 |
function pxlbsadminify_fa_to_dashicons_map() { |
| 28 |
return array( |
| 29 |
'fa-address-book' => 'dashicons dashicons-id', |
| 30 |
'fa-address-card' => 'dashicons dashicons-id-alt', |
| 31 |
'fa-arrow-down' => 'dashicons dashicons-arrow-down-alt', |
| 32 |
'fa-arrow-left' => 'dashicons dashicons-arrow-left-alt', |
| 33 |
'fa-arrow-right' => 'dashicons dashicons-arrow-right-alt', |
| 34 |
'fa-arrow-up' => 'dashicons dashicons-arrow-up-alt', |
| 35 |
'fa-bars' => 'dashicons dashicons-menu', |
| 36 |
'fa-bell' => 'dashicons dashicons-bell', |
| 37 |
'fa-bolt' => 'dashicons dashicons-performance', |
| 38 |
'fa-book' => 'dashicons dashicons-book', |
| 39 |
'fa-briefcase' => 'dashicons dashicons-portfolio', |
| 40 |
'fa-brush' => 'dashicons dashicons-art', |
| 41 |
'fa-bug' => 'dashicons dashicons-warning', |
| 42 |
'fa-business-time' => 'dashicons dashicons-clock', |
| 43 |
'fa-calendar' => 'dashicons dashicons-calendar-alt', |
| 44 |
'fa-calendar-alt' => 'dashicons dashicons-calendar-alt', |
| 45 |
'fa-camera' => 'dashicons dashicons-camera', |
| 46 |
'fa-cart-plus' => 'dashicons dashicons-cart', |
| 47 |
'fa-chart-area' => 'dashicons dashicons-chart-area', |
| 48 |
'fa-chart-bar' => 'dashicons dashicons-chart-bar', |
| 49 |
'fa-chart-line' => 'dashicons dashicons-chart-line', |
| 50 |
'fa-chart-pie' => 'dashicons dashicons-chart-pie', |
| 51 |
'fa-check' => 'dashicons dashicons-yes', |
| 52 |
'fa-check-circle' => 'dashicons dashicons-yes-alt', |
| 53 |
'fa-clock' => 'dashicons dashicons-clock', |
| 54 |
'fa-clone' => 'dashicons dashicons-admin-page', |
| 55 |
'fa-code' => 'dashicons dashicons-editor-code', |
| 56 |
'fa-cog' => 'dashicons dashicons-admin-generic', |
| 57 |
'fa-cogs' => 'dashicons dashicons-admin-settings', |
| 58 |
'fa-comment' => 'dashicons dashicons-admin-comments', |
| 59 |
'fa-comments' => 'dashicons dashicons-admin-comments', |
| 60 |
'fa-copyright' => 'dashicons dashicons-admin-site', |
| 61 |
'fa-database' => 'dashicons dashicons-database', |
| 62 |
'fa-desktop' => 'dashicons dashicons-desktop', |
| 63 |
'fa-download' => 'dashicons dashicons-download', |
| 64 |
'fa-edit' => 'dashicons dashicons-edit', |
| 65 |
'fa-envelope' => 'dashicons dashicons-email', |
| 66 |
'fa-exclamation' => 'dashicons dashicons-warning', |
| 67 |
'fa-eye' => 'dashicons dashicons-visibility', |
| 68 |
'fa-file' => 'dashicons dashicons-media-default', |
| 69 |
'fa-file-alt' => 'dashicons dashicons-media-text', |
| 70 |
'fa-fill-drip' => 'dashicons dashicons-art', |
| 71 |
'fa-filter' => 'dashicons dashicons-filter', |
| 72 |
'fa-flag' => 'dashicons dashicons-flag', |
| 73 |
'fa-folder' => 'dashicons dashicons-portfolio', |
| 74 |
'fa-gear' => 'dashicons dashicons-admin-generic', |
| 75 |
'fa-gears' => 'dashicons dashicons-admin-settings', |
| 76 |
'fa-globe' => 'dashicons dashicons-admin-site', |
| 77 |
'fa-heart' => 'dashicons dashicons-heart', |
| 78 |
'fa-home' => 'dashicons dashicons-admin-home', |
| 79 |
'fa-image' => 'dashicons dashicons-format-image', |
| 80 |
'fa-images' => 'dashicons dashicons-format-gallery', |
| 81 |
'fa-info' => 'dashicons dashicons-info', |
| 82 |
'fa-info-circle' => 'dashicons dashicons-info', |
| 83 |
'fa-key' => 'dashicons dashicons-admin-network', |
| 84 |
'fa-layer-group' => 'dashicons dashicons-layout', |
| 85 |
'fa-link' => 'dashicons dashicons-admin-links', |
| 86 |
'fa-list' => 'dashicons dashicons-editor-ul', |
| 87 |
'fa-lock' => 'dashicons dashicons-lock', |
| 88 |
'fa-map-marker' => 'dashicons dashicons-location', |
| 89 |
'fa-map-marker-alt' => 'dashicons dashicons-location-alt', |
| 90 |
'fa-microphone' => 'dashicons dashicons-microphone', |
| 91 |
'fa-mobile' => 'dashicons dashicons-smartphone', |
| 92 |
'fa-music' => 'dashicons dashicons-format-audio', |
| 93 |
'fa-newspaper' => 'dashicons dashicons-admin-post', |
| 94 |
'fa-outdent' => 'dashicons dashicons-editor-outdent', |
| 95 |
'fa-paint-brush' => 'dashicons dashicons-art', |
| 96 |
'fa-paperclip' => 'dashicons dashicons-paperclip', |
| 97 |
'fa-pencil-alt' => 'dashicons dashicons-edit', |
| 98 |
'fa-phone' => 'dashicons dashicons-phone', |
| 99 |
'fa-play' => 'dashicons dashicons-controls-play', |
| 100 |
'fa-plug' => 'dashicons dashicons-admin-plugins', |
| 101 |
'fa-plus' => 'dashicons dashicons-plus', |
| 102 |
'fa-plus-circle' => 'dashicons dashicons-plus-alt', |
| 103 |
'fa-question-circle' => 'dashicons dashicons-editor-help', |
| 104 |
'fa-quote-left' => 'dashicons dashicons-format-quote', |
| 105 |
'fa-random' => 'dashicons dashicons-randomize', |
| 106 |
'fa-redo' => 'dashicons dashicons-update', |
| 107 |
'fa-rocket' => 'dashicons dashicons-performance', |
| 108 |
'fa-rss' => 'dashicons dashicons-rss', |
| 109 |
'fa-search' => 'dashicons dashicons-search', |
| 110 |
'fa-server' => 'dashicons dashicons-database', |
| 111 |
'fa-share' => 'dashicons dashicons-share', |
| 112 |
'fa-shield-alt' => 'dashicons dashicons-shield', |
| 113 |
'fa-shopping-cart' => 'dashicons dashicons-cart', |
| 114 |
'fa-sign-out-alt' => 'dashicons dashicons-exit', |
| 115 |
'fa-star' => 'dashicons dashicons-star-filled', |
| 116 |
'fa-sync' => 'dashicons dashicons-update', |
| 117 |
'fa-tag' => 'dashicons dashicons-tag', |
| 118 |
'fa-tags' => 'dashicons dashicons-tag', |
| 119 |
'fa-times' => 'dashicons dashicons-no-alt', |
| 120 |
'fa-tools' => 'dashicons dashicons-admin-tools', |
| 121 |
'fa-trash' => 'dashicons dashicons-trash', |
| 122 |
'fa-trash-alt' => 'dashicons dashicons-trash', |
| 123 |
'fa-upload' => 'dashicons dashicons-upload', |
| 124 |
'fa-user' => 'dashicons dashicons-admin-users', |
| 125 |
'fa-users' => 'dashicons dashicons-groups', |
| 126 |
'fa-video' => 'dashicons dashicons-format-video', |
| 127 |
'fa-wordpress' => 'dashicons dashicons-wordpress', |
| 128 |
'fa-wrench' => 'dashicons dashicons-admin-tools', |
| 129 |
); |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* Convert a single stored icon value. |
| 134 |
* |
| 135 |
* @param mixed $value Stored icon value. |
| 136 |
* @return mixed Converted value, or the original when it is not a Font Awesome class. |
| 137 |
*/ |
| 138 |
function pxlbsadminify_convert_fa_icon_value( $value ) { |
| 139 |
|
| 140 |
if ( ! is_string( $value ) || '' === $value ) { |
| 141 |
return $value; |
| 142 |
} |
| 143 |
|
| 144 |
// Only touch Font Awesome classes: "fa fa-gear", "fas fa-rocket", "far fa-clone". |
| 145 |
if ( ! preg_match( '/(?:^|\s)fa[bsrl]?\s+fa-([a-z0-9-]+)/i', $value, $matches ) ) { |
| 146 |
return $value; |
| 147 |
} |
| 148 |
|
| 149 |
$map = pxlbsadminify_fa_to_dashicons_map(); |
| 150 |
$slug = 'fa-' . strtolower( $matches[1] ); |
| 151 |
|
| 152 |
return isset( $map[ $slug ] ) ? $map[ $slug ] : 'dashicons dashicons-admin-generic'; |
| 153 |
} |
| 154 |
|
| 155 |
/** |
| 156 |
* Walk an array and convert every Font Awesome icon value found in it. |
| 157 |
* |
| 158 |
* @param mixed $data Data to walk. |
| 159 |
* @param bool $changed Set to true when anything was rewritten. |
| 160 |
* @return mixed |
| 161 |
*/ |
| 162 |
function pxlbsadminify_convert_fa_icons_deep( $data, &$changed ) { |
| 163 |
|
| 164 |
if ( is_array( $data ) ) { |
| 165 |
foreach ( $data as $key => $item ) { |
| 166 |
$data[ $key ] = pxlbsadminify_convert_fa_icons_deep( $item, $changed ); |
| 167 |
} |
| 168 |
|
| 169 |
return $data; |
| 170 |
} |
| 171 |
|
| 172 |
$converted = pxlbsadminify_convert_fa_icon_value( $data ); |
| 173 |
|
| 174 |
if ( $converted !== $data ) { |
| 175 |
$changed = true; |
| 176 |
} |
| 177 |
|
| 178 |
return $converted; |
| 179 |
} |
| 180 |
|
| 181 |
/** |
| 182 |
* Run the one-time Font Awesome to Dashicons migration. |
| 183 |
* |
| 184 |
* Idempotent: guarded by the "pxlbsadminify_fa_icons_migrated" flag. Upgrade::run_updates() |
| 185 |
* does not advance the stored version, so every routine must guard itself. |
| 186 |
* |
| 187 |
* @return void |
| 188 |
*/ |
| 189 |
function pxlbsadminify_migrate_fa_icons_to_dashicons() { |
| 190 |
|
| 191 |
if ( get_option( 'pxlbsadminify_fa_icons_migrated' ) ) { |
| 192 |
return; |
| 193 |
} |
| 194 |
|
| 195 |
// Dashboard widget icons (and any Font Awesome markup in widget bodies is left |
| 196 |
// alone — only stored icon field values are converted, and the deep walk only |
| 197 |
// rewrites values that are entirely a Font Awesome class). |
| 198 |
$widgets = get_option( 'pxlbsadminify_dasboard_widgets' ); |
| 199 |
|
| 200 |
if ( ! empty( $widgets ) && is_array( $widgets ) ) { |
| 201 |
$changed = false; |
| 202 |
$updated = pxlbsadminify_convert_fa_icons_deep( $widgets, $changed ); |
| 203 |
|
| 204 |
if ( $changed ) { |
| 205 |
update_option( 'pxlbsadminify_dasboard_widgets', $updated ); |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
// Pro admin page menu icons. |
| 210 |
$admin_pages = get_posts( |
| 211 |
array( |
| 212 |
'post_type' => 'adminify_admin_page', |
| 213 |
'post_status' => 'any', |
| 214 |
'numberposts' => -1, |
| 215 |
'fields' => 'ids', |
| 216 |
'suppress_filters' => false, |
| 217 |
) |
| 218 |
); |
| 219 |
|
| 220 |
if ( ! empty( $admin_pages ) ) { |
| 221 |
foreach ( $admin_pages as $page_id ) { |
| 222 |
$icon = get_post_meta( $page_id, 'pxlbsadminify_menu_icon', true ); |
| 223 |
|
| 224 |
if ( empty( $icon ) || ! is_string( $icon ) ) { |
| 225 |
continue; |
| 226 |
} |
| 227 |
|
| 228 |
$converted = pxlbsadminify_convert_fa_icon_value( $icon ); |
| 229 |
|
| 230 |
if ( $converted !== $icon ) { |
| 231 |
update_post_meta( $page_id, 'pxlbsadminify_menu_icon', $converted ); |
| 232 |
} |
| 233 |
} |
| 234 |
} |
| 235 |
|
| 236 |
update_option( 'pxlbsadminify_fa_icons_migrated', true ); |
| 237 |
} |
| 238 |
|
| 239 |
pxlbsadminify_migrate_fa_icons_to_dashicons(); |
| 240 |
|