is_active() ) { $properties += array( 'wpc_notion' => array(), ); } return $properties; } /** * Saves the wpc_notion property value. * * @param WPCF7_ContactForm $contact_form A WPCF7_ContactForm instance. * @see 'wpcf7_save_contact_form' action hook */ function save_contact_form( $contact_form ) { $service = WPCF7_Notion_Service::get_instance(); if ( ! $service->is_active() ) { return; } // Nonce checked by WPCF7 {@see wpcf7_load_contact_form_admin} and sanitize functions apply on each prop. // phpcs:ignore WordPress.Security.NonceVerification.Missing $prop = isset( $_POST['wpc-wpcf7-notion'] ) ? (array) wp_unslash( $_POST['wpc-wpcf7-notion'] ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing : array(); $prop = wp_parse_args( $prop, array( 'enable_database' => false, 'database_selected' => '', 'mapping' => array(), ) ); $prop['enable_database'] = (bool) $prop['enable_database']; $prop['database_selected'] = sanitize_key( $prop['database_selected'] ); if ( $prop['enable_database'] && $prop['database_selected'] ) { $columns = Helpers\get_notion_databases_columns( $prop['database_selected'] ); $columns_keys = array_keys( $columns ); $prop['mapping'] = array_filter( $prop['mapping'], function ( $column_id ) use ( $columns_keys ) { return in_array( $column_id, $columns_keys, true ); } ); } $contact_form->set_properties( array( 'wpc_notion' => $prop, ) ); } /** * Builds the editor panel for the wpc_notion property. * * @param array $panels Contact Form 7 panels. * @see 'wpcf7_editor_panels' filter hook. */ function editor_panels( $panels ) { $service = WPCF7_Notion_Service::get_instance(); if ( ! $service->is_active() ) { return $panels; } $contact_form = \WPCF7_ContactForm::get_current(); $prop = wp_parse_args( $contact_form->prop( 'wpc_notion' ), array( 'enable_database' => false, 'database_selected' => '', 'mapping' => array(), ) ); $editor_panel = function () use ( $prop, $service, $contact_form ) { $description = sprintf( /* translators: %s: html link */ esc_html( __( 'You can set up the Notion integration here. For details, see %s.', 'add-on-cf7-for-notion' ) ), str_replace( 'get_databases(); $database_selected = false; $inline_script = " jQuery(function ($) { var enableDatabaseCheck = $('#wpc-wpcf7-notion-enable-database-list'); enableDatabaseCheck.change(function () { if ($(this).prop('checked')) { $(this).closest('tr').removeClass('inactive'); } else { $(this).closest('tr').addClass('inactive'); } }); $('.js-wpc-wpcf7-notion-mapping-table').each(function () { var selects = $('.js-wpc-wpcf7-notion-mapping-select'); var getSelectedNotionFieldIds = function () { return selects.map(function () { return $(this).val(); }).toArray().filter(function (val) { return val !== ''; }); }; var updateAvailableFields = function () { selects.each(function () { var select = $(this); var selectedIds = getSelectedNotionFieldIds(); $(this).find('option').each(function () { $(this).prop('disabled', $(this).val() !== select.val() && selectedIds.indexOf($(this).val()) > -1); }); }); }; selects.change(updateAvailableFields); updateAvailableFields(); }); });"; wp_register_script( 'wpc-wpcf7-notion-contact-form-properties', '', array( 'jquery' ), WPCONNECT_WPCF7_NTN_VERSION, true ); wp_enqueue_script( 'wpc-wpcf7-notion-contact-form-properties' ); wp_add_inline_script( 'wpc-wpcf7-notion-contact-form-properties', $inline_script ); ?>
WP Connect logo


id ); $supported_remote_types = $field_mapper->get_supported_notion_types(); $available_columns_name = array_reduce( $columns, function ( $columns_name, $column ) use ( $supported_remote_types ) { if ( in_array( $column->type, $supported_remote_types, true ) ) { $columns_name[] = $column->name; } return $columns_name; }, array() ); $mapped_tags = Helpers\get_mapped_tags_from_contact_form( $contact_form, $columns ); $mapped_columns = array(); // Make sure mapped tags are compatible. $cleaned_mapped_tags = $field_mapper->filter_mapped_tags( $mapped_tags ); $wrongly_mapped_tags = array_diff_key( $mapped_tags, $cleaned_mapped_tags ); $displayed_file_warning = false; foreach ( $contact_form->scan_form_tags() as $tag ) { if ( empty( $tag->name ) ) { continue; } if ( 'file' === Helpers\normalize_cf7_field_type( $tag->basetype ) && ! $displayed_file_warning ) { echo '
'; echo '

' . esc_html__( 'Due to Notion API limitation your field file-upload won\'t be transfered as an image but as a link.', 'add-on-cf7-for-notion' ) . '

'; echo '
'; $displayed_file_warning = true; } ?> name; $selected_column_id = ''; $selected_column_name = ''; $mapped_class = ''; $mapped_text = $tag_name; $mapped_error_desc = ''; if ( isset( $cleaned_mapped_tags[ $tag_name ] ) ) { $selected_column_name = $cleaned_mapped_tags[ $tag_name ]['notion_field_name']; $selected_column_id = $cleaned_mapped_tags[ $tag_name ]['notion_field_id']; $mapped_class = 'is-mapped'; /* translators: %s: tag name */ $mapped_text = sprintf( __( '%s: mapped', 'add-on-cf7-for-notion' ), $tag_name ); } elseif ( isset( $wrongly_mapped_tags[ $tag_name ] ) ) { $selected_column_name = $wrongly_mapped_tags[ $tag_name ]['notion_field_name']; $selected_column_id = $wrongly_mapped_tags[ $tag_name ]['notion_field_id']; $mapped_class = 'is-error'; /* translators: %s: tag name */ $mapped_text = sprintf( __( '%s: error', 'add-on-cf7-for-notion' ), $tag_name ); if ( empty( $selected_column_name ) || ! in_array( $selected_column_name, $available_columns_name, true ) ) { $mapped_error_desc = __( 'The mapped column does not exist or its type is not supported', 'add-on-cf7-for-notion' ); } else { /* translators: %s: WPCF7 tag type */ $mapped_error_desc = sprintf( __( 'The column is not supported by the tag type "%s"', 'add-on-cf7-for-notion' ), $wrongly_mapped_tags[ $tag_name ]['type'] ); } } if ( ! empty( $selected_column_name ) ) { $mapped_columns[] = $selected_column_name; } ?>
0 ) { ?>

' . esc_html( implode( ', ', $unmapped_columns_name ) ); ?>

array( 'title' => __( 'Notion', 'add-on-cf7-for-notion' ), 'callback' => $editor_panel, ), ); return $panels; }