Changeset 3736632
- Timestamp:
- 10/09/2026 12:30:22 PM (2 weeks ago)
- Location:
- automaize-event-calendar/trunk
- Files:
-
- 5 edited
-
automaize-event-calendar.php (modified) (2 diffs)
-
includes/class-aec-events-query.php (modified) (1 diff)
-
includes/class-aec-events-write.php (modified) (1 diff)
-
includes/class-aec-rest.php (modified) (3 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
automaize-event-calendar/trunk/automaize-event-calendar.php
r3708972 r3736632 3 3 * Plugin Name: Automaize Event Calendar 4 4 * Description: Displays upcoming events in a responsive tile grid with recurring event support and optional WooCommerce integration. 5 * Version: 1. 1.05 * Version: 1.2.0 6 6 * Author: Automaize 7 7 * Author URI: https://automaize.app … … 18 18 } 19 19 20 define( 'AMZEC_VERSION', '1. 1.0' );20 define( 'AMZEC_VERSION', '1.2.0' ); 21 21 define( 'AMZEC_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); 22 22 define( 'AMZEC_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); -
automaize-event-calendar/trunk/includes/class-aec-events-query.php
r3708972 r3736632 120 120 ); 121 121 } 122 123 /** 124 * Paginated listing of image attachments already in the WordPress 125 * media library - lets the app offer "choose an existing image" 126 * alongside "upload a new one" when setting an event's featured 127 * image, instead of only ever re-uploading from the device. 128 * 129 * @param int $paged 1-based page number. 130 * @param int $per_page Items per page. 131 * @return array{ attachment_ids: int[], total: int, total_pages: int } 132 */ 133 public static function get_media_list( $paged = 1, $per_page = 40 ) { 134 $query = new WP_Query( 135 array( 136 'post_type' => 'attachment', 137 'post_mime_type' => 'image', 138 'post_status' => 'inherit', 139 'posts_per_page' => $per_page, 140 'paged' => max( 1, (int) $paged ), 141 'orderby' => 'date', 142 'order' => 'DESC', 143 'fields' => 'ids', 144 ) 145 ); 146 147 return array( 148 'attachment_ids' => $query->posts, 149 'total' => (int) $query->found_posts, 150 'total_pages' => (int) $query->max_num_pages, 151 ); 152 } 122 153 } -
automaize-event-calendar/trunk/includes/class-aec-events-write.php
r3708972 r3736632 161 161 } 162 162 163 /** 164 * Sets an event's featured image to an attachment already in the media 165 * library, instead of uploading a new one - the counterpart to 166 * set_featured_image() for the app's "choose existing image" picker. 167 * 168 * @param int $post_id Event post ID. 169 * @param int $attachment_id Existing media library attachment ID. 170 * @return int|WP_Error The attachment ID on success. 171 */ 172 public static function set_featured_image_from_media( $post_id, $attachment_id ) { 173 $post = get_post( $post_id ); 174 if ( ! $post || 'amzec_event' !== $post->post_type ) { 175 return new WP_Error( 'aec_not_found', __( 'Event not found.', 'automaize-event-calendar' ), array( 'status' => 404 ) ); 176 } 177 178 $attachment = get_post( $attachment_id ); 179 if ( ! $attachment || 'attachment' !== $attachment->post_type || 0 !== strpos( (string) $attachment->post_mime_type, 'image/' ) ) { 180 return new WP_Error( 'aec_invalid', __( 'That media item could not be found.', 'automaize-event-calendar' ), array( 'status' => 404 ) ); 181 } 182 183 set_post_thumbnail( $post_id, $attachment_id ); 184 185 return $attachment_id; 186 } 187 163 188 // ------------------------------------------------------------------------- 164 189 // Shared field mapping -
automaize-event-calendar/trunk/includes/class-aec-rest.php
r3708972 r3736632 137 137 ) 138 138 ); 139 140 register_rest_route( 141 self::NAMESPACE_, 142 '/staff/media', 143 array( 144 'methods' => WP_REST_Server::READABLE, 145 'callback' => array( __CLASS__, 'list_media' ), 146 'permission_callback' => array( __CLASS__, 'check_api_key' ), 147 ) 148 ); 139 149 } 140 150 … … 385 395 */ 386 396 public static function upload_event_image( WP_REST_Request $request ) { 387 $files = $request->get_file_params(); 388 389 if ( empty( $files['file'] ) ) { 390 return self::error_response( new WP_Error( 'aec_invalid', __( 'Please provide an image file.', 'automaize-event-calendar' ), array( 'status' => 400 ) ) ); 391 } 392 393 $attach_id = AMZEC_Events_Write::set_featured_image( absint( $request['id'] ), $files['file'] ); 397 $files = $request->get_file_params(); 398 $media_id = absint( $request->get_param( 'media_id' ) ); 399 400 if ( ! empty( $files['file'] ) ) { 401 $attach_id = AMZEC_Events_Write::set_featured_image( absint( $request['id'] ), $files['file'] ); 402 } elseif ( $media_id > 0 ) { 403 // Picked an existing media library item instead of uploading a 404 // new file - see AMZEC_Events_Query::get_media_list() / 405 // GET /staff/media. 406 $attach_id = AMZEC_Events_Write::set_featured_image_from_media( absint( $request['id'] ), $media_id ); 407 } else { 408 return self::error_response( new WP_Error( 'aec_invalid', __( 'Please provide an image file or an existing media_id.', 'automaize-event-calendar' ), array( 'status' => 400 ) ) ); 409 } 394 410 395 411 if ( is_wp_error( $attach_id ) ) { … … 401 417 'attachment_id' => $attach_id, 402 418 'image_url' => wp_get_attachment_url( $attach_id ), 419 ) 420 ); 421 } 422 423 /** 424 * GET /staff/media?page= - paginated image picker for the app's "choose 425 * an existing image" option when setting an event's featured image. 426 * 427 * @param WP_REST_Request $request Request. 428 * @return WP_REST_Response 429 */ 430 public static function list_media( WP_REST_Request $request ) { 431 $page = max( 1, absint( $request->get_param( 'page' ) ) ); 432 $result = AMZEC_Events_Query::get_media_list( $page ); 433 434 $items = array_map( 435 function ( $attachment_id ) { 436 $thumb = wp_get_attachment_image_src( $attachment_id, 'thumbnail' ); 437 438 return array( 439 'id' => $attachment_id, 440 'url' => wp_get_attachment_url( $attachment_id ), 441 'thumbnail_url' => $thumb ? $thumb[0] : wp_get_attachment_url( $attachment_id ), 442 'title' => get_the_title( $attachment_id ), 443 ); 444 }, 445 $result['attachment_ids'] 446 ); 447 448 return rest_ensure_response( 449 array( 450 'items' => $items, 451 'total' => $result['total'], 452 'total_pages' => $result['total_pages'], 403 453 ) 404 454 ); -
automaize-event-calendar/trunk/readme.txt
r3708972 r3736632 5 5 Tested up to: 7.0 6 6 Requires PHP: 7.4 7 Stable tag: 1. 1.07 Stable tag: 1.2.0 8 8 License: GPL-2.0-or-later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 79 79 == Changelog == 80 80 81 = 1.2.0 = 82 * Added `GET /staff/media`: a paginated listing of existing image attachments in the WordPress media library, so the app can offer "choose an existing image" alongside "upload a new one" when setting an event's featured image. `POST /staff/events/{id}/image` now also accepts a `media_id` of an existing attachment as an alternative to a file upload. 83 81 84 = 1.1.0 = 82 85 * New: REST API for the Kerstins mobile companion app (public event browsing plus an API-key-protected staff surface to create, edit, delete events and upload a featured image — including full recurrence support)
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)