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