self::SLUG ), $args ), admin_url( 'tools.php' ) ); } /** * Menu entry. * * @return void */ public static function menu() { add_management_page( __( 'Bakeout: move off WPBakery', 'bakeout' ), __( 'Bakeout', 'bakeout' ), self::CAP, self::SLUG, array( __CLASS__, 'render' ) ); } /** * Settings link on the plugins screen. * * @param string[] $links Links. * @return string[] */ public static function action_links( $links ) { array_unshift( $links, '' . esc_html__( 'Scan the site', 'bakeout' ) . '' ); return $links; } /** * Styles and scripts on our screen only. * * @param string $hook Hook suffix. * @return void */ public static function assets( $hook ) { if ( 'tools_page_' . self::SLUG !== $hook ) { return; } wp_enqueue_style( 'bakeout-admin', BAKEOUT_URL . 'assets/admin.css', array(), BAKEOUT_VERSION ); wp_enqueue_script( 'bakeout-admin', BAKEOUT_URL . 'assets/admin.js', array(), BAKEOUT_VERSION, true ); wp_localize_script( 'bakeout-admin', 'bakeoutAdmin', array( 'ajax' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'bakeout_scan' ), /* translators: 1: pages scanned, 2: pages to scan. */ 'scanning' => __( 'Scanning… %1$d of %2$d', 'bakeout' ), 'failed' => __( 'The scan stopped. Reload the page to continue.', 'bakeout' ), ) ); } /* ----- Actions ----- */ /** * Convert one post. * * @return void */ public static function handle_convert() { $id = isset( $_POST['post'] ) ? absint( $_POST['post'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Missing -- checked next. check_admin_referer( 'bakeout_convert_' . $id ); if ( ! current_user_can( self::CAP ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'bakeout' ) ); } $result = Store::convert( $id ); self::back( is_wp_error( $result ) ? $result->get_error_message() : 'converted', $id ); } /** * Undo one post. * * @return void */ public static function handle_undo() { $id = isset( $_POST['post'] ) ? absint( $_POST['post'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification.Missing -- checked next. check_admin_referer( 'bakeout_undo_' . $id ); if ( ! current_user_can( self::CAP ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'bakeout' ) ); } $result = Store::undo( $id ); self::back( is_wp_error( $result ) ? $result->get_error_message() : 'undone', $id ); } /** * Save settings. * * @return void */ public static function handle_settings() { check_admin_referer( 'bakeout_settings' ); if ( ! current_user_can( self::CAP ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'bakeout' ) ); } Settings::save( array( 'render' => ! empty( $_POST['render'] ) ) ); wp_safe_redirect( self::url( array( 'tab' => 'settings', 'bakeout_msg' => 'saved' ) ) ); exit; } /** * Start or continue a scan without JavaScript. * * @return void */ public static function handle_scan() { check_admin_referer( 'bakeout_scan' ); if ( ! current_user_can( self::CAP ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'bakeout' ) ); } if ( ! empty( $_POST['restart'] ) ) { Scanner::start(); } $state = Scanner::step(); wp_safe_redirect( self::url( $state['done'] ? array() : array( 'scanning' => 1 ) ) ); exit; } /** * One scan batch for the page's script. * * @return void */ public static function ajax_scan() { check_ajax_referer( 'bakeout_scan' ); if ( ! current_user_can( self::CAP ) ) { wp_send_json_error( null, 403 ); } if ( ! empty( $_POST['restart'] ) ) { Scanner::start(); } $state = Scanner::step(); wp_send_json_success( array( 'done' => (bool) $state['done'], 'total' => (int) $state['total'], 'left' => count( $state['queue'] ), ) ); } /** * Redirect back with a message. * * @param string $msg Message key or text. * @param int $id Post ID. * @return void */ private static function back( $msg, $id ) { $view = isset( $_POST['view'] ) ? sanitize_key( wp_unslash( $_POST['view'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing -- the caller checked the nonce. $args = array( 'bakeout_msg' => rawurlencode( $msg ) ); // add_query_arg() does not encode values. if ( 'preview' === $view ) { $args['view'] = 'preview'; $args['post'] = $id; } wp_safe_redirect( self::url( $args ) ); exit; } /* ----- Screens ----- */ /** * The screen. * * @return void */ public static function render() { if ( ! current_user_can( self::CAP ) ) { return; } // phpcs:disable WordPress.Security.NonceVerification.Recommended -- read-only view switches. $tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : 'scan'; $view = isset( $_GET['view'] ) ? sanitize_key( wp_unslash( $_GET['view'] ) ) : ''; $post = isset( $_GET['post'] ) ? absint( $_GET['post'] ) : 0; $msg = isset( $_GET['bakeout_msg'] ) ? sanitize_text_field( wp_unslash( $_GET['bakeout_msg'] ) ) : ''; // phpcs:enable $tabs = apply_filters( 'bakeout_admin_tabs', array( 'scan' => __( 'Scan and convert', 'bakeout' ), 'settings' => __( 'Settings', 'bakeout' ), ) ); echo '
%s
' . esc_html__( 'Bakeout reads your pages, turns every WPBakery element it knows into the matching block, and keeps anything else as a Shortcode block, so nothing on a page is lost. Each page keeps a backup: Undo puts it back exactly.', 'bakeout' ) . '
' . esc_html__( 'Bakeout moves the content of your pages, not your theme.', 'bakeout' ) . ' ' . esc_html__( 'Your header, footer, sidebar, fonts and colours come from the theme. If you also switch to a new theme, those will change, and elements that belong to the old theme stop working. The scan lists them as theme elements.', 'bakeout' ) . '
' . esc_html__( 'No WPBakery content was found.', 'bakeout' ) . '
'; return; } echo '| ' . esc_html__( 'Title', 'bakeout' ) . ' | ' . esc_html__( 'Type', 'bakeout' ) . ' | ' . esc_html__( 'Elements', 'bakeout' ) . ' | ' . esc_html__( 'Converts automatically', 'bakeout' ) . ' | ' . esc_html__( 'State', 'bakeout' ) . ' | ' . esc_html__( 'Actions', 'bakeout' ) . ' |
|---|---|---|---|---|---|
| ' . esc_html( $title ) . ''; if ( 'publish' !== $row['status'] ) { echo ' (' . esc_html( $row['status'] ) . ')'; } if ( $row['theme'] ) { echo ' ' . esc_html( implode( ', ', array_keys( $row['theme'] ) ) ) . ''; } echo ' | ' . esc_html( $row['type'] ) . ' | ' . (int) $row['builder'] . ' | ' . (int) $row['percent'] . '% | '; echo $row['converted'] ? '' . esc_html__( 'Converted', 'bakeout' ) . '' : esc_html__( 'Not converted', 'bakeout' ); echo ' | '; echo '' . esc_html__( 'Preview', 'bakeout' ) . ' '; self::action_button( $id, $row['converted'] ? 'undo' : 'convert', '' ); echo ' |
| ' . esc_html__( 'Shortcode', 'bakeout' ) . ' | ' . esc_html__( 'Times used', 'bakeout' ) . ' | ' . esc_html__( 'What happens', 'bakeout' ) . ' |
|---|---|---|
[' . esc_html( $tag ) . '] | ' . (int) $n . ' | ' . esc_html( $what ) . ' |
' . esc_html__( 'That post cannot be shown.', 'bakeout' ) . '
'; return; } $converted = (bool) Store::backup( $id ); $result = Store::preview( $id ); echo '← ' . esc_html__( 'Back to the scan', 'bakeout' ) . '
'; echo '' . esc_html( $result->get_error_message() ) . '
'; /* translators: %d: number of elements. */ echo esc_html( sprintf( _n( '%d element converted to blocks.', '%d elements converted to blocks.', $conv, 'bakeout' ), $conv ) ) . ' '; if ( $rend ) { /* translators: %d: number of elements. */ echo esc_html( sprintf( _n( '%d element kept as static HTML.', '%d elements kept as static HTML.', $rend, 'bakeout' ), $rend ) ) . ' '; } if ( $kept ) { /* translators: 1: number of elements, 2: list of shortcodes. */ echo esc_html( sprintf( _n( '%1$d element kept as a shortcode: %2$s.', '%1$d elements kept as shortcodes: %2$s.', $kept, 'bakeout' ), $kept, implode( ', ', array_keys( $report['kept'] ) ) ) ); } echo '
'; if ( $report['notes'] ) { echo '