post_type, Options::enabled_post_types(), true ) ) { wp_die( esc_html__( 'Akram is not enabled for this post type. Enable it in Akram → Settings.', 'akram' ) ); } // Opening the editor can change the post (draft status, edit lock, page template), so the link must be nonced. if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ?? '' ) ), 'akram_edit' ) ) { wp_die( '

' . esc_html__( 'This editor link has expired.', 'akram' ) . '

' . esc_html__( 'Open in Akram', 'akram' ) . '

', esc_html__( 'Akram', 'akram' ), array( 'response' => 403 ) ); } if ( 'auto-draft' === $post->post_status ) { wp_update_post( array( 'ID' => $post_id, 'post_status' => 'draft', 'post_title' => $post->post_title ?: __( 'Untitled', 'akram' ), ) ); } // The full-screen editor prints styles itself; WordPress's legacy emoji printers aren't needed // (and would log a deprecation notice because the admin_enqueue_scripts unhooking never runs here). remove_action( 'admin_print_styles', 'print_emoji_styles' ); remove_action( 'wp_print_styles', 'print_emoji_styles' ); remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); require_once ABSPATH . 'wp-admin/includes/post.php'; $lock = wp_check_post_lock( $post_id ); if ( ! $lock ) { wp_set_post_lock( $post_id ); } // First visit: page template defaults to full width (theme header/footer, no title, no sidebar). if ( ! Document::is_built( $post_id ) && 'page' === $post->post_type && ! get_page_template_slug( $post_id ) ) { update_post_meta( $post_id, '_wp_page_template', Options::get( 'default_template', 'akram-full' ) ); } wp_enqueue_media(); $ver = self::asset_ver( Plugin::build_file( 'editor.js' ) ); wp_enqueue_style( 'akram-editor', Plugin::build_url( 'editor.css' ), array(), $ver ); wp_add_inline_style( 'akram-editor', Brand::font_css() ); wp_enqueue_script( 'akram-editor', Plugin::build_url( 'editor.js' ), array(), $ver, true ); wp_add_inline_script( 'akram-editor', 'window.AKRAM=' . wp_json_encode( self::config( $post_id, $lock ) ) . ';', 'before' ); do_action( 'akram_editor_enqueue', $post_id ); header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); $theme = Options::get( 'editor_theme', 'dark' ); ?> data-theme=""> <?php echo esc_html( sprintf( /* translators: %s: post title */ __( 'Akram · %s', 'akram' ), $post->post_title ?: __( 'Untitled', 'akram' ) ) ); ?>
post_type; $user = wp_get_current_user(); $menus = array(); foreach ( wp_get_nav_menus() as $m ) { $menus[] = array( 'id' => $m->term_id, 'name' => $m->name, ); } $pts = array(); foreach ( get_post_types( array( 'public' => true ), 'objects' ) as $pt ) { if ( 'attachment' === $pt->name || 'akram_template' === $pt->name ) { continue; } $pts[] = array( $pt->name, $pt->labels->name ); } $preview_ctx = 0; if ( $is_tpl ) { $preview_ctx = (int) get_post_meta( $post_id, '_akram_preview', true ); } $lock_user = $lock ? get_userdata( $lock ) : null; $draft = Document::get_draft( $post_id ); $s = Options::all(); return array( 'post' => array( 'id' => $post_id, 'title' => $post->post_title, 'type' => $post->post_type, 'typeLabel' => get_post_type_object( $post->post_type )->labels->singular_name, 'status' => $post->post_status, 'slug' => $post->post_name, 'link' => get_permalink( $post_id ), 'preview' => Rest::preview_link( $post_id ), 'template' => get_page_template_slug( $post_id ) ?: 'default', 'thumb' => (int) get_post_thumbnail_id( $post_id ), 'thumbUrl' => get_the_post_thumbnail_url( $post_id, 'medium' ) ?: '', 'tplType' => $is_tpl ? Post_Types::template_type( $post_id ) : '', 'conditions' => $is_tpl ? Theme_Builder::get_conditions( $post_id ) : null, 'settings' => $is_tpl ? Theme_Builder::get_settings( $post_id ) : null, 'previewCtx' => $preview_ctx, 'hasElementor' => (bool) get_post_meta( $post_id, '_elementor_data', true ), 'canPublish' => current_user_can( get_post_type_object( $post->post_type )->cap->publish_posts ), ), 'doc' => Document::get_doc( $post_id ), 'draft' => $draft ? array( 'doc' => $draft['doc'], 'time' => $draft['time'], ) : null, 'hash' => Document::hash( $post_id ), 'lock' => $lock_user ? array( 'user' => $lock_user->display_name, 'avatar' => get_avatar_url( $lock_user->ID ), ) : null, 'canvas' => self::canvas_url( $post_id ), 'rest' => esc_url_raw( rest_url( Rest::NS . '/' ) ), 'wpRest' => esc_url_raw( rest_url() ), 'nonce' => wp_create_nonce( 'wp_rest' ), 'admin' => admin_url(), 'editNonce' => wp_create_nonce( 'akram_edit' ), 'exit' => $is_tpl ? admin_url( 'admin.php?page=akram#/templates' ) : get_edit_post_link( $post_id, 'raw' ), 'dashboard' => admin_url( 'admin.php?page=akram' ), 'assets' => AKRAM_URL . 'assets/', 'min' => Plugin::min_suffix(), 'tz' => (float) get_option( 'gmt_offset' ), 'version' => AKRAM_VERSION, 'bps' => Options::breakpoints(), 'globals' => Options::globals(), 'menus' => $menus, 'postTypes' => $pts, 'woo' => Options::has_woo(), 'user' => array( 'name' => $user->display_name, 'avatar' => get_avatar_url( $user->ID, array( 'size' => 64 ) ), 'unfiltered' => current_user_can( 'unfiltered_html' ), 'design' => current_user_can( 'edit_theme_options' ), 'manage' => Plugin::can_manage(), 'contentOnly' => Plugin::content_only(), ), 'disabled' => array_values( (array) $s['disabled_widgets'] ), 'i18n' => I18n::js_map(), 'rtl' => I18n::is_rtl(), 'brand' => I18n::brand(), 'brandLogo' => I18n::brand_logo(), 'customFonts' => array_column( (array) $s['custom_fonts'], 'family' ), 'ai' => Ai::available(), 'site' => array( 'name' => get_bloginfo( 'name' ), 'url' => home_url( '/' ), 'logo' => (int) get_theme_mod( 'custom_logo' ), ), 'theme' => $s['editor_theme'], 'tplTypes' => Post_Types::type_labels(), 'locale' => get_user_locale(), ); } public static function canvas_url( $post_id ) { $post = get_post( $post_id ); $base = 'akram_template' === $post->post_type ? add_query_arg( array( 'post_type' => 'akram_template', 'p' => $post_id, ), home_url( '/' ) ) : get_permalink( $post_id ); if ( 'akram_template' !== $post->post_type && in_array( $post->post_status, array( 'draft', 'auto-draft', 'pending', 'future', 'private' ), true ) ) { $base = add_query_arg( array( 'p' => $post_id, 'post_type' => $post->post_type, 'preview' => 'true', ), home_url( '/' ) ); if ( 'page' === $post->post_type ) { $base = add_query_arg( array( 'page_id' => $post_id, 'preview' => 'true', ), home_url( '/' ) ); } } return add_query_arg( array( 'akram-canvas' => $post_id, '_nxc' => wp_create_nonce( 'akram_canvas_' . $post_id ), ), $base ); } /** * Inside the editor iframe the real theme renders around an empty mount point that the * editor fills. Template documents render on a blank canvas. */ public static function canvas_mode() { if ( ! self::is_canvas() ) { return; } $id = isset( $_GET['akram-canvas'] ) ? absint( $_GET['akram-canvas'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification -- verified just below. if ( ! $id || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_nxc'] ?? '' ) ), 'akram_canvas_' . $id ) || ! Plugin::can_build( $id ) ) { return; } $GLOBALS['akram_canvas_id'] = $id; show_admin_bar( false ); add_filter( 'show_admin_bar', '__return_false', 99 ); nocache_headers(); remove_action( 'wp_head', '_admin_bar_bump_cb' ); add_action( 'wp_enqueue_scripts', static function () { wp_register_style( 'akram-canvas-base', false, array(), AKRAM_VERSION ); wp_enqueue_style( 'akram-canvas-base' ); wp_add_inline_style( 'akram-canvas-base', 'html{margin-top:0!important}#nx-canvas-root{min-height:60vh}' ); }, 1 ); if ( 'akram_template' === get_post_type( $id ) ) { $type = Post_Types::template_type( $id ); // Header/footer/popup/section templates edit on a blank page; single/archive keep the site's header & footer. add_filter( 'template_include', static function () use ( $type ) { return AKRAM_DIR . 'templates/' . ( in_array( $type, array( 'single', 'archive', 'search', '404' ), true ) ? 'canvas-template.php' : 'canvas-blank.php' ); }, 9999 ); } } public static function canvas_id() { return isset( $GLOBALS['akram_canvas_id'] ) ? (int) $GLOBALS['akram_canvas_id'] : 0; } }