PluginProbe
Extendify / 3.1.5
Extendify v3.1.5
3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 0.7.0 All 126 releases
extendify / app / Recommendations / Admin.php

Admin.php in Extendify 3.1.5, at app/Recommendations/Admin.php

87 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Admin.
5 */
6
7 namespace Extendify\Recommendations;
8
9 defined('ABSPATH') || die('No direct access.');
10
11 use Extendify\Config;
12 use Extendify\PartnerData;
13
14 /**
15 * This class handles any file loading for the admin area.
16 */
17
18 class Admin
19 {
20 /**
21 * Adds various actions to set up the page
22 *
23 * @return void
24 */
25 public function __construct()
26 {
27 \add_action('admin_enqueue_scripts', [$this, 'loadScriptsAndStyles']);
28 }
29
30 /**
31 * Adds various JS scripts if on the plugin install page
32 *
33 * @return void
34 */
35 public function loadScriptsAndStyles()
36 {
37 if (\get_current_screen()->id !== 'plugin-install') {
38 return;
39 }
40
41 $version = constant('EXTENDIFY_DEVMODE') ? uniqid() : Config::$version;
42 $scriptAssetPath = EXTENDIFY_PATH . 'public/build/' . Config::$assetManifest['extendify-recommendations.php'];
43 $fallback = [
44 'dependencies' => [],
45 'version' => $version,
46 ];
47 $scriptAsset = file_exists($scriptAssetPath) ? require $scriptAssetPath : $fallback;
48
49 foreach ($scriptAsset['dependencies'] as $style) {
50 \wp_enqueue_style($style);
51 }
52
53 \wp_enqueue_script(
54 Config::$slug . '-recommendations-scripts',
55 EXTENDIFY_BASE_URL . 'public/build/' . Config::$assetManifest['extendify-recommendations.js'],
56 array_merge([Config::$slug . '-shared-scripts'], $scriptAsset['dependencies']),
57 $scriptAsset['version'],
58 true
59 );
60
61 \wp_enqueue_style(
62 Config::$slug . '-recommendations-styles',
63 EXTENDIFY_BASE_URL . 'public/build/' . Config::$assetManifest['extendify-recommendations.css'],
64 [],
65 Config::$version,
66 'all'
67 );
68
69 \wp_add_inline_script(
70 Config::$slug . '-recommendations-scripts',
71 'window.extRecommendationsData = ' . \wp_json_encode(
72 [
73 'showPartnerBranding' => (bool) \esc_attr(
74 PartnerData::setting('productRecommendations')['showPartnerBranding']
75 ),
76 ]
77 ),
78 'before'
79 );
80 \wp_set_script_translations(
81 Config::$slug . '-recommendations-scripts',
82 'extendify-local',
83 EXTENDIFY_PATH . 'languages/js'
84 );
85 }
86 }
87