Edit File by line
/home/barbar84/www/wp-conte.../plugins/ninja-fo.../blocks
File: bootstrap.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Register blocks and there scripts
[3] Fix | Delete
*/
[4] Fix | Delete
add_action('init', function () {
[5] Fix | Delete
/**
[6] Fix | Delete
* Form Block
[7] Fix | Delete
*/
[8] Fix | Delete
// automatically load dependencies and version
[9] Fix | Delete
$block_asset_file = include dirname(__DIR__) . '/build/form-block.asset.php';
[10] Fix | Delete
$block = (array)json_decode(file_get_contents(__DIR__ . '/form/block.json'), true);
[11] Fix | Delete
[12] Fix | Delete
wp_register_script(
[13] Fix | Delete
'ninja-forms/form',
[14] Fix | Delete
plugins_url('../build/form-block.js', __FILE__),
[15] Fix | Delete
$block_asset_file['dependencies'],
[16] Fix | Delete
$block_asset_file['version']
[17] Fix | Delete
);
[18] Fix | Delete
[19] Fix | Delete
register_block_type('ninja-forms/form', array_merge($block, [
[20] Fix | Delete
'title' => esc_attr__('Ninja Form', 'ninja-forms'),
[21] Fix | Delete
'render_callback' => function ($atts) {
[22] Fix | Delete
$formID = isset($atts['formID']) ? $atts['formID'] : 1;
[23] Fix | Delete
ob_start();
[24] Fix | Delete
Ninja_Forms()->display( absint($formID), true );
[25] Fix | Delete
return ob_get_clean();
[26] Fix | Delete
},
[27] Fix | Delete
'editor_script' => 'ninja-forms/form'
[28] Fix | Delete
]));
[29] Fix | Delete
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* Views Block
[33] Fix | Delete
*/
[34] Fix | Delete
$token = NinjaForms\Blocks\Authentication\TokenFactory::make();
[35] Fix | Delete
$publicKey = NinjaForms\Blocks\Authentication\KeyFactory::make();
[36] Fix | Delete
[37] Fix | Delete
// automatically load dependencies and version
[38] Fix | Delete
$block_asset_file = include dirname(__DIR__) . '/build/sub-table-block.asset.php';
[39] Fix | Delete
wp_register_script(
[40] Fix | Delete
'ninja-forms/submissions-table/block',
[41] Fix | Delete
plugins_url('../build/sub-table-block.js', __FILE__),
[42] Fix | Delete
$block_asset_file['dependencies'],
[43] Fix | Delete
$block_asset_file['version']
[44] Fix | Delete
);
[45] Fix | Delete
[46] Fix | Delete
wp_localize_script('ninja-forms/submissions-table/block', 'ninjaFormsViews', [
[47] Fix | Delete
'token' => $token->create($publicKey),
[48] Fix | Delete
]);
[49] Fix | Delete
[50] Fix | Delete
$render_asset_file = include dirname(__DIR__) . '/build/sub-table-render.asset.php';
[51] Fix | Delete
wp_register_script(
[52] Fix | Delete
'ninja-forms/submissions-table/render',
[53] Fix | Delete
plugins_url('../build/sub-table-render.js', __FILE__),
[54] Fix | Delete
$render_asset_file['dependencies'],
[55] Fix | Delete
$render_asset_file['version']
[56] Fix | Delete
);
[57] Fix | Delete
[58] Fix | Delete
wp_localize_script('ninja-forms/submissions-table/render', 'ninjaFormsViews', [
[59] Fix | Delete
'token' => $token->create($publicKey),
[60] Fix | Delete
]);
[61] Fix | Delete
[62] Fix | Delete
register_block_type('ninja-forms/submissions-table', array(
[63] Fix | Delete
'editor_script' => 'ninja-forms/submissions-table/block',
[64] Fix | Delete
'render_callback' => function ($attributes, $content) {
[65] Fix | Delete
if (isset($attributes['formID']) && $attributes['formID']) {
[66] Fix | Delete
wp_enqueue_script('ninja-forms/submissions-table/render');
[67] Fix | Delete
$className = 'ninja-forms-views-submissions-table';
[68] Fix | Delete
if (isset($attributes['alignment'])) {
[69] Fix | Delete
$className .= ' align' . $attributes['alignment'];
[70] Fix | Delete
}
[71] Fix | Delete
return sprintf("<div class='%s' data-attributes='%s'></div>", esc_attr($className),
[72] Fix | Delete
esc_attr(wp_json_encode($attributes)));
[73] Fix | Delete
}
[74] Fix | Delete
}
[75] Fix | Delete
));
[76] Fix | Delete
[77] Fix | Delete
/**
[78] Fix | Delete
* Have Translations set in scripts via i18n package
[79] Fix | Delete
* https://developer.wordpress.org/block-editor/packages/packages-i18n/
[80] Fix | Delete
* https://developer.wordpress.org/reference/functions/wp_set_script_translations/
[81] Fix | Delete
* https://developer.wordpress.org/block-editor/developers/internationalization/
[82] Fix | Delete
*/
[83] Fix | Delete
wp_set_script_translations( "ninja-forms/form", "ninja-forms", plugin_dir_path( __FILE__ ) . 'lang' );
[84] Fix | Delete
wp_set_script_translations( "ninja-forms/submissions-table/block", "ninja-forms", plugin_dir_path( __FILE__ ) . 'lang' );
[85] Fix | Delete
wp_set_script_translations( "ninja-forms/submissions-table/render", "ninja-forms", plugin_dir_path( __FILE__ ) . 'lang' );
[86] Fix | Delete
[87] Fix | Delete
});
[88] Fix | Delete
[89] Fix | Delete
/**
[90] Fix | Delete
* Localize data for blocks
[91] Fix | Delete
*/
[92] Fix | Delete
add_action('admin_enqueue_scripts', function () {
[93] Fix | Delete
//Get all forms, to base form selector on.
[94] Fix | Delete
$formsBuilder = (new NinjaForms\Blocks\DataBuilder\FormsBuilderFactory)->make();
[95] Fix | Delete
$forms = $formsBuilder->get();
[96] Fix | Delete
if (!empty($forms)) {
[97] Fix | Delete
//Escape for use in JavaScript
[98] Fix | Delete
foreach ($forms as $key => $form) {
[99] Fix | Delete
$forms[$key] = [
[100] Fix | Delete
'formID' => absint($form['formID']),
[101] Fix | Delete
'formTitle' => esc_textarea($form['formTitle'])
[102] Fix | Delete
];
[103] Fix | Delete
}
[104] Fix | Delete
}
[105] Fix | Delete
wp_localize_script('ninja-forms/form', 'nfFormsBlock', [
[106] Fix | Delete
'forms' => $forms,//array keys escaped above
[107] Fix | Delete
'siteUrl' => esc_url_raw(site_url()),
[108] Fix | Delete
'previewToken' => wp_create_nonce('nf_iframe' )
[109] Fix | Delete
]);
[110] Fix | Delete
});
[111] Fix | Delete
[112] Fix | Delete
/**
[113] Fix | Delete
* Register REST API routes related to blocks
[114] Fix | Delete
*/
[115] Fix | Delete
add_action('rest_api_init', function () {
[116] Fix | Delete
[117] Fix | Delete
$tokenAuthenticationCallback = function (WP_REST_Request $request) {
[118] Fix | Delete
$token = NinjaForms\Blocks\Authentication\TokenFactory::make();
[119] Fix | Delete
return $token->validate($request->get_header('X-NinjaFormsViews-Auth'));
[120] Fix | Delete
};
[121] Fix | Delete
[122] Fix | Delete
register_rest_route('ninja-forms-views', 'forms', array(
[123] Fix | Delete
'methods' => 'GET',
[124] Fix | Delete
'callback' => function (WP_REST_Request $request) {
[125] Fix | Delete
$formsBuilder = (new NinjaForms\Blocks\DataBuilder\FormsBuilderFactory)->make();
[126] Fix | Delete
return $formsBuilder->get();
[127] Fix | Delete
},
[128] Fix | Delete
'permission_callback' => '__return_true',
[129] Fix | Delete
));
[130] Fix | Delete
[131] Fix | Delete
register_rest_route('ninja-forms-views', 'forms/(?P<id>\d+)/fields', [
[132] Fix | Delete
'methods' => 'GET',
[133] Fix | Delete
'args' => [
[134] Fix | Delete
'id' => [
[135] Fix | Delete
'required' => true,
[136] Fix | Delete
'description' => esc_attr__('Unique identifier for the object.', 'ninja-forms'),
[137] Fix | Delete
'type' => 'integer',
[138] Fix | Delete
'validate_callback' => 'rest_validate_request_arg',
[139] Fix | Delete
],
[140] Fix | Delete
],
[141] Fix | Delete
'callback' => function (WP_REST_Request $request) {
[142] Fix | Delete
$fieldsBuilder = (new NinjaForms\Blocks\DataBuilder\FieldsBuilderFactory)->make(
[143] Fix | Delete
$request->get_param('id')
[144] Fix | Delete
);
[145] Fix | Delete
return $fieldsBuilder->get();
[146] Fix | Delete
},
[147] Fix | Delete
'permission_callback' => $tokenAuthenticationCallback,
[148] Fix | Delete
]);
[149] Fix | Delete
[150] Fix | Delete
register_rest_route('ninja-forms-views', 'forms/(?P<id>\d+)/submissions', [
[151] Fix | Delete
'methods' => 'GET',
[152] Fix | Delete
'args' => [
[153] Fix | Delete
'id' => [
[154] Fix | Delete
'required' => true,
[155] Fix | Delete
'description' => esc_attr__('Unique identifier for the object.', 'ninja-forms'),
[156] Fix | Delete
'type' => 'integer',
[157] Fix | Delete
'validate_callback' => 'rest_validate_request_arg',
[158] Fix | Delete
],
[159] Fix | Delete
'perPage' => [
[160] Fix | Delete
'description' => esc_attr__('Maximum number of items to be returned in result set.', 'ninja-forms'),
[161] Fix | Delete
'type' => 'integer',
[162] Fix | Delete
'minimum' => 1,
[163] Fix | Delete
'maximum' => 100,
[164] Fix | Delete
'sanitize_callback' => 'absint',
[165] Fix | Delete
'validate_callback' => 'rest_validate_request_arg',
[166] Fix | Delete
],
[167] Fix | Delete
'page' => [
[168] Fix | Delete
'description' => esc_attr__('Current page of the collection.', 'ninja-forms'),
[169] Fix | Delete
'type' => 'integer',
[170] Fix | Delete
'default' => 1,
[171] Fix | Delete
'sanitize_callback' => 'absint',
[172] Fix | Delete
'validate_callback' => 'rest_validate_request_arg',
[173] Fix | Delete
'minimum' => 1,
[174] Fix | Delete
]
[175] Fix | Delete
],
[176] Fix | Delete
'callback' => function (WP_REST_Request $request) {
[177] Fix | Delete
$submissionsBuilder = (new NinjaForms\Blocks\DataBuilder\SubmissionsBuilderFactory)->make(
[178] Fix | Delete
$request->get_param('id'),
[179] Fix | Delete
$request->get_param('perPage'),
[180] Fix | Delete
$request->get_param('page')
[181] Fix | Delete
);
[182] Fix | Delete
return $submissionsBuilder->get();
[183] Fix | Delete
},
[184] Fix | Delete
'permission_callback' => $tokenAuthenticationCallback,
[185] Fix | Delete
]);
[186] Fix | Delete
[187] Fix | Delete
});
[188] Fix | Delete
[189] Fix | Delete
/**
[190] Fix | Delete
* Handler for form preview iFrame used in Forms block
[191] Fix | Delete
*/
[192] Fix | Delete
add_action( 'wp_head', function () {
[193] Fix | Delete
// check for preview and iframe get parameters
[194] Fix | Delete
if( isset( $_GET[ 'nf_preview_form' ] ) && isset( $_GET[ 'nf_iframe' ] ) ){
[195] Fix | Delete
if( ! wp_verify_nonce( $_GET['nf_iframe'], 'nf_iframe') ){
[196] Fix | Delete
wp_die( esc_html__('Preview token failed validation', 'ninja-forms'));
[197] Fix | Delete
exit;
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
//Attempt to get theme background color
[201] Fix | Delete
$background = '#fff';
[202] Fix | Delete
$supports = get_theme_support('editor-color-palette','background');
[203] Fix | Delete
if( is_array($supports) ){
[204] Fix | Delete
foreach($supports[0] as $index => $support ){
[205] Fix | Delete
if( 'background' === $support['slug']){
[206] Fix | Delete
$background = $support['color'];
[207] Fix | Delete
break;
[208] Fix | Delete
}
[209] Fix | Delete
}
[210] Fix | Delete
}
[211] Fix | Delete
[212] Fix | Delete
$js_dir = Ninja_Forms::$url . 'assets/js/min/';
[213] Fix | Delete
[214] Fix | Delete
$form_id = absint( $_GET[ 'nf_preview_form' ] );
[215] Fix | Delete
// Style below: update width and height for particular form
[216] Fix | Delete
?>
[217] Fix | Delete
<style media="screen">
[218] Fix | Delete
#wpadminbar {
[219] Fix | Delete
display: none;
[220] Fix | Delete
}
[221] Fix | Delete
#nf-form-<?php echo $form_id; ?>-cont {
[222] Fix | Delete
z-index: 90000001;
[223] Fix | Delete
position: fixed;
[224] Fix | Delete
top: 0; left: 0;
[225] Fix | Delete
width: 100vw;
[226] Fix | Delete
height: 100vh;
[227] Fix | Delete
background-color: <?php echo sanitize_hex_color($background ); ?>;
[228] Fix | Delete
}
[229] Fix | Delete
[230] Fix | Delete
div.site-branding, header.entry-header, .site-footer, header, .footer-nav-widgets-wrapper {
[231] Fix | Delete
display:none !important;
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
</style>
[235] Fix | Delete
[236] Fix | Delete
<?php
[237] Fix | Delete
[238] Fix | Delete
// register our script to target the form iFrame in page builder
[239] Fix | Delete
wp_register_script(
[240] Fix | Delete
'ninja-forms-block-setup',
[241] Fix | Delete
$js_dir . 'blockFrameSetup.js',
[242] Fix | Delete
array( 'underscore', 'jquery' )
[243] Fix | Delete
);
[244] Fix | Delete
[245] Fix | Delete
wp_localize_script( 'ninja-forms-block-setup', 'ninjaFormsBlockSetup', array(
[246] Fix | Delete
'form_id' => $form_id
[247] Fix | Delete
) );
[248] Fix | Delete
[249] Fix | Delete
wp_enqueue_script( 'ninja-forms-block-setup' );
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
});
[253] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function