markers): * - Elementor support is part of the linking engine, which ships in both * Free and Paid. This UI must be available wherever that engine runs. * * Design choices: * - The box only appears when the current post is actually built with * Elementor (post_uses_elementor). Classic posts already link on save * and don't need a manual trigger here. * - It calls the existing AJAX handler `flink_elementor_preview` * (FLINK_Ajax::elementor_preview), which does the dry-run by default * and only writes when explicitly told to apply. No new server logic. * - Dry-run IGNORES the origen filter on purpose (so the user can always * preview), but APPLY respects it — exactly mirroring the handler. We * surface that distinction in the UI copy so the result isn't confusing * when a page can't actually be linked from under current settings. * - Pure DOM JS, no jQuery. CSS + JS inlined: the box is tiny and keeping * it self-contained avoids adding stray asset files to the build. * - Namespaced `flink-elem-*` to avoid collisions. * * @since v4.6.65 */ class FLINK_Elementor_Meta_Box { /** * Boot: register the meta box. Idempotent. */ public function init() { add_action( 'add_meta_boxes', array( $this, 'register' ), 10, 2 ); } /** * Register the box for post/page types — only when the post is built * with Elementor. Other post types and classic posts are skipped. * * @param string $post_type Current post type. * @param WP_Post|null $post Current post object (passed by the action). */ public function register( $post_type, $post = null ) { $supported = (array) apply_filters( 'flink_elementor_box_post_types', array( 'post', 'page' ) ); if ( ! in_array( $post_type, $supported, true ) ) { return; } if ( ! $post ) { global $post; } if ( ! $post || empty( $post->ID ) ) { return; } // Only Elementor-built posts. We check the same flag the engine // uses (_elementor_edit_mode === 'builder') via the linker helper // when available, with a direct meta fallback. $is_elementor = ( get_post_meta( $post->ID, '_elementor_edit_mode', true ) === 'builder' ); if ( ! $is_elementor ) { return; } add_meta_box( 'flink_elementor_panel', __( 'Internal linking (Elementor)', '4linking-free' ), array( $this, 'render' ), $post_type, 'side', 'default', array( '__back_compat_meta_box' => false, '__block_editor_compatible_meta_box' => true, ) ); } /** * Render the box: an intro line, two buttons (preview / apply), and an * empty results area the JS fills in. The nonce is embedded for the * AJAX call (same nonce action the rest of the admin uses). * * @param WP_Post $post The current post. */ public function render( $post ) { $post_id = (int) $post->ID; $nonce = wp_create_nonce( 'flink_nonce' ); $ajax_url = admin_url( 'admin-ajax.php' ); // Inform the user whether APPLY will actually link from this page // under current settings. Dry-run always previews, but apply obeys // the origen-type filter. This avoids the "preview shows links but // apply does nothing" confusion documented in the Elementor brief. $origen_tipo = get_option( 'flink_origen_tipo', 'post' ); $can_apply = ( $origen_tipo === 'any' ); if ( ! $can_apply ) { $tipos = array_map( 'trim', explode( ',', (string) $origen_tipo ) ); $can_apply = in_array( get_post_type( $post_id ), $tipos, true ); } ?>