getInputs(); $id = (int) ( $inputs['meeting_id'] ?? 0 ); $title = $id > 0 ? get_the_title( $id ) : ''; $label = '' !== $title ? "\"{$title}\" (ID: {$id})" : "#{$id}"; $fields = array_keys( array_diff_key( $inputs, [ 'meeting_id' => true ] ) ); $what = $fields ? implode( ', ', $fields ) : 'nothing'; return "Update meeting {$label}: change {$what}"; } public function get_approval_inputs(): array { $inputs = $this->getInputs(); if ( isset( $inputs['meeting_id'] ) ) { $id = (int) $inputs['meeting_id']; $title = get_the_title( $id ); $inputs['meeting_id'] = '' !== $title ? "{$title} (ID: {$id})" : (string) $id; } return $inputs; } public function __invoke( int $meeting_id, ?string $name = null, ?string $description = null, ?int $duration_minutes = null, ?float $price = null, ?int $capacity = null, ?string $visibility = null, ?string $timezone = null, ?array $category_ids = null ): array { $check = $this->guard_admin(); if ( $check ) { return $check; } if ( $meeting_id <= 0 ) { return [ 'error' => 'A valid meeting_id is required.' ]; } if ( null === $name && null === $description && null === $duration_minutes && null === $price && null === $capacity && null === $visibility && null === $timezone && null === $category_ids ) { return [ 'error' => 'No changes were specified. Provide at least one field to update.' ]; } if ( null !== $visibility && ! in_array( $visibility, self::VISIBILITY, true ) ) { return [ 'error' => "Invalid visibility '{$visibility}'. Accepted values: " . implode( ', ', self::VISIBILITY ) . '.' ]; } try { $body = $this->load_meeting_state( $meeting_id ); if ( null === $body ) { return [ 'error' => "Meeting #{$meeting_id} was not found." ]; } if ( null !== $name ) { if ( '' === trim( $name ) ) { return [ 'error' => 'name cannot be empty.' ]; } $body['name'] = sanitize_text_field( $name ); } if ( null !== $description ) { $body['description'] = sanitize_text_field( $description ); } if ( null !== $duration_minutes ) { $body['duration'] = max( 1, $duration_minutes ) . ' min'; } if ( null !== $price ) { if ( is_array( $body['price'] ) ) { return [ 'error' => 'This is a group meeting with per-ticket pricing, which cannot be changed here. Edit its tickets in Timetics.' ]; } $body['price'] = (float) $price; } if ( null !== $capacity ) { $body['capacity'] = max( 1, $capacity ); } if ( null !== $visibility ) { $body['visibility'] = $visibility; } if ( null !== $category_ids ) { $body['categories'] = $this->sanitize_id_list( $category_ids ); } // Guarantee a valid timezone: a supplied one must parse; otherwise keep // the meeting's current timezone (repaired to a valid value if needed). if ( null !== $timezone ) { if ( ! $this->is_valid_timezone( $timezone ) ) { return [ 'error' => "Invalid timezone '{$timezone}'. Use an IANA name such as 'America/New_York'." ]; } $body['timezone'] = trim( $timezone ); } else { $body['timezone'] = $this->resolve_timezone( is_string( $body['timezone'] ) ? $body['timezone'] : null ); } $request = $this->build_request( 'PUT', '/timetics/v1/appointments/' . $meeting_id, [], $body, [ 'appointment_id' => $meeting_id ] ); if ( is_array( $request ) ) { return $request; } $controller = \Timetics\Core\Appointments\Api_Appointment::instance(); $data = $this->extract_response( $controller->update_item( $request ), "Failed to update meeting #{$meeting_id}." ); if ( isset( $data['error'] ) ) { return $data; } return [ 'success' => true, 'meeting_id' => $meeting_id, 'meeting' => $this->shape_meeting( $data, true ), 'message' => "Meeting #{$meeting_id} updated successfully.", ]; } catch ( \Throwable $e ) { Log::error( 'Timetics_Update_Meeting_Tool error', [ 'error' => $e->getMessage() ] ); return [ 'error' => 'Failed to update meeting: ' . $e->getMessage() ]; } } }