$model * @param int $post_id * @param string $subtree_id * @return array */ protected function analyze( array $model, int $post_id, string $subtree_id ): array { $keys = array( 'padding', 'margin', 'width', '_column_size' ); $source = ''; $row = null; foreach ( (array) $model['rows'] as $candidate ) { if ( (int) $candidate['lane_count'] >= 2 ) { $row = $candidate; break; } } if ( null === $row ) { return Design_Mutator::report( array( 'changed' => array(), 'applied' => false ), '', __( 'No row in scope has two or more lanes, so there are no siblings to copy between.', 'acrossai-abilities-manager' ) ); } $lanes = (array) $row['lanes']; $first = (array) ( $lanes[0] ?? array() ); $source = (string) ( $first['id'] ?? '' ); $from = (array) ( $first['settings'] ?? array() ); $payload = array(); foreach ( $keys as $key ) { if ( array_key_exists( $key, $from ) ) { $payload[ $key ] = $from[ $key ]; } } if ( array() === $payload ) { return Design_Mutator::report( array( 'changed' => array(), 'applied' => false ), '', __( 'The source lane sets no spacing of its own, so there is nothing to copy.', 'acrossai-abilities-manager' ) ); } $siblings = array_values( array_filter( array_map( static fn( array $l ): string => (string) $l['id'], $lanes ), static fn( string $id ): bool => '' !== $id && $id !== $source ) ); $result = Design_Mutator::edit( $model, static function ( array &$settings, array $element ) use ( $siblings, $payload ): array { if ( ! in_array( (string) ( $element['id'] ?? '' ), $siblings, true ) ) { return array(); } $changes = array(); foreach ( $payload as $key => $value ) { $changes = array_merge( $changes, Design_Mutator::set( $settings, (string) $key, $value ) ); } return $changes; } ); if ( is_wp_error( $result ) ) { return $result; } return Design_Mutator::report( $result, sprintf( /* translators: %s: source lane id */ __( 'Copied spacing from lane %s onto its siblings.', 'acrossai-abilities-manager' ), $source ), __( 'Sibling lanes already matched the source, so nothing was changed.', 'acrossai-abilities-manager' ) ); } }