Post_Type::POST_TYPE, 'post_status' => 'draft', 'post_title' => __( 'New quickscan', 'funnelfork' ), ), true ); if ( is_wp_error( $id ) ) { wp_die( esc_html( $id->get_error_message() ) ); } funnelfork_save_graph( $id, Graph::default_graph() ); wp_safe_redirect( funnelfork_editor_url( $id ) ); exit; } /** * Sends post.php?action=edit for scans to the visual editor. */ public static function redirect_classic_edit(): void { // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only redirect. $action = isset( $_GET['action'] ) ? sanitize_key( wp_unslash( $_GET['action'] ) ) : ''; $id = isset( $_GET['post'] ) ? absint( $_GET['post'] ) : 0; // phpcs:enable if ( 'edit' === $action && $id && Post_Type::POST_TYPE === get_post_type( $id ) ) { wp_safe_redirect( funnelfork_editor_url( $id ) ); exit; } } /** * Edit links of scans point to the visual editor. * * @param string $link Edit link. * @param int $post_id Post ID. */ public static function edit_link( $link, $post_id ) { if ( Post_Type::POST_TYPE === get_post_type( $post_id ) ) { return funnelfork_editor_url( (int) $post_id ); } return $link; } /** * Whether the current screen is the visual editor. */ public static function is_editor_screen(): bool { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; return $screen && self::$hook && $screen->id === self::$hook; } /** * Body class used to give the editor the full screen height. * * @param string $classes Body classes. */ public static function body_class( $classes ) { if ( self::is_editor_screen() ) { $classes .= ' funnelfork-editor-screen'; } return $classes; } /** * Renders the editor page; the React app mounts on the root element. */ public static function render_editor_page(): void { $id = self::current_scan_id(); $post = $id ? get_post( $id ) : null; if ( ! $post instanceof WP_Post || Post_Type::POST_TYPE !== $post->post_type ) { echo '
' . esc_html__( 'Loading editor…', 'funnelfork' ) . '
[funnelfork id="%d"]', (int) $post_id );
break;
case 'funnelfork_questions':
case 'funnelfork_endpoints':
$counts = Graph::count_nodes( funnelfork_get_graph( (int) $post_id ) );
echo (int) ( 'funnelfork_questions' === $column ? $counts['question'] : $counts['end'] );
break;
}
}
/**
* Row actions: drop "Quick edit", add "Preview".
*
* @param array $actions Actions.
* @param WP_Post $post Post.
*/
public static function row_actions( $actions, $post ) {
if ( Post_Type::POST_TYPE !== $post->post_type ) {
return $actions;
}
unset( $actions['inline hide-if-no-js'] );
$actions['funnelfork_preview'] = sprintf(
'%s',
esc_url( Frontend::preview_url( $post->ID ) ),
esc_html__( 'Preview', 'funnelfork' )
);
return $actions;
}
/**
* Link to the overview on the Plugins screen.
*
* @param array $links Links.
*/
public static function plugin_links( $links ) {
array_unshift(
$links,
sprintf(
'%s',
esc_url( admin_url( 'edit.php?post_type=' . Post_Type::POST_TYPE ) ),
esc_html__( 'Quickscans', 'funnelfork' )
)
);
return $links;
}
}