[], 'connected' => true ]; // Best to do this formation in one spot if(!empty($all_settings) && !empty($all_settings['forms'])){ foreach($all_settings['forms'] as $form){ $script_src = activecampaign_form_script_src($all_settings, $form, false, null, true); if(isset($script_src)){ $settings['forms'][$form['id']] = [ 'script_container_id' => '_form_'.$form['id'], 'script_src' => $script_src, 'name' => $form['name'], 'id' => $form['id'], 'version' => $form['version'], ]; } } } elseif(empty($all_settings) || empty($all_settings['api_url']) || empty($all_settings['api_key'])){ $settings['connected'] = false; } $block_attributes = [ 'className' => [ 'type' => 'string', 'default' => '' ], 'formId' => [ 'type' => 'string', 'default' => '0' ], 'useCss' => [ 'type' => 'string', 'default' => 'global' ], 'settings_activecampaign' => [ 'type' => 'object', 'default' => $settings ], // Indicates dynamic block update 'hasRenderCallback' => [ 'type' => 'boolean', 'default' => false ], 'migrationVersion' => [ 'type' => 'integer', 'default' => 0 ] ]; register_block_type( 'activecampaign-form/activecampaign-form-block', [ 'editor_script' => 'activecampaign-form-block-editor', 'editor_style' => 'activecampaign-form-block-editor', 'style' => 'activecampaign-form-block', 'attributes' => $block_attributes, 'render_callback' => 'activecampaign_form_block_render' ] ); } function activecampaign_form_block_render($attributes, $content){ // can compare $attributes['migrationVersion'] for conditional rendering based on attribute changes // CSS support still needs global setting support for un-upgraded blocks $css = ''; // global fallback if(isset($attributes['useCss']) && $attributes['useCss'] === '0'){ $css = ' css=0'; } elseif(isset($attributes['useCss']) && $attributes['useCss'] === '1'){ $css = ' css=1'; } $escapedClassNames = esc_attr($attributes['className']); if(!empty($attributes['formId'])){ return "
[activecampaign form=".$attributes['formId'].$css."]
"; } return "
[activecampaign]
"; }