' . esc_html__( 'Upgrade to Pro', 'tablewright' ) . '', 'edit_posts', 'tablewright-pro', array( $this, 'page_pro' ) ); } add_submenu_page( $parent, __( 'More from us', 'tablewright' ), __( 'More tools', 'tablewright' ), 'manage_options', 'tablewright-more', array( $this, 'page_more' ) ); } /** Where "Get Pro" buttons point (TABLEWRIGHT_PRO_URL, a Studio redirect; filter tablewright_pro_url to change it). */ public static function pro_url() { $url = defined( 'TABLEWRIGHT_PRO_URL' ) ? TABLEWRIGHT_PRO_URL : ''; return (string) apply_filters( 'tablewright_pro_url', $url ); } public static function pro_features() { return array( __( 'Accordion, compare-columns, hide-columns and pinned-column layouts for phones', 'tablewright' ), __( 'Separate layouts for tablets and phones', 'tablewright' ), __( 'Button and image cells', 'tablewright' ), __( '2,800+ Font Awesome icons, including brand logos', 'tablewright' ), __( 'Pagination and a header that stays visible while scrolling', 'tablewright' ), __( 'Save your own styles and templates, plus 4 extra styles and 2 extra templates', 'tablewright' ), ); } /** Our other products, services and newsletter (links only; see Tablewright_More_Tools). */ public function page_more() { ?>
[tablewright id="' . (int) $post_id . '"]';
} elseif ( 'tablewright_size' === $col ) {
$d = Tablewright_Data::get( $post_id );
if ( $d ) {
/* translators: 1: rows, 2: columns */
printf( esc_html__( '%1$d rows × %2$d columns', 'tablewright' ), count( $d['cells'] ), count( $d['cells'][0] ) );
}
}
}
public function row_actions( $actions, $post ) {
if ( Tablewright_Plugin::CPT !== $post->post_type ) {
return $actions;
}
unset( $actions['inline hide-if-no-js'] );
$url = wp_nonce_url( admin_url( 'admin.php?action=tablewright_duplicate&post=' . $post->ID ), 'tablewright_dup_' . $post->ID );
$actions['tablewright_dup'] = '' . esc_html__( 'Duplicate', 'tablewright' ) . '';
return $actions;
}
public function duplicate() {
$id = isset( $_GET['post'] ) ? absint( wp_unslash( $_GET['post'] ) ) : 0;
check_admin_referer( 'tablewright_dup_' . $id );
if ( ! $id || Tablewright_Plugin::CPT !== get_post_type( $id ) || ! current_user_can( 'edit_post', $id ) || ! current_user_can( 'edit_posts' ) ) {
wp_die( esc_html__( 'You are not allowed to duplicate this table.', 'tablewright' ) );
}
$src = get_post( $id );
$new = wp_insert_post(
array(
'post_type' => Tablewright_Plugin::CPT,
'post_status' => 'publish',
/* translators: %s: table title */
'post_title' => sprintf( __( '%s (copy)', 'tablewright' ), $src->post_title ),
)
);
if ( $new && ! is_wp_error( $new ) ) {
Tablewright_Data::save( $new, Tablewright_Data::get( $id ) );
}
wp_safe_redirect( admin_url( 'edit.php?post_type=' . Tablewright_Plugin::CPT ) );
exit;
}
/* ------------------------------------------------------------------ */
/* Assets */
/* ------------------------------------------------------------------ */
public function assets() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Only picks which admin page's scripts to load; nothing is changed.
$page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';
if ( 'tablewright-more' === $page ) {
Tablewright_More_Tools::enqueue();
return;
}
if ( ! in_array( $page, array( 'tablewright-editor', 'tablewright-new', 'tablewright-pro' ), true ) ) {
return;
}
wp_enqueue_style( 'tablewright-admin', TABLEWRIGHT_URL . 'assets/admin/editor.css', array(), TABLEWRIGHT_VERSION );
wp_enqueue_style( 'tablewright-frontend' );
if ( 'tablewright-new' === $page ) {
// Template previews: their CSS goes with the admin stylesheet (the cards are printed by page_new()).
foreach ( Tablewright_Data::builtin_templates() as $tpl ) {
$tuid = 'twr-tpl-' . sanitize_html_class( $tpl['id'] );
wp_add_inline_style( 'tablewright-admin', Tablewright_Render::esc_css( Tablewright_Render::table_css( $tuid, Tablewright_Data::sanitize_table( $tpl['data'] ) ) ) );
}
wp_enqueue_script( 'tablewright-new', TABLEWRIGHT_URL . 'assets/admin/new-table.js', array(), TABLEWRIGHT_VERSION, true );
wp_localize_script(
'tablewright-new',
'TABLEWRIGHT_NEW',
array(
'ajax' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'tablewright_editor' ),
)
);
}
if ( 'tablewright-editor' !== $page ) {
return;
}
wp_enqueue_media();
wp_enqueue_style( 'tablewright-pickr', TABLEWRIGHT_URL . 'assets/vendor/pickr/nano.min.css', array(), '1.10.2' );
wp_enqueue_script( 'tablewright-pickr', TABLEWRIGHT_URL . 'assets/vendor/pickr/pickr.min.js', array(), '1.10.2', true );
wp_enqueue_script( 'tablewright-editor', TABLEWRIGHT_URL . 'assets/admin/editor.js', array( 'tablewright-pickr' ), TABLEWRIGHT_VERSION, true );
$id = self::requested_table();
$data = $id ? Tablewright_Data::get( $id ) : null;
$post = $data ? get_post( $id ) : null;
if ( ! $data ) {
$id = 0;
}
wp_localize_script(
'tablewright-editor',
'TABLEWRIGHT_EDITOR',
array(
'ajax' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'tablewright_editor' ),
'id' => $id,
'title' => $post ? $post->post_title : '',
'data' => $data,
'defaults' => Tablewright_Data::default_settings(),
'presets' => Tablewright_Data::builtin_presets(),
'fontsUrl' => TABLEWRIGHT_URL . 'assets/data/google-fonts.json?v=' . TABLEWRIGHT_VERSION,
'iconsUrl' => TABLEWRIGHT_URL . 'assets/data/icons-lucide.json?v=' . TABLEWRIGHT_VERSION,
'pro' => Tablewright_Data::is_pro(),
'proUrl' => self::pro_url() ? self::pro_url() : admin_url( 'admin.php?page=tablewright-pro' ),
'layouts' => Tablewright_Data::layouts(),
'systemFonts' => Tablewright_Fonts::system_fonts(),
'listUrl' => admin_url( 'edit.php?post_type=' . Tablewright_Plugin::CPT ),
'breakpoint' => (int) Tablewright_Plugin::get_settings()['breakpoint'],
'breakpointT' => (int) Tablewright_Plugin::get_settings()['breakpoint_t'],
'fontMode' => Tablewright_Plugin::get_settings()['font_mode'],
)
);
}
/* ------------------------------------------------------------------ */
/* Pages */
/* ------------------------------------------------------------------ */
public function page_new() {
$templates = Tablewright_Data::builtin_templates();
?>
' . esc_html__( 'Create a new table', 'tablewright' ) . '
'; return; } echo '' . esc_html__( 'Loading editor…', 'tablewright' ) . '