validator = $validator; $this->page_identify = $page_identify; } public function add_hooks() { if ( $this->validator->is_valid( get_current_user_id() ) || $this->load_how_to_button() ) { add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 10, 0 ); } } public function enqueue_scripts() { wp_register_script( self::RESOURCE_NAMESPACE, ICL_PLUGIN_URL . '/res/js/end-user.js', array( 'jquery-ui-dialog' ) ); wp_localize_script( self::RESOURCE_NAMESPACE, 'wpml_end_user_data', $this->get_how_to_link() ); wp_enqueue_script( self::RESOURCE_NAMESPACE ); } private function get_how_to_link() { $button = ' %1$s '; $button = sprintf( $button, esc_html__( 'How to translate', 'sitepress' ) ); return array( 'button' => $button, 'endpoint' => WPML_COMPATIBILITY_ENDPOINT, 'confirm_button_label' => esc_attr__( 'Continue', 'sitepress' ), ); } /** * @return bool */ private function load_how_to_button() { return $this->page_identify->is_page_list() || $this->page_identify->is_tm_dashboard(); } }