$model * @param int $post_id * @param string $subtree_id * @return array */ protected function analyze( array $model, int $post_id, string $subtree_id ): array { $tallies = array(); $targets = array(); foreach ( (array) $model['rows'] as $row ) { if ( (int) $row['lane_count'] < 2 ) { continue; } $targets[] = (string) $row['id']; $gap = ( (array) $row['settings'] )['gap'] ?? null; if ( ! is_array( $gap ) || ! isset( $gap['size'] ) ) { continue; } $key = wp_json_encode( array( $gap['size'], $gap['unit'] ?? 'px' ) ); $tallies[ $key ] = ( $tallies[ $key ] ?? 0 ) + 1; } if ( array() === $tallies ) { return Design_Mutator::report( array( 'changed' => array(), 'applied' => false ), '', __( 'No multi-lane row in scope sets its own gap, so there is no majority rhythm to apply and nothing was changed.', 'acrossai-abilities-manager' ) ); } arsort( $tallies ); $winner = json_decode( (string) array_key_first( $tallies ), true ); $size = $winner[0] ?? ''; $unit = (string) ( $winner[1] ?? 'px' ); $result = Design_Mutator::edit( $model, static function ( array &$settings, array $element ) use ( $targets, $size, $unit ): array { if ( ! in_array( (string) ( $element['id'] ?? '' ), $targets, true ) ) { return array(); } return Design_Mutator::set( $settings, 'gap', array( 'unit' => $unit, 'size' => $size, 'sizes' => array() ) ); } ); if ( is_wp_error( $result ) ) { return $result; } return Design_Mutator::report( $result, sprintf( /* translators: 1: gap size, 2: unit */ __( 'Applied the majority column gap (%1$s%2$s) to every multi-lane row in scope.', 'acrossai-abilities-manager' ), (string) $size, $unit ), __( 'Every multi-lane row already used the majority gap, so nothing was changed.', 'acrossai-abilities-manager' ) ); } }