forms = new ConvertKit_Resource_Forms( 'block_formatter_register' ); if ( $this->forms->non_inline_exist() ) { add_filter( 'convertkit_get_block_formatters', array( $this, 'register' ) ); } // Enqueue JS in footer if links exist in the content that have the formatter applied. add_filter( 'the_content', array( $this, 'maybe_enqueue_scripts' ) ); } /** * Returns this formatter's programmatic name, excluding the convertkit- prefix. * * @since 2.2.0 * * @return string */ public function get_name() { return 'form-link'; } /** * Returns this formatters's Title, Description and Icon * * @since 2.2.0 * * @return array */ public function get_overview() { return array( 'title' => __( 'Kit Form Trigger', 'convertkit' ), 'description' => __( 'Displays a modal, sticky bar or slide in form to display when the link is pressed.', 'convertkit' ), 'icon' => 'resources/backend/images/block-icon-formtrigger.svg', // Gutenberg: Block Icon in Editor. 'gutenberg_icon' => convertkit_get_file_contents( CONVERTKIT_PLUGIN_PATH . '/resources/backend/images/block-icon-formtrigger.svg' ), ); } /** * Returns this formatter's attributes, which are applied * to the tag. * * @since 2.2.0 * * @return array */ public function get_attributes() { return array( 'data-id' => '', 'data-formkit-toggle' => '', 'href' => '', ); } /** * Returns this formatter's fields to display when the formatter * button is clicked in the toolbar. * * @since 2.2.0 * * @return bool|array */ public function get_fields() { // Bail if the request is not for the WordPress Administration or frontend editor. if ( ! WP_ConvertKit()->is_admin_or_frontend_editor() ) { return false; } // Get non-inline ConvertKit Forms. $forms = array(); $forms_data = array(); if ( $this->forms->exist() ) { foreach ( $this->forms->get_non_inline() as $form ) { // Add this form's necessary to the attribute arrays. // Legacy forms don't include a `format` key, so define them as inline. $forms[ absint( $form['id'] ) ] = sprintf( '%s [%s]', sanitize_text_field( $form['name'] ), ( ! empty( $form['format'] ) ? sanitize_text_field( $form['format'] ) : 'inline' ) ); $forms_data[ absint( $form['id'] ) ] = array( 'data-id' => sanitize_text_field( $form['id'] ), 'data-formkit-toggle' => sanitize_text_field( $form['uid'] ), 'href' => $form['embed_url'], ); } } // Return field. return array( 'data-id' => array( 'label' => __( 'Form', 'convertkit' ), 'type' => 'select', 'description' => __( 'The modal, sticky bar or slide in form to display when the text is clicked.', 'convertkit' ), // Key/value pairs for the