-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuagb-static-form.php
51 lines (46 loc) · 2.14 KB
/
uagb-static-form.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Plugin Name: UAGB Static Form
* Plugin URI: https://github.com/natbienetre/uagb-static-form
* Description: Patching the UAGB form block for Gutenberg to work with Simply Static.
* Author: Pierre PÉRONNET <[email protected]>
* Version: 0.0.1
*/
define( 'UAGB_STATIC_FORM_PATH', 'uagb-static-form' );
/**
* Patch the rendering of the UAGB form block to work with Simply Static.
*
* This function adds the action attribute to the form tag.
*
* @param string $block_content The block content.
* @param array $block The block attributes.
* @param WP_Block $instance The block instance.
*/
function uagb_static_form_render_block_uagb_forms( string $block_content, array $block, WP_Block $instance ) {
$actionDestination = $instance->attributes['action_destination'];
if ( ! $actionDestination ) {
return $block_content;
}
return str_ireplace( '<form', '<form action="' . esc_url( $actionDestination ) . '"', $block_content );
}
add_filter( 'render_block_uagb/forms', 'uagb_static_form_render_block_uagb_forms', 10, 3 );
function uagd_static_form_enqueue_block_editor_assets() {
if ( ! wp_enqueue_script( 'uagb-static-form-editor-assets', plugin_dir_url( __FILE__ ) . 'build/index.js', array( 'wp-blocks', 'wp-element' ), filemtime( plugin_dir_path( __FILE__ ) . 'build/index.js' ), false ) ) {
add_action( 'admin_notices', function() {
?><div class="notice notice-error">
<p><?php _e( 'Failed to enqueue the UAGB Static Form editor assets.', 'uagb-static-form' ); ?></p>
</div><?php
} );
}
}
add_action( 'enqueue_block_editor_assets', 'uagd_static_form_enqueue_block_editor_assets' );
function uagd_static_form_load_textdomain() {
if ( ! load_plugin_textdomain( 'uagb-static-form', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ) ) {
add_action( 'admin_notices', function() {
?><div class="notice notice-error">
<p><?php _e( 'Failed to load the UAGB Static Form text domain.', 'uagb-static-form' ); ?></p>
</div><?php
} );
}
}
add_action( 'init', 'uagd_static_form_load_textdomain' );