tp_api = $wpml_tp_api; } public function add_hooks() { add_action( 'wp_ajax_' . self::AJAX_ACTION, array( $this, 'refresh_language_pairs' ) ); } public function refresh_language_pairs() { if ( $this->is_valid_request() ) { try { $this->tp_api->refresh_language_pairs(); wp_send_json_success( array( 'msg' => __( 'Language pairs refreshed', 'wpml-translation-management' ), ) ); } catch ( Exception $e ) { wp_send_json_error( array( 'msg' => __( 'Language pairs not refreshed, please try again', 'wpml-translation-management' ), ) ); } } else { wp_send_json_error( array( 'msg' => __( 'Invalid Request', 'wpml-translation-management' ), ) ); } } /** * @return bool */ private function is_valid_request() { return array_key_exists( 'nonce', $_POST ) && wp_verify_nonce( filter_var( $_POST['nonce'], FILTER_SANITIZE_FULL_SPECIAL_CHARS ), self::AJAX_ACTION ); } }