*/ const OPTIONS = array( 'clip' => array( 'peg', 'binder', 'tape' ), 'sag' => array( 'little', 'more' ), 'length' => array( 'medium', 'short', 'long' ), ); /** * The block's folder name. * * @return string */ public function slug() { return 'hanging-rail'; } /** * The option classes, with the default for anything missing or unknown. * * @param array $attributes Block attributes. * @return string[] Class names. */ public static function classes( $attributes ) { $classes = array(); foreach ( self::OPTIONS as $option => $values ) { $value = isset( $attributes[ $option ] ) ? $attributes[ $option ] : ''; $classes[] = 'purplish-rail-' . $option . '-' . ( in_array( $value, $values, true ) ? $value : $values[0] ); } return $classes; } /** * The wrapper and a stage that holds the inner blocks, so the section * can stick while the page scrolls through it. * * @param array $attributes Block attributes. * @param string $content Rendered inner blocks. * @param \WP_Block $block Block instance. * @return string */ public function render( $attributes, $content, $block ) { return sprintf( '
%2$s
', get_block_wrapper_attributes( array( 'class' => implode( ' ', self::classes( $attributes ) ) ) ), $content ); } }