store = new Akintu_Connection_Store(); } /** * Register WordPress hooks. * * @return void */ public function register() { $api = new Akintu_Api_Client(); $admin = new Akintu_Admin( $this->store, $api ); $admin->register(); $admin_api = new Akintu_Admin_Api( $this->store, $api ); $admin_api->register(); add_action( 'init', array( $this, 'register_content_integrations' ) ); add_action( 'wp_head', array( $this, 'render_verification_marker' ), 1 ); add_action( 'wp_footer', array( $this, 'enqueue_runtime' ), 1 ); add_filter( 'wp_script_attributes', array( $this, 'add_runtime_credentials' ) ); add_action( 'plugins_loaded', array( $this, 'register_elementor' ), 20 ); } /** * Register Elementor whether it loaded before or after Akintu. * * @return void */ public function register_elementor() { if ( did_action( 'elementor/loaded' ) ) { Akintu_Elementor::register(); return; } add_action( 'elementor/loaded', array( 'Akintu_Elementor', 'register' ) ); } /** * Set the activation redirect only for interactive single-site activation. * * @return void */ public static function activate() { add_option( 'akintu_activation_redirect', '1', '', false ); } /** * Register the shortcode and dynamic block. * * @return void */ public function register_content_integrations() { add_shortcode( 'akintu_embed', array( $this, 'render_embed_shortcode' ) ); register_block_type( AKINTU_PLUGIN_DIR . 'blocks/embed', array( 'render_callback' => array( $this, 'render_embed_block' ) ) ); } /** * Render Embed from a shortcode. * * @return string */ public function render_embed_shortcode() { return $this->get_embed_markup(); } /** * Render the dynamic Embed block. * * @return string */ public function render_embed_block() { return $this->get_embed_markup(); } /** * Return canonical Embed markup and request its runtime. * * @return string */ public function get_embed_markup() { $this->should_enqueue = true; if ( ! $this->store->is_connected() ) { return current_user_can( 'edit_posts' ) ? '

' . esc_html__( 'Collega Akintu dalla dashboard WordPress per mostrare Embed.', 'akintu' ) . '

' : ''; } return ''; } /** * Emit the one-time site verification marker while setup is active. * * @return void */ public function render_verification_marker() { $connection = $this->store->get(); if ( empty( $connection['verification_token'] ) || ! is_string( $connection['verification_token'] ) ) { return; } printf( '' . "\n", esc_attr( $connection['verification_token'] ) ); } /** * Enqueue the local runtime only on pages that rendered an Embed surface. * * @return void */ public function enqueue_runtime() { if ( ! $this->should_enqueue || ! $this->store->is_connected() ) { return; } wp_enqueue_script( 'akintu-widget-runtime', AKINTU_PLUGIN_URL . 'assets/widget/loader.js', array(), AKINTU_VERSION, array( 'in_footer' => true, 'strategy' => 'defer', ) ); } /** * Add the browser client key only to Akintu's local loader script. * * @param array $attributes Script attributes. * @return array */ public function add_runtime_credentials( $attributes ) { if ( empty( $attributes['id'] ) || 'akintu-widget-runtime-js' !== $attributes['id'] ) { return $attributes; } $connection = $this->store->get(); if ( empty( $connection['client_key'] ) || ! is_string( $connection['client_key'] ) ) { return $attributes; } $attributes['data-api-key'] = $connection['client_key']; return $attributes; } }