Skip to content

Commit d9b8dae

Browse files
committed
use own plugin icons, add hook only if in editor or useful plugins page
1 parent 5e6fb4d commit d9b8dae

File tree

4 files changed

+18
-30
lines changed

4 files changed

+18
-30
lines changed

src/welcome/images/cimo-icon.png

4.61 KB
Loading
935 Bytes
Loading

src/welcome/useful-plugins.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import CimoIcon from './images/cimo-icon.png'
2+
import InteractionsIcon from './images/interactions-icon.png'
3+
14
import {
2-
i18n, usefulPlugins, ajaxUrl, installerNonce, activateNonce,
5+
i18n, usefulPlugins, ajaxUrl, installerNonce, activateNonce, srcUrl,
36
} from 'stackable'
47

58
import { Button, Spinner } from '@wordpress/components'
@@ -10,10 +13,12 @@ import { __ } from '@wordpress/i18n'
1013
// List of plugins to display in the Useful Plugins section
1114
const PLUGINS = [ {
1215
id: 'interactions',
16+
icon: InteractionsIcon,
1317
title: __( 'Interactions', i18n ),
1418
description: __( 'Easily add animations and interactive experiences to your web pages using the block editor. Craft interactions from subtle hover effects to attention-grabbing story-telling animations.', i18n ),
1519
}, {
1620
id: 'cimo-image-optimizer',
21+
icon: CimoIcon,
1722
title: __( 'Cimo - Image Optimizer', i18n ),
1823
description: __( 'A game-changer for image optimization. Cimo optimizes and converts your images instantly as you upload — even before the files are added to your Media Library.', i18n ),
1924
} ]
@@ -101,20 +106,10 @@ const PluginCard = ( { plugin } ) => {
101106
} )
102107
}
103108

104-
// Validate URL before using
105-
const isValidUrl = url => {
106-
try {
107-
const parsed = new URL( url )
108-
return [ 'http:', 'https:' ].includes( parsed.protocol )
109-
} catch {
110-
return false
111-
}
112-
}
113-
114109
return <div key={ plugin.id } className="s-card">
115110
<div className="s-plugin-title">
116-
{ pluginData.icon && isValidUrl( pluginData.icon ) && (
117-
<img className="s-plugin-icon" src={ pluginData.icon } alt={ __( 'Plugin icon', i18n ) } />
111+
{ plugin.icon && (
112+
<img className="s-plugin-icon" src={ `${ srcUrl }/${ plugin.icon }` } alt={ __( 'Plugin icon', i18n ) } />
118113
) }
119114
<h3 className="s-card-title">{ plugin.title }</h3>
120115
</div>

src/welcome/useful-plugins.php

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,16 @@ class Stackable_Useful_Plugins {
2727
function __construct() {
2828
// Register action on 'admin_menu' to ensure filters for the editor and admin settings
2929
// are added early, before those scripts are enqueued and filters are applied.
30-
add_action( 'admin_menu', array( $this, 'get_useful_plugins_info' ) );
30+
// Only add this action if we're on the useful plugins page or post.php
31+
global $pagenow;
32+
33+
$page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
34+
$is_useful_plugins_page = ( $page === 'stackable-useful-plugins' );
35+
$is_post_editor = ( $pagenow === 'post.php' );
36+
37+
if ( $is_useful_plugins_page || $is_post_editor ) {
38+
add_action( 'admin_menu', array( $this, 'get_useful_plugins_info' ) );
39+
}
3140

3241
// use WordPress ajax installer
3342
// see Docs: https://developer.wordpress.org/reference/functions/wp_ajax_install_plugin/
@@ -77,9 +86,6 @@ public function get_useful_plugins_info() {
7786
return;
7887
}
7988

80-
if ( ! function_exists( 'plugins_api' ) ) {
81-
include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
82-
}
8389
if ( ! function_exists( 'get_plugins' ) || ! function_exists( 'is_plugin_active' ) ) {
8490
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
8591
}
@@ -120,21 +126,8 @@ public function get_useful_plugins_info() {
120126
}
121127
}
122128

123-
$plugin_info = plugins_api( 'plugin_information', [
124-
'slug' => $plugin['slug'],
125-
'fields' => [ 'icons' => true, 'sections' => false ],
126-
] );
127-
128-
$icon_url = '';
129-
if ( ! is_wp_error( $plugin_info ) && isset( $plugin_info->icons )
130-
&& is_array( $plugin_info->icons ) && ! empty( $plugin_info->icons )
131-
) {
132-
$icon_url = array_values( $plugin_info->icons )[0];
133-
}
134-
135129
$data_to_localize[ $key ] = array(
136130
'status' => $status,
137-
'icon' => $icon_url,
138131
'fullSlug' => $full_slug_to_use,
139132
);
140133
}

0 commit comments

Comments
 (0)