1 | | Needs Gutenberg PR to work: |
2 | | https://github.com/WordPress/gutenberg/pull/67802/ |
| 1 | ''This ticket was mentioned in [https://github.com/WordPress/wordpress-develop/pull/7987 PR #7987] on [https://github.com/WordPress/wordpress-develop/ WordPress/wordpress-develop] by [https://profiles.wordpress.org/cbravobernal/ @cbravobernal].'' |
| 2 | Trac ticket: https://core.trac.wordpress.org/ticket/62705 |
| 3 | |
| 4 | ## What? |
| 5 | I'm experimenting if it is possible to add sources to the UI just by defining them on the server side. It will need a PR in Gutenberg to be landed. |
| 6 | |
| 7 | This registration: |
| 8 | |
| 9 | {{{ |
| 10 | #!php |
| 11 | register_block_bindings_source( |
| 12 | 'bbe/now-date', |
| 13 | array( |
| 14 | 'label' => __( 'Current date', 'custom-bindings' ), |
| 15 | 'get_value_callback' => function ( array $source_args, $block_instance ) { |
| 16 | return gmdate( $source_args['key'] ); |
| 17 | }, |
| 18 | 'fields' => |
| 19 | array( |
| 20 | 'Y-m-d H:i:s' => array( |
| 21 | 'type' => 'string', |
| 22 | 'value' => 'Y-m-d H:i:s', |
| 23 | ), |
| 24 | 'D' => array( |
| 25 | 'type' => 'string', |
| 26 | 'value' => 'D', |
| 27 | ), |
| 28 | ), |
| 29 | ) |
| 30 | ); |
| 31 | }}} |
| 32 | |
| 33 | |
| 34 | will return: |
| 35 | |
| 36 | [[Image(https://github.com/user-attachments/assets/0e08f37c-829a-46c9-880c-511453bc20d4)]] |
| 37 | |
| 38 | We are using keys as the source arguments to decide the format. It's an approach I'm not 100% comfortable with. We may need to update the JS API. |
| 39 | [[Image(https://github.com/user-attachments/assets/71246745-a02f-432c-b6b0-69157bdccec4)]] |
| 40 | |
| 41 | |
| 42 | [[Image(https://github.com/user-attachments/assets/60f7934a-e772-457f-8be7-f9ca32fd1a1e)]] |