register_hooks(); } }, 20 ); } /** * Adapters whose form plugin is active. * * @return AdapterInterface[] */ public static function available() { return array_values( array_filter( self::all(), static function ( $adapter ) { return $adapter->is_available(); } ) ); } /** * Every known adapter, including ones added by other code. * * @return AdapterInterface[] */ public static function all() { if ( null === self::$adapters ) { /** * Form adapters. Add an AdapterInterface instance to support another form plugin. * * @param AdapterInterface[] $adapters Adapters. */ $adapters = apply_filters( 'consiva_consent_form_adapters', array( new ContactForm7(), new WPForms() ) ); self::$adapters = array_values( array_filter( (array) $adapters, static function ( $adapter ) { return $adapter instanceof AdapterInterface; } ) ); } return self::$adapters; } /** * @param string $id Adapter ID. * @return AdapterInterface|null */ public static function get( $id ) { foreach ( self::all() as $adapter ) { if ( $adapter->id() === $id ) { return $adapter; } } return null; } /** * Published forms stored as a post type, by title. Loaded 100 at a time, up to MAX_FORMS: admin * screens only, never on a front-end page. * * @param string $post_type Post type. * @return array */ public static function published_forms( $post_type ) { $out = array(); $pages = (int) ( self::MAX_FORMS / 100 ); for ( $page = 1; $page <= $pages; $page++ ) { $posts = get_posts( array( 'post_type' => $post_type, 'post_status' => 'publish', 'posts_per_page' => 100, 'paged' => $page, 'orderby' => 'title', 'order' => 'ASC', 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, ) ); foreach ( $posts as $post ) { $out[] = array( 'id' => (int) $post->ID, 'title' => $post->post_title, ); } if ( count( $posts ) < 100 ) { break; } } return $out; } }