sitepress = $sitepress; $this->wpml_post_translations = $wpml_post_translations; } /** * Adds the actions and filters. */ public function add_hooks() { add_action( 'admin_init', [ $this, 'maybe_setup_post_edit' ] ); add_action( 'wpcf7_admin_misc_pub_section', [ $this, 'add_language_meta_box' ] ); add_filter( 'wpml_link_to_translation', [ $this, 'link_to_translation' ], 10, 4 ); add_filter( 'wpml_admin_language_switcher_items', [ $this, 'admin_language_switcher_items' ] ); } /** * Call the required code for the language meta box functionality. * * @TODO Remove duplicated code */ public function maybe_setup_post_edit() { global $post_edit_screen; $is_wpcf7_page = $this->is_wpcf7_page(); $post = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT ); if ( $is_wpcf7_page && $post ) { // Duplicated code from wpml_maybe_setup_post_edit(). $post_edit_screen = new \WPML_Post_Edit_Screen( $this->sitepress ); add_action( 'admin_head', array( $this->sitepress, 'post_edit_language_options' ) ); // Duplicated code from SitePress::js_load(). wp_register_script( 'sitepress-post-edit-tags', ICL_PLUGIN_URL . '/res/js/post-edit-terms.js', array( 'jquery' ) ); $post_edit_messages = array( 'switch_language_title' => __( 'You are about to change the language of {post_name}.', 'sitepress' ), 'switch_language_alert' => __( 'All categories and tags will be translated if possible.', 'sitepress' ), 'connection_loss_alert' => __( 'The following terms do not have a translation in the chosen language and will be disconnected from this post:', 'sitepress' ), 'loading' => __( 'Loading Language Data for {post_name}', 'sitepress' ), 'switch_language_message' => __( 'Please make sure that you\'ve saved all the changes. We will have to reload the page.', 'sitepress' ), 'switch_language_confirm' => __( 'Do you want to continue?', 'sitepress' ), '_nonce' => wp_create_nonce( 'wpml_switch_post_lang_nonce' ), 'empty_post_title' => __( '(No title for this post yet)', 'sitepress' ), 'ok_button_label' => __( 'OK', 'sitepress' ), 'cancel_button_label' => __( 'Cancel', 'sitepress' ), ); wp_localize_script( 'sitepress-post-edit-tags', 'icl_post_edit_messages', $post_edit_messages ); wp_enqueue_script( 'sitepress-post-edit-tags' ); // Duplicated code from WPML_Meta_Boxes_Post_Edit_Ajax::enqueue_scripts(). wp_enqueue_script( 'wpml-meta-box', ICL_PLUGIN_URL . '/dist/js/wpml-meta-box/wpml-meta-box.js' ); // Only if TM is active. if ( class_exists( 'WPML_TM_Post_Edit_TM_Editor_Select' ) ) { $tm_selector = new \WPML_TM_Post_Edit_TM_Editor_Select( $this->sitepress ); $tm_selector->add_hooks(); } } } /** * Add the WPML meta box when editing forms. * * @param int|\WP_Post $post The post ID or an instance of WP_Post. */ public function add_language_meta_box( $post ) { $post = get_post( $post ); $trid = filter_input( INPUT_GET, 'trid', FILTER_SANITIZE_NUMBER_INT ); if ( $post ) { add_filter( 'wpml_post_edit_can_translate', '__return_true' ); ?>