$model * @param int $post_id * @param string $subtree_id * @return array */ protected function analyze( array $model, int $post_id, string $subtree_id ): array { $rows = array_values( (array) $model['rows'] ); if ( count( $rows ) < 3 ) { return Design_Mutator::report( array( 'changed' => array(), 'applied' => false ), '', __( 'Fewer than three sections in scope, so there is no boundary rhythm to enforce.', 'acrossai-abilities-manager' ) ); } $bottoms = array(); foreach ( $rows as $row ) { $padding = ( (array) $row['settings'] )['padding'] ?? null; if ( is_array( $padding ) && isset( $padding['bottom'] ) && is_numeric( $padding['bottom'] ) ) { $bottoms[] = (string) $padding['bottom']; } } if ( count( $bottoms ) < 2 ) { return Design_Mutator::report( array( 'changed' => array(), 'applied' => false ), '', __( 'Too few sections set their own bottom padding for a majority boundary to exist.', 'acrossai-abilities-manager' ) ); } $tallies = array_count_values( $bottoms ); arsort( $tallies ); $target = (string) array_key_first( $tallies ); $row_ids = array_map( static fn( array $r ): string => (string) $r['id'], $rows ); $result = Design_Mutator::edit( $model, static function ( array &$settings, array $element ) use ( $row_ids, $target ): array { if ( ! in_array( (string) ( $element['id'] ?? '' ), $row_ids, true ) ) { return array(); } if ( ! isset( $settings['padding'] ) || ! is_array( $settings['padding'] ) ) { return array(); } $padding = $settings['padding']; $padding['bottom'] = $target; return Design_Mutator::set( $settings, 'padding', $padding ); } ); if ( is_wp_error( $result ) ) { return $result; } return Design_Mutator::report( $result, sprintf( /* translators: %s: bottom padding value */ __( 'Set every section that defines its own bottom padding to the majority value (%s), so each boundary contributes the same gap.', 'acrossai-abilities-manager' ), $target ), __( 'Every section boundary already contributed the same gap, so nothing was changed.', 'acrossai-abilities-manager' ) ); } }