'local', // google | local | off 'default_preset' => 'clean', 'breakpoint' => 640, 'breakpoint_t' => 1024, 'share_stats' => 0, // anonymous stats, off until the owner says yes (Tablewright_Stats) ); } public static function get_settings() { $s = get_option( 'tablewright_settings', array() ); return array_merge( self::default_global_settings(), is_array( $s ) ? $s : array() ); } public function register() { register_post_type( self::CPT, array( 'labels' => array( 'name' => __( 'Tables', 'tablewright' ), 'singular_name' => __( 'Table', 'tablewright' ), 'add_new_item' => __( 'Add new table', 'tablewright' ), 'edit_item' => __( 'Edit table', 'tablewright' ), 'search_items' => __( 'Search tables', 'tablewright' ), 'not_found' => __( 'No tables yet. Create your first one.', 'tablewright' ), 'all_items' => __( 'All tables', 'tablewright' ), ), 'public' => false, 'show_ui' => true, 'show_in_menu' => false, 'show_in_rest' => true, 'rest_base' => 'tablewright-tables', 'supports' => array( 'title' ), 'capability_type' => 'post', 'map_meta_cap' => true, ) ); add_shortcode( 'tablewright', array( 'Tablewright_Render', 'shortcode' ) ); wp_register_style( 'tablewright-frontend', TABLEWRIGHT_URL . 'assets/frontend/tablewright.css', array(), TABLEWRIGHT_VERSION ); wp_register_script( 'tablewright-frontend', TABLEWRIGHT_URL . 'assets/frontend/tablewright.js', array(), TABLEWRIGHT_VERSION, true ); wp_register_script( 'tablewright-block', TABLEWRIGHT_URL . 'assets/admin/block.js', array( 'wp-blocks', 'wp-element', 'wp-components', 'wp-block-editor', 'wp-server-side-render', 'wp-api-fetch' ), TABLEWRIGHT_VERSION, true ); register_block_type( 'tablewright/table', array( 'api_version' => 2, 'editor_script' => 'tablewright-block', 'editor_style' => 'tablewright-frontend', 'attributes' => array( 'id' => array( 'type' => 'number', 'default' => 0 ), ), 'render_callback' => function ( $atts ) { return empty( $atts['id'] ) ? '' : Tablewright_Render::render( (int) $atts['id'] ); }, ) ); } /** * If the current singular post contains tables, load CSS and fonts in
* so text doesn't flash in a fallback font. (Page builders that render * shortcodes from their own storage still work — assets then load in the footer.) */ public function preload_for_current_post() { if ( ! is_singular() ) { return; } $post = get_post(); if ( ! $post || ( false === strpos( $post->post_content, '[tablewright' ) && false === strpos( $post->post_content, 'wp:tablewright/table' ) ) ) { return; } $ids = array(); if ( preg_match_all( '/\[tablewright[^\]]*\bid=["\']?(\d+)/', $post->post_content, $m ) ) { $ids = array_merge( $ids, $m[1] ); } if ( preg_match_all( '/wp:tablewright\/table\s+\{"id":(\d+)/', $post->post_content, $m ) ) { $ids = array_merge( $ids, $m[1] ); } wp_enqueue_style( 'tablewright-frontend' ); foreach ( array_unique( array_map( 'intval', $ids ) ) as $id ) { if ( self::CPT !== get_post_type( $id ) ) { continue; } $data = Tablewright_Data::get( $id ); if ( $data ) { Tablewright_Fonts::enqueue_for( $data ); // The table's own CSS goes into the head too; the first render of this id (twr-