403 ) ); } // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only screen selection. Changes verify a POST nonce and capabilities. $id = absint( $_GET['form_id'] ?? 0 ); $mode = sanitize_key( wp_unslash( $_GET['af_mode'] ?? 'manual' ) ); $saved = ! empty( $_GET['af_saved'] ); // phpcs:enable WordPress.Security.NonceVerification.Recommended if ( ! Schema::get( $id ) ) { wp_die( esc_html__( 'Publish this form before choosing where it appears.', 'accessible-forms-by-accessible-org' ), '', array( 'back_link' => true ) ); } $tabs = (array) Extensions::filter( 'accessible_forms_placement_tabs', array( 'manual' => __( 'One page or post', 'accessible-forms-by-accessible-org' ), 'block' => __( 'Block or shortcode', 'accessible-forms-by-accessible-org' ), ), $id ); if ( ! isset( $tabs[ $mode ] ) ) { $mode = 'manual'; } // Shared with add-on tabs that search content. wp_register_script( 'accessible-forms-admin-search', ACCESSIBLE_FORMS_URL . 'assets/admin-search.js', array(), \AccessibleForms\VERSION, true ); wp_enqueue_script( 'accessible-forms-placement-settings', ACCESSIBLE_FORMS_URL . 'assets/placement-settings.js', array( 'wp-i18n' ), \AccessibleForms\VERSION, true ); wp_set_script_translations( 'accessible-forms-placement-settings', 'accessible-forms-by-accessible-org' ); $async_tabs = (array) Extensions::filter( 'accessible_forms_async_tabs', array( 'manual', 'block' ), 'placement' ); echo '

' . esc_html__( 'Where this form appears', 'accessible-forms-by-accessible-org' ) . '

' . esc_html( get_the_title( $id ) ) . ': ' . esc_html__( 'Use the same accessible form in one place or across your site.', 'accessible-forms-by-accessible-org' ) . '

'; if ( current_user_can( 'edit_post', $id ) ) { echo '

' . esc_html__( 'Back to form settings', 'accessible-forms-by-accessible-org' ) . '

'; } echo ''; self::render_panel( $mode, $id, $saved ); foreach ( array_intersect( array( 'manual', 'block' ), array_keys( $tabs ), $async_tabs ) as $key ) { if ( $key !== $mode ) { Navigation::preload( Placement::url( $id, array( 'af_mode' => $key ) ), static function () use ( $key, $id ) { self::render_panel( $key, $id, false ); } ); } } echo '
'; } private static function render_panel( $mode, $id, $saved ) { echo '
'; if ( 'block' === $mode ) { self::block( $id ); } elseif ( 'manual' === $mode ) { self::manual( $id ); } else { Extensions::notify( 'accessible_forms_placement_tab', $mode, $id, $saved ); } echo '
'; } private static function manual( $id ) { $types = ContentTypes::types( true ); if ( ! $types ) { echo '

' . esc_html__( 'Ask a content editor to place this form', 'accessible-forms-by-accessible-org' ) . '

' . esc_html__( 'Your role can build forms but cannot edit public content. Share the form name or shortcode with someone who can edit the destination.', 'accessible-forms-by-accessible-org' ) . '

' . esc_html__( 'Get block and shortcode instructions', 'accessible-forms-by-accessible-org' ) . '
'; return; } // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only content search. Opening an editor does not change content. $type = sanitize_key( wp_unslash( $_GET['af_content_type'] ?? 'page' ) ); $search = sanitize_text_field( wp_unslash( $_GET['af_page_search'] ?? '' ) ); $page = max( 1, absint( $_GET['af_page'] ?? 1 ) ); $position = 'before' === sanitize_key( wp_unslash( $_GET['af_position'] ?? '' ) ) ? 'before' : 'after'; // phpcs:enable WordPress.Security.NonceVerification.Recommended if ( ! isset( $types[ $type ] ) ) { $type = array_key_first( $types ); } $args = array( 'post_type' => $type, 'post_status' => array( 'publish', 'draft', 'pending', 'private', 'future' ), 'posts_per_page' => 10, 'paged' => $page, 's' => $search, 'orderby' => array( 'modified' => 'DESC', 'ID' => 'DESC', ), ); if ( ! current_user_can( $types[ $type ]->cap->edit_others_posts ) ) { $args['author'] = get_current_user_id(); } $query = new \WP_Query( $args ); echo '

' . esc_html__( 'Choose an existing item', 'accessible-forms-by-accessible-org' ) . '

' . esc_html__( 'Open its editor, insert the form, then save the page or post. You can move the block to any position before saving.', 'accessible-forms-by-accessible-org' ) . '

'; if ( ! $shown ) { echo '

' . esc_html__( 'No editable items match. Try another title or content type, or create a draft below.', 'accessible-forms-by-accessible-org' ) . '

'; } if ( $query->max_num_pages > 1 ) { echo ''; } echo '
'; $creatable = array_filter( $types, static function ( $object ) { return current_user_can( $object->cap->create_posts ); } ); if ( $creatable ) { echo '
' . esc_html__( 'Create a new page or post instead', 'accessible-forms-by-accessible-org' ) . '

' . esc_html__( 'Starts a draft with the form already included. Review and publish it from the content editor.', 'accessible-forms-by-accessible-org' ) . '

'; wp_nonce_field( 'accessible_forms_create_page_' . $id ); self::type_select( 'content_type', __( 'New content type', 'accessible-forms-by-accessible-org' ), $creatable, isset( $creatable[ $type ] ) ? $type : array_key_first( $creatable ) ); echo '

'; } } private static function type_select( $name, $label, array $types, $selected ) { echo '
'; } private static function block( $id ) { echo '

' . esc_html__( 'Place an Accessible Form block', 'accessible-forms-by-accessible-org' ) . '

  1. ' . esc_html__( 'Open the page, post, custom content or template in the WordPress block editor.', 'accessible-forms-by-accessible-org' ) . '
  2. ' . esc_html__( 'Open the block inserter and search for “Accessible Form”.', 'accessible-forms-by-accessible-org' ) . '
  3. ' . esc_html__( 'Choose this published form:', 'accessible-forms-by-accessible-org' ) . ' ' . esc_html( get_the_title( $id ) ) . '
  4. ' . esc_html__( 'Move the block to the intended position. Use its alignment control if your theme supports wide or full width.', 'accessible-forms-by-accessible-org' ) . '
  5. ' . esc_html__( 'Save the content, then check the published form with a keyboard and on a small screen.', 'accessible-forms-by-accessible-org' ) . '

' . esc_html__( 'For every item of a post type, you can place the block in that type’s Single template. Avoid adding it to a Query Loop unless you intend a separate form on every listed item.', 'accessible-forms-by-accessible-org' ) . '

' . esc_html__( 'Classic Editor or page builder', 'accessible-forms-by-accessible-org' ) . '

' . esc_html__( 'Paste this shortcode in a Shortcode block or a shortcode-enabled content area.', 'accessible-forms-by-accessible-org' ) . '

' . esc_html__( 'All placements use this form’s published fields, recipients and accessible color theme. Change the form once to update every placement.', 'accessible-forms-by-accessible-org' ) . '

'; } }