abilities
1 week ago
admin
1 week ago
compatibility
1 week ago
extensions
1 week ago
foopluginbase
1 week ago
public
1 week ago
thumbs
1 week ago
asset-manifest.php
1 week ago
class-attachment-filters.php
1 week ago
class-command-palette.php
1 week ago
class-foogallery-animated-gif-support.php
1 week ago
class-foogallery-attachment-custom-class.php
1 week ago
class-foogallery-attachment-filename.php
1 week ago
class-foogallery-attachment-type.php
1 week ago
class-foogallery-attachment.php
1 week ago
class-foogallery-cache.php
1 week ago
class-foogallery-common-fields.php
1 week ago
class-foogallery-crop-position.php
1 week ago
class-foogallery-datasource-media_library.php
1 week ago
class-foogallery-debug.php
1 week ago
class-foogallery-delayed-runtime-loader.php
1 week ago
class-foogallery-extensions-compatibility.php
1 week ago
class-foogallery-force-https.php
1 week ago
class-foogallery-lazyload.php
1 week ago
class-foogallery-license-constant-handler.php
1 week ago
class-foogallery-lightbox.php
1 week ago
class-foogallery-no-javascript-fallback.php
1 week ago
class-foogallery-paging.php
1 week ago
class-foogallery-password-protect.php
1 week ago
class-foogallery-sitemaps.php
1 week ago
class-foogallery-widget.php
1 week ago
class-foogallery.php
1 week ago
class-gallery-advanced-settings.php
1 week ago
class-il8n.php
1 week ago
class-override-thumbnail.php
1 week ago
class-posttypes.php
1 week ago
class-previews.php
1 week ago
class-retina.php
1 week ago
class-thumbnail-dimensions.php
1 week ago
class-thumbnails.php
1 week ago
class-version-check.php
1 week ago
constants.php
1 week ago
functions.php
1 week ago
gallery-management-functions.php
1 week ago
includes.php
1 week ago
index.php
1 week ago
render-functions.php
1 week ago
class-command-palette.php
79 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | /** |
| 8 | * FooGallery Command Palette Integration |
| 9 | * |
| 10 | * Registers FooGallery galleries in the WordPress Command Palette |
| 11 | * (Ctrl+K / Cmd+K), introduced in WordPress 6.3 via @wordpress/commands. |
| 12 | * |
| 13 | * Adds: |
| 14 | * - A dynamic loader that searches galleries by title as the user types. |
| 15 | * - A static "Add New Gallery" command always present in the palette. |
| 16 | */ |
| 17 | |
| 18 | if ( ! class_exists( 'FooGallery_Command_Palette' ) ) { |
| 19 | |
| 20 | class FooGallery_Command_Palette { |
| 21 | |
| 22 | public function __construct() { |
| 23 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Enqueue the command-palette script on all wp-admin pages. |
| 28 | * Bails out gracefully on WordPress versions prior to 6.3 that do not |
| 29 | * ship the @wordpress/commands package. |
| 30 | */ |
| 31 | public function enqueue_assets() { |
| 32 | // @wordpress/commands was introduced in WordPress 6.3. |
| 33 | // If the script handle is not registered we are on an older version. |
| 34 | if ( ! wp_script_is( 'wp-commands', 'registered' ) ) { |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | wp_enqueue_script( |
| 39 | 'foogallery-command-palette', |
| 40 | FOOGALLERY_URL . 'js/foogallery-command-palette.js', |
| 41 | array( 'wp-commands', 'wp-data', 'wp-element', 'wp-i18n' ), |
| 42 | FOOGALLERY_VERSION, |
| 43 | true |
| 44 | ); |
| 45 | |
| 46 | if ( function_exists( 'wp_set_script_translations' ) ) { |
| 47 | wp_set_script_translations( 'foogallery-command-palette', 'foogallery' ); |
| 48 | } |
| 49 | |
| 50 | wp_add_inline_script( |
| 51 | 'foogallery-command-palette', |
| 52 | 'window.FOOGALLERY_COMMAND_PALETTE = ' . wp_json_encode( $this->get_js_config() ) . ';', |
| 53 | 'before' |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Returns the configuration object passed to the JavaScript layer. |
| 59 | * |
| 60 | * @return array |
| 61 | */ |
| 62 | private function get_js_config() { |
| 63 | $post_type_object = get_post_type_object( FOOGALLERY_CPT_GALLERY ); |
| 64 | |
| 65 | $edit_url = ''; |
| 66 | if ( $post_type_object && ! empty( $post_type_object->_edit_link ) ) { |
| 67 | // _edit_link contains a printf-style %d placeholder for the post ID. |
| 68 | $edit_url = admin_url( $post_type_object->_edit_link . '&action=edit' ); |
| 69 | } |
| 70 | |
| 71 | return array( |
| 72 | 'editGalleryUrl' => $edit_url, |
| 73 | 'addNewGalleryUrl' => admin_url( 'post-new.php?post_type=' . FOOGALLERY_CPT_GALLERY ), |
| 74 | 'galleryName' => foogallery_plugin_name(), |
| 75 | ); |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 |