get_index_option_name(), false ); } die; } /** * Change option to false. */ public function upgrader_page_close() { if ( isset( $_POST['nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), '{{slug}}_upgrade_notice' ) ) { update_option( $this->get_page_option_name(), false ); } die; } /** * Change option to false. */ public function upgrader_page_content_close() { if ( isset( $_POST['nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), '{{slug}}_content_upgrade_notice' ) ) { update_option( $this->get_page_content_option_name(), false ); } die; } /** * Change option to false. */ public function upgrade_index_process() { if ( ! current_user_can( 'manage_options' ) ) { exit; } /** * Insert front page */ $index = get_block_template( wp_get_theme()->template . '//index' ); $front = get_block_template( wp_get_theme()->template . '//front-page' ); if ( 'custom' === $front->source ) { wp_send_json( array( 'flag' => false, 'message' => esc_html__( 'Front Page exist. If you want migrate index, please clear Front Page customization.', '{{slug}}' ), ) ); exit; } wp_insert_post( array( 'post_name' => 'front-page', 'post_title' => esc_html__( 'Front Page', '{{slug}}' ), 'post_type' => 'wp_template', 'post_status' => 'publish', 'post_content' => $index->content, 'tax_input' => array( 'wp_theme' => array( wp_get_theme()->template ), ), ) ); $this->upgrader_index_close(); wp_send_json( array( 'flag' => true, ) ); exit; } /** * Get Option Name. * * @return string. */ public function get_index_option_name() { return wp_get_theme()->template . '_upgrader_index'; } /** * Get Option Name. * * @return string. */ public function get_page_option_name() { return wp_get_theme()->template . '_upgrader_page'; } /** * Get Option Name. * * @return string. */ public function get_page_content_option_name() { return wp_get_theme()->template . '_upgrader_page_content'; } /** * Check if user using old template. if yes, then insert the flag. */ public function determine_old_template() { if ( $this->assume_old_template() ) { $flag = get_option( $this->get_index_option_name() ); if ( ! $flag ) { add_option( $this->get_index_option_name(), true ); } } } /** * Set content width upgrader option meta */ public function set_upgrader_page() { $flag = get_option( $this->get_page_option_name() ); if ( ! $flag ) { add_option( $this->get_page_option_name(), true ); } } /** * Set content width upgrader option meta */ public function set_upgrader_page_content() { $flag = get_option( $this->get_page_content_option_name() ); if ( ! $flag ) { add_option( $this->get_page_content_option_name(), true ); } } /** * Check if we can render the notice. */ public function assume_old_template() { $index = get_block_template( wp_get_theme()->template . '//index' ); $front = get_block_template( wp_get_theme()->template . '//front-page' ); return 'custom' === $index->source && 'theme' === $front->source; } /** * Admin Notice. */ public function index_notice() { if ( ! current_user_can( 'manage_options' ) ) { return; } $flag = get_option( $this->get_index_option_name() ); $front = get_block_template( wp_get_theme()->template . '//front-page' ); if ( $flag ) { ?>
get_page_content_option_name() ) ) { $this->enqueue_script(); ?> set_upgrader_page(); if ( get_option( $this->get_page_option_name() ) && ! ( 'admin.php' === $pagenow && isset( $_GET['page'] ) && 'gutenverse-upgrade-notice' === $_GET['page'] ) ) { $this->enqueue_script(); ?> set_upgrader_page(); if ( get_option( $this->get_page_option_name() ) && ! ( 'admin.php' === $pagenow && isset( $_GET['page'] ) && 'gutenverse-upgrade-notice' === $_GET['page'] ) ) { $this->enqueue_script(); ?>