editor ) && method_exists( $plugin->editor, 'is_edit_mode' ) && $plugin->editor->is_edit_mode() ) { if ( method_exists( $plugin->editor, 'get_post_id' ) ) { $pid = (int) $plugin->editor->get_post_id(); if ( $pid ) { return $pid; } } } } catch ( \Throwable $e ) {} } // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( isset( $_GET['post'] ) ) { return (int) $_GET['post']; } // phpcs:ignore WordPress.Security.NonceVerification.Missing if ( isset( $_REQUEST['editor_post_id'] ) ) { return (int) $_REQUEST['editor_post_id']; } } // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( isset( $_GET['elementor-preview'] ) ) { return (int) $_GET['elementor-preview']; } return 0; } /** * Get kit id for a post. */ function abdielmskef_get_kit_id_for_post( int $post_id ): int { $kit_id = 0; if ( is_admin() && class_exists( 'Elementor\\Plugin' ) ) { try { $plugin = \Elementor\Plugin::instance(); if ( isset( $plugin->editor ) && method_exists( $plugin->editor, 'is_edit_mode' ) && $plugin->editor->is_edit_mode() ) { $doc = $plugin->documents->get( $post_id ); if ( $doc && method_exists( $doc, 'get_settings' ) ) { $kit_id = (int) $doc->get_settings( ABDIELMSKEF_META_LOCAL_KIT_ID ); } } } catch ( \Throwable $e ) {} } // Editor live preview override // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( isset( $_GET['abdielmskef_preview_kit'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $preview_id = (int) $_GET['abdielmskef_preview_kit']; if ( $preview_id && function_exists( 'abdielmskef_is_kit' ) && abdielmskef_is_kit( $preview_id ) && current_user_can( 'edit_post', $post_id ) ) { return $preview_id; } } if ( ! $kit_id && class_exists( 'Elementor\\Plugin' ) ) { try { $doc = \Elementor\Plugin::instance()->documents->get_doc_for_frontend( $post_id ); if ( $doc && method_exists( $doc, 'get_settings' ) ) { $kit_id = (int) $doc->get_settings( ABDIELMSKEF_META_LOCAL_KIT_ID ); } elseif ( $doc && method_exists( $doc, 'get_settings_for_display' ) ) { $kit_id = (int) $doc->get_settings_for_display( ABDIELMSKEF_META_LOCAL_KIT_ID ); } } catch ( \Throwable $e ) {} } if ( ! $kit_id ) { $page_settings = get_post_meta( $post_id, '_elementor_page_settings', true ); if ( is_array( $page_settings ) && isset( $page_settings[ ABDIELMSKEF_META_LOCAL_KIT_ID ] ) ) { $kit_id = (int) $page_settings[ ABDIELMSKEF_META_LOCAL_KIT_ID ]; } } if ( ! $kit_id ) { $kit_id = (int) get_post_meta( (int) $post_id, ABDIELMSKEF_META_LOCAL_KIT_ID, true ); } if ( ! $kit_id ) { $settings = function_exists( 'abdielmskef_get_settings' ) ? abdielmskef_get_settings() : []; $kit_id = (int) ( $settings['default_new_pages_kit'] ?? 0 ); } return $kit_id; }