PluginProbe
Icon Element – Icon Pack for Elementor Page Builder (6718 icons) / trunk
Icon Element – Icon Pack for Elementor Page Builder (6718 icons) vtrunk
icon-element / admin / iconelement-admin.php

iconelement-admin.php in Icon Element – Icon Pack for Elementor Page Builder (6718 icons) trunk, at admin/iconelement-admin.php

804 lines 26.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 define( 'RAP_VERSION', '7.1.0' );
8
9 // List of WordPress.org authors to fetch plugins from.
10 define( 'RAP_AUTHORS', array( 'softtent', 'webangon' ) ); // Customize as needed.
11
12 require_once ICON_ELEM_DIR . 'admin/class-rap-plugin-fetcher.php';
13 require_once ICON_ELEM_DIR . 'admin/class-rap-plugin-installer.php';
14
15 /**
16 * Register admin menu page.
17 */
18 function rap_add_admin_menu() {
19 add_menu_page(
20 __( 'Icon Element Panel', 'iconelement' ),
21 __( 'Icon Element', 'iconelement' ),
22 'manage_options',
23 'iconelement',
24 'rap_render_admin_page',
25 'dashicons-admin-generic',
26 30
27 );
28 }
29 add_action( 'admin_menu', 'rap_add_admin_menu' );
30
31 /**
32 * Render container for React app.
33 */
34 function rap_render_admin_page() {
35 ?>
36 <div class="wrap">
37 <div class="rap-page-wrap">
38 <div id="rap-root"></div>
39 </div>
40 </div>
41 <?php
42 }
43
44 /**
45 * Get all icon sets with metadata.
46 *
47 * @return array
48 */
49 function rap_get_icon_sets() {
50 return array(
51 // Free (28)
52 array(
53 'id' => 'ie-material-design',
54 'name' => 'Material Design (931 icons)',
55 'pro' => false,
56 'preview' => 'https://material.io/resources/icons/?style=baseline',
57 ),
58 array(
59 'id' => 'ie-academic',
60 'name' => 'Academic (73 icons)',
61 'pro' => false,
62 'preview' => 'https://jpswalsh.github.io/academicons/',
63 ),
64 array(
65 'id' => 'ie-phosphor-light',
66 'name' => 'Phosphor light (931 icons)',
67 'pro' => false,
68 'preview' => 'https://phosphoricons.com/?weight=%22light%22',
69 ),
70 array(
71 'id' => 'ie-metrize',
72 'name' => 'Metrize (299 icons)',
73 'pro' => false,
74 'preview' => 'http://www.alessioatzeni.com/metrize-icons/',
75 ),
76 array(
77 'id' => 'ie-captain',
78 'name' => 'Captain (374 icons)',
79 'pro' => false,
80 'preview' => 'https://mariodelvalle.github.io/CaptainIconWeb/',
81 ),
82 array(
83 'id' => 'ie-ionicons',
84 'name' => 'Ionicons (695 icons)',
85 'pro' => false,
86 'preview' => 'https://ionicons.com/',
87 ),
88 array(
89 'id' => 'ie-dripicons-icons',
90 'name' => 'Dripicons Icons (199 icons)',
91 'pro' => false,
92 'preview' => 'http://demo.amitjakhu.com/dripicons/',
93 ),
94 array(
95 'id' => 'ie-simpline',
96 'name' => 'Simpline (188 icons)',
97 'pro' => false,
98 'preview' => 'https://github.com/thesabbir/simple-line-icons',
99 ),
100 array(
101 'id' => 'ie-wppagebuilder',
102 'name' => 'Wp Pagebuilder (344 icons)',
103 'pro' => false,
104 'preview' => 'https://builder.themeum.com/wppbicon/',
105 ),
106 array(
107 'id' => 'ie-elementor',
108 'name' => 'Elementor (386 icons)',
109 'pro' => false,
110 'preview' => 'https://elementor.github.io/elementor-icons/',
111 ),
112 array(
113 'id' => 'ie-vscode',
114 'name' => 'VsCode Icon (411 icons)',
115 'pro' => false,
116 'preview' => 'https://www.figma.com/community/file/768673354734944365',
117 ),
118 array(
119 'id' => 'ie-elusive',
120 'name' => 'Elusive (298 icons)',
121 'pro' => false,
122 'preview' => 'http://elusiveicons.com/icons/',
123 ),
124 array(
125 'id' => 'ie-obicon',
126 'name' => 'Obicon (107 icons)',
127 'pro' => false,
128 'preview' => 'https://ob-cloud.github.io/obicon-iot/',
129 ),
130 array(
131 'id' => 'ie-webicon',
132 'name' => 'Web icon (169 icons)',
133 'pro' => false,
134 'preview' => 'https://github.com/thecreation/web-icons',
135 ),
136 array(
137 'id' => 'ie-feather',
138 'name' => 'Feather (265 icons)',
139 'pro' => false,
140 'preview' => 'https://feathericons.com/',
141 ),
142 array(
143 'id' => 'ie-iconsaxbold',
144 'name' => 'Iconsax Bold (904 icons)',
145 'pro' => false,
146 'preview' => 'https://iconsax.io/',
147 ),
148 array(
149 'id' => 'ie-tutor',
150 'name' => 'Tutor LMS Icon (314 icons)',
151 'pro' => false,
152 'preview' => 'https://wordpress.org/plugins/tutor/',
153 ),
154 array(
155 'id' => 'ie-uniconsolid',
156 'name' => 'Unicon solid (189 icons)',
157 'pro' => false,
158 'preview' => 'https://iconscout.com/unicons/explore/solid',
159 ),
160 array(
161 'id' => 'ie-happyicon',
162 'name' => 'Happy icon (646 icons)',
163 'pro' => false,
164 'preview' => 'https://wordpress.org/plugins/happy-elementor-addons/',
165 ),
166 array(
167 'id' => 'ie-woocommerce',
168 'name' => 'Woo Commerce (68 icons)',
169 'pro' => false,
170 'preview' => 'https://rawgit.com/woothemes/woocommerce-icons/master/demo.html',
171 ),
172 array(
173 'id' => 'ie-detheme',
174 'name' => 'DeTheme icon (385 icons)',
175 'pro' => false,
176 'preview' => 'https://wordpress.org/plugins/dethemekit-for-elementor/',
177 ),
178 array(
179 'id' => 'ie-prestashop',
180 'name' => 'Prestashop (478 icons)',
181 'pro' => false,
182 'preview' => 'https://build.prestashop-project.org/prestashop-icon-font/',
183 ),
184 array(
185 'id' => 'ie-uicons',
186 'name' => 'Uicons (2287 icons)',
187 'pro' => false,
188 'preview' => 'https://github.com/freepik-company/flaticon-uicons/',
189 ),
190 array(
191 'id' => 'ie-jquery-uicons',
192 'name' => 'jQuery UI Icons (450 icons)',
193 'pro' => false,
194 'preview' => 'https://api.jqueryui.com/resources/icons-list.html',
195 ),
196 array(
197 'id' => 'ie-xlslim',
198 'name' => 'XL Slim (292 icons)',
199 'pro' => false,
200 'preview' => 'https://user-images.githubusercontent.com/5102591/46199020-8f8ed700-c316-11e8-9b3a-7388f3f4e818.png/',
201 ),
202 array(
203 'id' => 'ie-fabric',
204 'name' => 'Fabric Icon (1922 icons)',
205 'pro' => false,
206 'preview' => 'https://uifabricicons.azurewebsites.net/',
207 ),
208 array(
209 'id' => 'ie-grommet',
210 'name' => 'Grommet (200 icons)',
211 'pro' => false,
212 'preview' => 'https://icons.grommet.io/',
213 ),
214 array(
215 'id' => 'ie-orchid',
216 'name' => 'Orchid (283 icons)',
217 'pro' => false,
218 'preview' => 'https://github.com/orchidsoftware/icons',
219 ),
220
221 // Pro (39)
222 array(
223 'id' => 'ie-bootstrap',
224 'name' => 'Bootstrap (1682 icons)',
225 'pro' => true,
226 'preview' => 'https://icons.getbootstrap.com/#icons',
227 ),
228 array(
229 'id' => 'ie-linea-music',
230 'name' => 'Linea Music (29 icons)',
231 'pro' => true,
232 'preview' => 'https://linea.io/',
233 ),
234 array(
235 'id' => 'ie-boxicons-icons',
236 'name' => 'Boxicons (490 icons)',
237 'pro' => true,
238 'preview' => 'https://github.com/atisawd/boxicons',
239 ),
240 array(
241 'id' => 'ie-elegant-font',
242 'name' => 'Elegant Font (359 icons)',
243 'pro' => true,
244 'preview' => 'https://www.elegantthemes.com/blog/resources/elegant-icon-font',
245 ),
246 array(
247 'id' => 'ie-et-line',
248 'name' => 'ET Line (99 icons)',
249 'pro' => true,
250 'preview' => 'https://www.elegantthemes.com/blog/freebie-of-the-week/free-line-style-icons',
251 ),
252 array(
253 'id' => 'ie-gonzo-font',
254 'name' => 'Gonzo (99 icons)',
255 'pro' => true,
256 'preview' => 'https://www.gonzodesign.nl/gonzocons/',
257 ),
258 array(
259 'id' => 'ie-icomoon-font',
260 'name' => 'Icomoon (490 icons)',
261 'pro' => true,
262 'preview' => 'https://icomoon.io/#preview-free',
263 ),
264 array(
265 'id' => 'ie-iconmonstr-font',
266 'name' => 'Iconmonstr (299 icons)',
267 'pro' => true,
268 'preview' => 'https://iconmonstr.com/',
269 ),
270 array(
271 'id' => 'ie-io7-icon',
272 'name' => 'iOS7 (260 icons)',
273 'pro' => true,
274 'preview' => 'http://akira-miyake.github.io/iOS7-icon-font/',
275 ),
276 array(
277 'id' => 'ie-linea_basic',
278 'name' => 'Linea Basic (134 icons)',
279 'pro' => true,
280 'preview' => 'https://linea.io/',
281 ),
282 array(
283 'id' => 'ie-linea_elaboration',
284 'name' => 'Linea Elaboration (144 icons)',
285 'pro' => true,
286 'preview' => 'https://linea.io/',
287 ),
288 array(
289 'id' => 'ie-linea_ecommerce',
290 'name' => 'Linea Ecommerce (84 icons)',
291 'pro' => true,
292 'preview' => 'https://linea.io/',
293 ),
294 array(
295 'id' => 'ie-linearicons',
296 'name' => 'Linearicons (169 icons)',
297 'pro' => true,
298 'preview' => 'https://linearicons.com/free',
299 ),
300 array(
301 'id' => 'ie-lineawesone-regular',
302 'name' => 'Lineawesome (1393 icons)',
303 'pro' => true,
304 'preview' => 'https://icons8.com/line-awesome',
305 ),
306 array(
307 'id' => 'ie-lineicons',
308 'name' => 'Lineicons (306 icons)',
309 'pro' => true,
310 'preview' => 'https://lineicons.com/',
311 ),
312 array(
313 'id' => 'ie-mobirise',
314 'name' => 'Mobirise (149 icons)',
315 'pro' => true,
316 'preview' => 'https://mobiriseicons.com/cheatsheet.html',
317 ),
318 array(
319 'id' => 'ie-rivolicon',
320 'name' => 'Rivolicon (130 icons)',
321 'pro' => true,
322 'preview' => 'https://rivolicons.hadrien.co/free/',
323 ),
324 array(
325 'id' => 'ie-themify-icons',
326 'name' => 'Themify-icons (351 icons)',
327 'pro' => true,
328 'preview' => 'https://themify.me/themify-icons',
329 ),
330 array(
331 'id' => 'ie-tilda',
332 'name' => 'Tilda (794 icons)',
333 'pro' => true,
334 'preview' => 'https://tilda.cc/free-icons/',
335 ),
336 array(
337 'id' => 'ie-tabler',
338 'name' => 'Tabler Icon (1977 icons)',
339 'pro' => true,
340 'preview' => 'https://tablericons.com/',
341 ),
342 array(
343 'id' => 'ie-antdesign',
344 'name' => 'Antdesign Icon (637 icons)',
345 'pro' => true,
346 'preview' => 'https://ant.design/components/icon/',
347 ),
348 array(
349 'id' => 'ie-chart',
350 'name' => 'Chart (37 icons)',
351 'pro' => true,
352 'preview' => 'https://www.figma.com/file/0Gtw7eOrDnbNxPpveO183k/Chart-Icons---Outline-(Community)?node-id=275%3A6576',
353 ),
354 array(
355 'id' => 'ie-mapicon',
356 'name' => 'Map Icon (174 icons)',
357 'pro' => true,
358 'preview' => 'http://map-icons.com/',
359 ),
360 array(
361 'id' => 'ie-devicon',
362 'name' => 'Devicon (499 icons)',
363 'pro' => true,
364 'preview' => 'https://devicon.dev/',
365 ),
366 array(
367 'id' => 'ie-androidmaterial',
368 'name' => 'Android material (432 icons)',
369 'pro' => true,
370 'preview' => 'https://www.androidicons.com/',
371 ),
372 array(
373 'id' => 'ie-androidholo',
374 'name' => 'Android holo (143 icons)',
375 'pro' => true,
376 'preview' => 'https://www.androidicons.com/',
377 ),
378 array(
379 'id' => 'ie-evaicon',
380 'name' => 'Evaicon (244 icons)',
381 'pro' => true,
382 'preview' => 'https://www.figma.com/file/T08qYmPlqINqGdU9ElXdXZ/Icon-Design-System---Eva-Icons-(Community)?node-id=0%3A1',
383 ),
384 array(
385 'id' => 'ie-iconicool',
386 'name' => 'Iconi cool (70 icons)',
387 'pro' => true,
388 'preview' => 'https://www.figma.com/file/2jUsVzQgltQG4LXBYabU71/Iconicool-%7C-Free-Iconset-(Community)?node-id=3%3A250',
389 ),
390 array(
391 'id' => 'ie-elementplus',
392 'name' => 'Element plus (243 icons)',
393 'pro' => true,
394 'preview' => 'https://element-plus.org/en-US/component/icon.html#icon-collection',
395 ),
396 array(
397 'id' => 'ie-uniconline',
398 'name' => 'Unicon line (1203 icons)',
399 'pro' => true,
400 'preview' => 'https://iconscout.com/unicons/explore/line',
401 ),
402 array(
403 'id' => 'ie-unithinline',
404 'name' => 'Unicon thin line (214 icons)',
405 'pro' => true,
406 'preview' => 'https://iconscout.com/unicons/explore/thinline',
407 ),
408 array(
409 'id' => 'ie-buddyboss',
410 'name' => 'Buddy Boss (1295 icons)',
411 'pro' => true,
412 'preview' => 'https://www.buddyboss.com/resources/font-cheatsheet/',
413 ),
414 array(
415 'id' => 'ie-trademe',
416 'name' => 'Trademe (397 icons)',
417 'pro' => true,
418 'preview' => 'https://trademe.github.io/TradeMe-IconFont/',
419 ),
420 array(
421 'id' => 'ie-mingcute',
422 'name' => 'Mingcute (2327 icons)',
423 'pro' => true,
424 'preview' => 'https://www.mingcute.com/',
425 ),
426 array(
427 'id' => 'ie-olicons',
428 'name' => 'Olicons (677 icons)',
429 'pro' => true,
430 'preview' => 'http://olicons.yemaosheji.com/index.html#sec-menu',
431 ),
432 array(
433 'id' => 'ie-phosphor-duotone',
434 'name' => 'Phosphor-duotone (3022 icons)',
435 'pro' => true,
436 'preview' => 'https://phosphoricons.com/?weight=%22duotone%22',
437 ),
438 array(
439 'id' => 'ie-ixsiemens',
440 'name' => 'Siemens icon (642 icons)',
441 'pro' => true,
442 'preview' => 'https://github.com/siemens/ix-icons',
443 ),
444 array(
445 'id' => 'ie-keyrune',
446 'name' => 'Keyrune (340 icons)',
447 'pro' => true,
448 'preview' => 'https://keyrune.andrewgioia.com/icons.html',
449 ),
450 array(
451 'id' => 'ie-health',
452 'name' => 'Health (739 icons)',
453 'pro' => true,
454 'preview' => 'https://healthicons.org/',
455 ),
456 array(
457 'id' => 'ie-icofont',
458 'name' => 'IcoFont (2139 icons)',
459 'pro' => true,
460 'preview' => 'https://icofont.com',
461 ),
462 array(
463 'id' => 'ie-remix',
464 'name' => 'Remix (2055 icons)',
465 'pro' => true,
466 'preview' => 'https://github.com/Remix-Design/RemixIcon',
467 ),
468 array(
469 'id' => 'ie-medical',
470 'name' => 'Medical (144 icons)',
471 'pro' => true,
472 'preview' => '#',
473 ),
474 array(
475 'id' => 'ie-payment',
476 'name' => 'Payment (35 icons)',
477 'pro' => true,
478 'preview' => '#',
479 ),
480 array(
481 'id' => 'ie-clarity',
482 'name' => 'Clarity (1081 icons)',
483 'pro' => true,
484 'preview' => '#',
485 ),
486 array(
487 'id' => 'ie-jam',
488 'name' => 'Jam (986 icons)',
489 'pro' => true,
490 'preview' => '#',
491 ),
492 array(
493 'id' => 'ie-octicons',
494 'name' => 'Octicons (986 icons)',
495 'pro' => true,
496 'preview' => '#',
497 ),
498 array(
499 'id' => 'ie-nip',
500 'name' => 'Nip (82 icons)',
501 'pro' => true,
502 'preview' => '#',
503 ),
504 array(
505 'id' => 'ie-framework7',
506 'name' => 'Framework7 (1233 icons)',
507 'pro' => true,
508 'preview' => '#',
509 ),
510 array(
511 'id' => 'ie-iconsaxcrypto',
512 'name' => 'Crypto (104 icons)',
513 'pro' => true,
514 'preview' => '#',
515 ),
516 array(
517 'id' => 'ie-iconsaxoutline',
518 'name' => 'Outline (898 icons)',
519 'pro' => true,
520 'preview' => '#',
521 ),
522 array(
523 'id' => 'ie-outlined',
524 'name' => 'Outlined (150 icons)',
525 'pro' => true,
526 'preview' => '#',
527 ),
528 );
529 }
530
531 /**
532 * Enqueue React scripts and styles.
533 */
534 function rap_enqueue_admin_assets( $hook ) {
535 if ( 'toplevel_page_iconelement' !== $hook ) {
536 return;
537 }
538
539 wp_enqueue_script( 'react' );
540 wp_enqueue_script( 'react-dom' );
541 wp_enqueue_script( 'wp-api-fetch' );
542
543 wp_enqueue_script(
544 'rap-admin-script',
545 ICON_ELEM_URL . 'admin/assets/js/admin-script.js',
546 array( 'react', 'react-dom', 'wp-api-fetch' ),
547 RAP_VERSION,
548 true
549 );
550
551 wp_enqueue_style(
552 'rap-admin-style',
553 ICON_ELEM_URL . 'admin/assets/css/admin-style.css',
554 array(),
555 RAP_VERSION
556 );
557
558 wp_localize_script(
559 'wp-api-fetch',
560 'wpApiSettings',
561 array(
562 'root' => esc_url_raw( rest_url() ),
563 'nonce' => wp_create_nonce( 'wp_rest' ),
564 )
565 );
566
567 wp_localize_script(
568 'rap-admin-script',
569 'rapSettings',
570 array(
571 'defaults' => rap_get_settings_array(),
572 'iconSets' => rap_get_icon_sets(),
573 'restNamespace' => 'iconelement-admin/v1', // ← only namespace
574 'nonce' => wp_create_nonce( 'wp_rest' ),
575 'isLoggedIn' => is_user_logged_in(),
576 'authorSlugs' => RAP_AUTHORS,
577 'ispro' => Icon_Element_Icons::is_iconelement_pro(),
578 )
579 );
580
581 }
582 add_action( 'admin_enqueue_scripts', 'rap_enqueue_admin_assets' );
583
584 /**
585 * Retrieve settings array from single option.
586 *
587 * @return array
588 */
589 function rap_get_settings_array() {
590 $icon_sets = rap_get_icon_sets();
591 $defaults = array();
592 foreach ( $icon_sets as $set ) {
593 $defaults[ $set['id'] ] = false;
594 }
595
596 $settings = get_option( 'rap_settings', array() );
597 return wp_parse_args( $settings, $defaults );
598 }
599
600 /**
601 * Register REST API routes.
602 */
603 function rap_register_rest_routes() {
604 // Settings endpoints.
605 register_rest_route(
606 'iconelement-admin/v1',
607 '/settings',
608 array(
609 'methods' => 'GET',
610 'callback' => 'rap_get_settings',
611 'permission_callback' => 'rap_permissions_check',
612 )
613 );
614 register_rest_route(
615 'iconelement-admin/v1',
616 '/settings',
617 array(
618 'methods' => 'POST',
619 'callback' => 'rap_update_settings',
620 'permission_callback' => 'rap_permissions_check',
621 'args' => array(),
622 )
623 );
624
625 // Plugins list endpoint (multi‑author).
626 register_rest_route(
627 'iconelement-admin/v1',
628 '/plugins',
629 array(
630 'methods' => 'GET',
631 'callback' => 'rap_get_plugins',
632 'permission_callback' => 'rap_permissions_check',
633 'args' => array(
634 'authors' => array(
635 'required' => true,
636 'type' => 'string',
637 ),
638 ),
639 )
640 );
641
642 // Plugin installation endpoint.
643 register_rest_route(
644 'iconelement-admin/v1',
645 '/install-plugin',
646 array(
647 'methods' => 'POST',
648 'callback' => 'rap_install_plugin',
649 'permission_callback' => 'rap_permissions_check',
650 'args' => array(
651 'slug' => array(
652 'required' => true,
653 'type' => 'string',
654 ),
655 ),
656 )
657 );
658
659 // Plugin activation endpoint.
660 register_rest_route(
661 'iconelement-admin/v1',
662 '/activate-plugin',
663 array(
664 'methods' => 'POST',
665 'callback' => 'rap_rest_activate_plugin',
666 'permission_callback' => 'rap_permissions_check',
667 'args' => array(
668 'slug' => array(
669 'required' => true,
670 'type' => 'string',
671 ),
672 ),
673 )
674 );
675
676 // Plugin status endpoint.
677 register_rest_route(
678 'iconelement-admin/v1',
679 '/plugin-status',
680 array(
681 'methods' => 'GET',
682 'callback' => 'rap_plugin_status',
683 'permission_callback' => 'rap_permissions_check',
684 'args' => array(
685 'slug' => array(
686 'required' => true,
687 'type' => 'string',
688 ),
689 ),
690 )
691 );
692 }
693 add_action( 'rest_api_init', 'rap_register_rest_routes' );
694
695 /**
696 * Permission callback.
697 */
698 function rap_permissions_check() {
699 return current_user_can( 'manage_options' );
700 }
701
702 /**
703 * GET endpoint: retrieve all settings.
704 */
705 function rap_get_settings() {
706 return rest_ensure_response( rap_get_settings_array() );
707 }
708
709 /**
710 * POST endpoint: update all settings.
711 */
712 function rap_update_settings( $request ) {
713 $settings = rap_get_settings_array();
714
715 foreach ( array_keys( $settings ) as $key ) {
716 if ( $request->has_param( $key ) ) {
717 $settings[ $key ] = (bool) $request->get_param( $key );
718 }
719 }
720
721 update_option( 'rap_settings', $settings );
722 return rest_ensure_response( $settings );
723 }
724
725 /**
726 * GET endpoint: fetch plugins from multiple authors.
727 */
728 function rap_get_plugins( $request ) {
729 $authors = $request->get_param( 'authors' );
730 if ( empty( $authors ) ) {
731 return rest_ensure_response( array( 'error' => true, 'message' => 'No authors provided.' ) );
732 }
733 if ( is_string( $authors ) ) {
734 $authors = array_map( 'trim', explode( ',', $authors ) );
735 }
736 return rest_ensure_response( RAP_Plugin_Fetcher::fetch_plugins_by_authors( $authors ) );
737 }
738
739 /**
740 * POST endpoint: install a plugin.
741 */
742 function rap_install_plugin( $request ) {
743 $slug = $request->get_param( 'slug' );
744 $result = RAP_Plugin_Installer::install_plugin( $slug );
745 return rest_ensure_response( $result );
746 }
747
748 /**
749 * POST endpoint: activate an installed plugin.
750 */
751 function rap_rest_activate_plugin( $request ) {
752 $slug = $request->get_param( 'slug' );
753 $result = RAP_Plugin_Installer::activate_plugin( $slug );
754 return rest_ensure_response( $result );
755 }
756
757 /**
758 * GET endpoint: check if plugin is installed/active.
759 */
760 function rap_plugin_status( $request ) {
761 $slug = $request->get_param( 'slug' );
762 return rest_ensure_response( array(
763 'installed' => RAP_Plugin_Installer::is_plugin_installed( $slug ),
764 'active' => RAP_Plugin_Installer::is_plugin_active( $slug ),
765 ) );
766 }
767
768 /**
769 * Activation hook: set default options and flush rewrite rules.
770 */
771 function rap_activate_plugin() {
772 $existing = get_option( 'rap_settings', array() );
773 if ( empty( $existing ) ) {
774 $defaults = rap_get_settings_array();
775 add_option( 'rap_settings', $defaults );
776 } else {
777 $defaults = rap_get_settings_array();
778 $merged = wp_parse_args( $existing, $defaults );
779 update_option( 'rap_settings', $merged );
780 }
781 // Clear plugin cache so requires_plugins field is fetched fresh.
782 RAP_Plugin_Fetcher::clear_cache();
783 flush_rewrite_rules();
784 }
785 register_activation_hook( ICONELEMENT_ROOT_FILE__, 'rap_activate_plugin' );
786
787 /**
788 * Deactivation hook: flush rewrite rules.
789 */
790 function rap_deactivate_plugin() {
791 flush_rewrite_rules();
792 }
793 register_deactivation_hook( ICONELEMENT_ROOT_FILE__, 'rap_deactivate_plugin' );
794
795 /**
796 * Clear the plugin list cache whenever WordPress runs its own update check.
797 * This fires during the scheduled wp_update_plugins / wp_update_themes cron events
798 * and when the user visits Dashboard → Updates.
799 */
800 function rap_clear_cache_on_wp_update_check() {
801 RAP_Plugin_Fetcher::clear_cache();
802 }
803 add_action( 'wp_update_plugins', 'rap_clear_cache_on_wp_update_check' );
804 add_action( 'wp_update_themes', 'rap_clear_cache_on_wp_update_check' );