, each field's wrapper and control, the groups and the response box * * These carry what the script and the submission need, so no template can lose them; templates are what goes * around each control (fields/) and inside the response box (form/{style}/response.php). */ class Renderer { // Where alert_templates() leave the message, for the script to fill in const MESSAGE = '%%remaily-message%%'; /** * Forms rendered on this page * * @var int */ private static $count = 0; /** * Forms rendered on this page, for the admin bar * * @var int[] */ private static $rendered = []; /** * Init */ public static function init() { add_action( 'wp_enqueue_scripts', [ __CLASS__, 'detect' ], 20 ); // Before the footer scripts print add_action( 'wp_footer', [ __CLASS__, 'admin_bar' ], 5 ); } /** * Admin bar menu of the forms this page shows, linked to their editor */ public static function admin_bar() { if ( !self::$rendered || !is_admin_bar_showing() ) { return; } $items = []; foreach ( array_unique( self::$rendered ) as $id ) { // No link when the user can't edit the form $link = get_edit_post_link( $id, 'raw' ); if ( $link ) { $items[] = [ 'title' => get_the_title( $id ) ?: sprintf( '#%d', $id ), 'url' => $link, ]; } } if ( !$items ) { return; } Assets::enqueue( 'remaily-admin-bar' ); Assets::data( 'remaily-admin-bar', 'remailyAdminBar', [ 'label' => __( 'Contact Form', 'remaily' ), 'items' => $items, ] ); } /** * The page's forms, found in its content, get their assets in ; any other loads them when rendered */ public static function detect() { if ( !is_singular() ) { return; } $content = (string) get_post_field( 'post_content', get_queried_object_id() ); if ( false === strpos( $content, '[remaily' ) && false === strpos( $content, '